KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > naming > JNDIBinding


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.naming;
23
24 import java.beans.PropertyEditor JavaDoc;
25
26 import org.jboss.util.propertyeditor.PropertyEditors;
27
28 /**
29  * A representation of a binding into JNDI.
30  *
31  * @author Scott.Stark@jboss.org
32  * @version $Revision: 37459 $
33  */

34 public class JNDIBinding
35 {
36    /** The jndi name to bind under */
37    private String JavaDoc name;
38    /** The binding text */
39    private String JavaDoc text;
40    /** The optional binding type the text should be converted to */
41    private String JavaDoc type;
42    /** The optional explicit PropertyEditor implementation class */
43    private String JavaDoc editor;
44    /** The actual binding value */
45    private Object JavaDoc value;
46    /** A flag indicating if the text should be trimmed */
47    private boolean trim;
48
49    /**
50     * The JNDI name to bind under
51     * @return
52     */

53    public String JavaDoc getName()
54    {
55       return name;
56    }
57
58    public void setName(String JavaDoc name)
59    {
60       this.name = name;
61    }
62
63    /**
64     * The text representation of the binding
65     * @return
66     */

67    public String JavaDoc getText()
68    {
69       return text;
70    }
71    /**
72     * Set the text representation of the binding. If the replace attribute
73     * is true, the text will be searched for system property references of the
74     * form ${x}.
75     *
76     * @param text
77     */

78    public void setText(String JavaDoc text)
79    {
80       if( trim == true )
81          text = text.trim();
82       this.text = text;
83    }
84
85    /**
86     * The optional type the text representation should be converted to.
87     *
88     * @return
89     */

90    public String JavaDoc getType()
91    {
92       return type;
93    }
94    /**
95     *
96     * @param type - type the text representation should be converted to.
97     */

98    public void setType(String JavaDoc type)
99    {
100       this.type = type;
101    }
102
103    /**
104     * The optional PropertyEditor implementation class name.
105     * @return
106     */

107    public String JavaDoc getEditor()
108    {
109       return editor;
110    }
111    /**
112     *
113     * @param editor - the optional PropertyEditor implementation class name.
114     */

115    public void setEditor(String JavaDoc editor)
116    {
117       this.editor = editor;
118    }
119
120    /**
121     * Object the binding value. If there is a binding from an external xml
122     * fragment it will be whatever that was. If there is a type it will be the
123     * value as obtained by converting the text of the value element to an object
124     * using the type PropertyEditor. If there is an explicit PropertyEditor
125     * given by the editor attribute that will be used to convert the text into
126     * an object.
127     *
128     * @return the value binding
129     * @throws Exception - on failure to load/use the PropertyEditor
130     */

131    public Object JavaDoc getValue() throws Exception JavaDoc
132    {
133       if( value == null && text != null )
134       {
135          // If there is a property editor set, transform text to value
136
if( editor != null )
137          {
138             ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
139             Class JavaDoc editorClass = loader.loadClass(editor);
140             PropertyEditor JavaDoc pe = (PropertyEditor JavaDoc) editorClass.newInstance();
141             pe.setAsText(text);
142             value = pe.getValue();
143          }
144          else if( type != null )
145          {
146             PropertyEditor JavaDoc pe = PropertyEditors.getEditor(type);
147             pe.setAsText(text);
148             value = pe.getValue();
149          }
150          else
151          {
152             value = text;
153          }
154       }
155       return value;
156    }
157    /**
158     * Set the raw value binding
159     * @param value
160     */

161    public void setValue(Object JavaDoc value)
162    {
163       this.value = value;
164    }
165
166    /**
167     *
168     * @return flag indicating if the text should be trimmed
169     */

170    public boolean isTrim()
171    {
172       return trim;
173    }
174    /**
175     *
176     * @param trim - flag indicating if the text should be trimmed
177     */

178    public void setTrim(boolean trim)
179    {
180       this.trim = trim;
181    }
182 }
183
Popular Tags