KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binding > BaseProperty


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.binding;
20
21 import java.util.BitSet JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 // Zeus imports
25
import org.enhydra.zeus.Binding;
26
27 /**
28  * <p>
29  * <code>{@link Property}</code> implements the <code>{@link Binding}</code>
30  * interface and defines behavior for a property of a Java class.
31  * These properties have modifiers, types, and names, as well
32  * as a value.
33  * </p><p>
34  * This base implementation of <code>Property</code> defines the common
35  * functionality for all <code>Property</code> implementations, removing
36  * a need for them to duplicate code for this functionality. All
37  * implementations of <code>Property</code> should extend this class
38  * rather than directly implementing the <code>Property</code> interface.
39  * </p>
40  *
41  * @author Brett McLaughlin
42  * @author Steve Witten
43  */

44 public abstract class BaseProperty extends BaseBinding implements Property {
45
46     /** The access level modifier for this <code>Property</code> */
47     protected BitSet JavaDoc modifier;
48     
49     /** Whether this <code>Property</code> is a <code>Collection</code> */
50     protected boolean isCollection;
51     
52     /** The default value for this <code>Property</code> */
53     protected Object JavaDoc defaultValue;
54
55     /** The allowed values for this <code>Property</code> */
56     protected Vector JavaDoc enumeration;
57
58     /**
59      * <p>
60      * Default constructor.
61      * </p>
62      */

63     public void BaseProperty() {
64         this.isCollection = false;
65         this.modifier = new BitSet JavaDoc();
66         this.defaultValue = null;
67         this.enumeration = null;
68     }
69
70     /**
71      * <p>
72      * This will set the modifiers for a property. The
73      * value submitted must be in the form of an <code>int</code>,
74      * which should correspond to one of the constants defined
75      * (<code>{@link #ACCESS_PRIVATE}</code>,
76      * <code>{@link #ACCESS_PROTECTED}</code>,
77      * <code>{@link #ACCESS_PUBLIC}</code>,
78      * <code>{@link #STORAGE_STATIC}</code>,
79      * <code>{@link #MUTABILITY_VOLATILE}</code>,
80      * or <code>{@link #MUTABILITY_FINAL}</code>. By default,
81      * all properties will be <code>private</code>
82      * (<code>ACCESS_PRIVATE</code>).
83      * </p>
84      *
85      * @param modifier <code>BitSet</code>representing modifiers.
86      * @see #ACCESS_PRIVATE
87      * @see #ACCESS_PROTECTED
88      * @see #ACCESS_PUBLIC
89      * @see #STORAGE_STATIC
90      * @see #MUTABILITY_VOLATILE
91      * @see #MUTABILITY_FINAL
92      */

93     public void setModifier(BitSet JavaDoc modifier) {
94         if (modifier == null) {
95             throw new IllegalArgumentException JavaDoc("A Property cannot have a " +
96                 "null set of modifiers.");
97         }
98         
99         this.modifier = modifier;
100     }
101
102     /**
103      * <p>
104      * This will return the access level modifier for a property. The
105      * value returned will be in the form of an <code>int</code>,
106      * which will correspond to one of the constants defined
107      * (<code>{@link #ACCESS_PRIVATE}</code>,
108      * <code>{@link #ACCESS_PROTECTED}</code>,
109      * <code>{@link #ACCESS_PUBLIC}</code>,
110      * <code>{@link #STORAGE_STATIC}</code>,
111      * or <code>{@link #MUTABILITY_FINAL}</code>.
112      * </p>
113      *
114      * @return <code>BitSet</code> - modifiers.
115      * @see #ACCESS_PRIVATE
116      * @see #ACCESS_PROTECTED
117      * @see #ACCESS_PUBLIC
118      * @see #STORAGE_STATIC
119      * @see #MUTABILITY_VOLATILE
120      * @see #MUTABILITY_FINAL
121      */

122     public BitSet JavaDoc getModifier() {
123         return modifier;
124     }
125     
126     /**
127      * <p>
128      * This will return the Java <code>String</code> representation
129      * of this <code>Property</code>'s modifier(s). For
130      * example, <code>{@link #ACCESS_PRIVATE}</code> would be
131      * converted to "private".
132      * </p>
133      *
134      * @return <code>String</code> - Java representation of modifiers
135      * @see #ACCESS_PRIVATE
136      * @see #ACCESS_PROTECTED
137      * @see #ACCESS_PUBLIC
138      * @see #STORAGE_STATIC
139      * @see #MUTABILITY_VOLATILE
140      * @see #MUTABILITY_FINAL
141      */

142     public String JavaDoc getModifierString() {
143         StringBuffer JavaDoc modifierString = new StringBuffer JavaDoc();
144         if (modifier.get(ACCESS_PRIVATE)) {
145             modifierString.append("private");
146         } else if (modifier.get(ACCESS_PROTECTED)) {
147             modifierString.append("protected");
148         } else if (modifier.get(ACCESS_PUBLIC)) {
149             modifierString.append("public");
150         } else {
151             throw new UnsupportedOperationException JavaDoc
152                 ("Modifier must set access modifiers.");
153         }
154         
155         if (modifier.get(STORAGE_STATIC)) {
156             modifierString.append(" static");
157         }
158         if (modifier.get(MUTABILITY_VOLATILE)) {
159             modifierString.append(" volatile");
160         } else if (modifier.get(MUTABILITY_FINAL)) {
161             modifierString.append(" final");
162         }
163         
164         return modifierString.toString();
165     }
166     
167     /**
168      * <p>
169      * This will determine whether or not this <code>Property</code>
170      * is a <code>Collection</code> (in other words, the property
171      * represents a collection of values). By default, properties
172      * are all singular values.
173      * </p>
174      *
175      * @param isCollection <code>true</code> is multiple values can be stored,
176      * or else <code>false</code>.
177      */

178     public void setIsCollection(boolean isCollection) {
179         this.isCollection = isCollection;
180     }
181
182     /**
183      * <p>
184      * This will indicate whether this <code>Property</code> represents
185      * a <code>Collection</code> of values (resulting in a <code>true</code>
186      * result from this method), or a singular value (resulting in a
187      * <code>false</code> result).
188      * </p>
189      *
190      * @return <code>boolean</code> - whether or not this <code>Property</code>
191      * represents a <code>Collection<code>.
192      */

193     public boolean isCollection() {
194         return isCollection;
195     }
196
197     /**
198      * <p>
199      * This indicates whether or not this <code>Property</code> has a
200      * a default value set.
201      * </p>
202      *
203      * @return <code>boolean</code> - whether there is a default value set.
204      */

205     public boolean hasDefaultValue() {
206         return (defaultValue != null);
207     }
208
209     /**
210      * <p>
211      * This will set the default value of the property. Since no typing
212      * is available at this point, a simple Java <code>Object</code>
213      * is allowed as the type supplied. As a result, any errors in
214      * mismatches between object type and allowed paramater type will
215      * occur at runtime, when class generation takes place. Supplying
216      * a value here essentially results in:
217      * <code><pre>
218      * public class Foo {
219      *
220      * private String myString = "some default value";
221      *
222      * public String getMyString() {
223      * return myString;
224      * }
225      *
226      * public void setMyString(String myString) {
227      * this.myString = myString;
228      * }
229      *
230      * // Other methods and properties
231      * }
232      * </pre></code>
233      * </p><p>
234      * Also, note that data binding users who supply their own class
235      * implementations will <b>LOSE THIS DEFAULT VALUE</b>, as the interface
236      * alone cannot specify a default value. So use this carefully!
237      * </p>
238      *
239      * @param defaultValue <code>Object</code> to be used as default value.
240      */

241     public void setDefaultValue(Object JavaDoc defaultValue) {
242         this.defaultValue = defaultValue;
243     }
244
245     /**
246      * <p>
247      * This will retrieve the default value associated with this property,
248      * or <code>null</code> if there is not one. For more information on
249      * default property values, see
250      * <code>{@link #setDefaultValue(Object)}</code>.
251      * </p>
252      *
253      * @return <code>Object</code> - default value of the property.
254      */

255     public Object JavaDoc getDefaultValue() {
256         return defaultValue;
257     }
258
259     /**
260      * <p>
261      * This will indicate if this <code>Property</code> has a set of
262      * allowed values (an enumeration) specified for it.
263      * </p>
264      *
265      * @return <code>boolean</code> - whether an enumeration is specified.
266      */

267     public boolean hasEnumeration() {
268         return (enumeration != null);
269     }
270
271     /**
272      * <p>
273      * This will set a list (enumeration) of allowed values for this
274      * <code>Property</code>. To allow any value, the <code>null</code>
275      * value should be supplied (which is the default value).
276      * </p>
277      *
278      * @param enumeration the <code>Vector</code> of allowed values.
279      */

280     public void setEnumeration(Vector JavaDoc enumeration) {
281         this.enumeration = enumeration;
282     }
283   
284     /**
285      * <p>
286      * This returns the <code>Vector</code> of allowed values for this
287      * <code>Property</code>, or <code>null</code> if there is none.
288      * </p>
289      *
290      * @return <code>Vector</code> - the allowed values.
291      */

292     public Vector JavaDoc getEnumeration() {
293         return enumeration;
294     }
295 }
296
Popular Tags