KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > model > PropertyHelper


1 package xdoclet.modules.ojb.model;
2
3 import java.util.HashMap JavaDoc;
4
5 /* Copyright 2004-2005 The Apache Software Foundation
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 /**
21  * Helper class for dealing with properties of the descriptor defs.
22  */

23 public abstract class PropertyHelper
24 {
25     // ojb repository properties
26
public static final String JavaDoc OJB_PROPERTY_ACCEPT_LOCKS = "accept-locks";
27     public static final String JavaDoc OJB_PROPERTY_ACCESS = "access";
28     public static final String JavaDoc OJB_PROPERTY_ARGUMENTS = "arguments";
29     public static final String JavaDoc OJB_PROPERTY_ARRAY_ELEMENT_CLASS_REF = "array-element-class-ref";
30     public static final String JavaDoc OJB_PROPERTY_ATTRIBUTES = "attributes";
31     public static final String JavaDoc OJB_PROPERTY_AUTOINCREMENT = "autoincrement";
32     public static final String JavaDoc OJB_PROPERTY_AUTO_DELETE = "auto-delete";
33     public static final String JavaDoc OJB_PROPERTY_AUTO_RETRIEVE = "auto-retrieve";
34     public static final String JavaDoc OJB_PROPERTY_AUTO_UPDATE = "auto-update";
35     public static final String JavaDoc OJB_PROPERTY_CLASS = "class";
36     public static final String JavaDoc OJB_PROPERTY_CLASS_REF = "class-ref";
37     public static final String JavaDoc OJB_PROPERTY_COLLECTION_CLASS = "collection-class";
38     public static final String JavaDoc OJB_PROPERTY_COLUMN = "column";
39     public static final String JavaDoc OJB_PROPERTY_COLUMN_DOCUMENTATION = "column-documentation";
40     public static final String JavaDoc OJB_PROPERTY_CONVERSION = "conversion";
41     public static final String JavaDoc OJB_PROPERTY_DATABASE_FOREIGNKEY = "database-foreignkey";
42     public static final String JavaDoc OJB_PROPERTY_DEFAULT_CLASS_REF = "default-class-ref";
43     public static final String JavaDoc OJB_PROPERTY_DEFAULT_CONVERSION = "default-conversion";
44     public static final String JavaDoc OJB_PROPERTY_DEFAULT_FETCH = "default-fetch";
45     public static final String JavaDoc OJB_PROPERTY_DEFAULT_JDBC_TYPE = "default-jdbc-type";
46     public static final String JavaDoc OJB_PROPERTY_DEFAULT_PRECISION = "default-precision";
47     public static final String JavaDoc OJB_PROPERTY_DEFAULT_SCALE = "default-scale";
48     public static final String JavaDoc OJB_PROPERTY_DETERMINE_EXTENTS = "determine-extents";
49     public static final String JavaDoc OJB_PROPERTY_DOCUMENTATION = "documentation";
50     public static final String JavaDoc OJB_PROPERTY_ELEMENT_CLASS_REF = "element-class-ref";
51     public static final String JavaDoc OJB_PROPERTY_FACTORY_CLASS = "factory-class";
52     public static final String JavaDoc OJB_PROPERTY_FACTORY_METHOD = "factory-method";
53     public static final String JavaDoc OJB_PROPERTY_FIELD_REF = "field-ref";
54     public static final String JavaDoc OJB_PROPERTY_FIELDS = "fields";
55     public static final String JavaDoc OJB_PROPERTY_FOREIGNKEY = "foreignkey";
56     public static final String JavaDoc OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION = "foreignkey-documentation";
57     public static final String JavaDoc OJB_PROPERTY_GENERATE_REPOSITORY_INFO = "generate-repository-info";
58     public static final String JavaDoc OJB_PROPERTY_GENERATE_TABLE_INFO = "generate-table-info";
59     public static final String JavaDoc OJB_PROPERTY_ID = "id";
60     public static final String JavaDoc OJB_PROPERTY_INDEXED = "indexed";
61     public static final String JavaDoc OJB_PROPERTY_IGNORE = "ignore";
62     public static final String JavaDoc OJB_PROPERTY_INCLUDE_INHERITED = "include-inherited";
63     public static final String JavaDoc OJB_PROPERTY_INDIRECTION_TABLE = "indirection-table";
64     public static final String JavaDoc OJB_PROPERTY_INDIRECTION_TABLE_DOCUMENTATION = "indirection-table-documentation";
65     public static final String JavaDoc OJB_PROPERTY_INDIRECTION_TABLE_PRIMARYKEYS = "indirection-table-primarykeys";
66     public static final String JavaDoc OJB_PROPERTY_INITIALIZATION_METHOD = "initialization-method";
67     public static final String JavaDoc OJB_PROPERTY_ISOLATION_LEVEL = "isolation-level";
68     public static final String JavaDoc OJB_PROPERTY_JAVA_TYPE = "java-type";
69     public static final String JavaDoc OJB_PROPERTY_JDBC_TYPE = "jdbc-type";
70     public static final String JavaDoc OJB_PROPERTY_LENGTH = "length";
71     public static final String JavaDoc OJB_PROPERTY_LOCKING = "locking";
72     public static final String JavaDoc OJB_PROPERTY_NAME = "name";
73     public static final String JavaDoc OJB_PROPERTY_NULLABLE = "nullable";
74     public static final String JavaDoc OJB_PROPERTY_OJB_PERSISTENT = "ojb-persistent";
75     public static final String JavaDoc OJB_PROPERTY_ORDERBY = "orderby";
76     public static final String JavaDoc OJB_PROPERTY_OTM_DEPENDENT = "otm-dependent";
77     public static final String JavaDoc OJB_PROPERTY_PRIMARYKEY = "primarykey";
78     public static final String JavaDoc OJB_PROPERTY_PRECISION = "precision";
79     public static final String JavaDoc OJB_PROPERTY_PROXY = "proxy";
80     public static final String JavaDoc OJB_PROPERTY_PROXY_PREFETCHING_LIMIT = "proxy-prefetching-limit";
81     public static final String JavaDoc OJB_PROPERTY_QUERY_CUSTOMIZER = "query-customizer";
82     public static final String JavaDoc OJB_PROPERTY_QUERY_CUSTOMIZER_ATTRIBUTES = "query-customizer-attributes";
83     public static final String JavaDoc OJB_PROPERTY_REFRESH = "refresh";
84     public static final String JavaDoc OJB_PROPERTY_REMOTE_FOREIGNKEY = "remote-foreignkey";
85     public static final String JavaDoc OJB_PROPERTY_REMOTE_FOREIGNKEY_DOCUMENTATION = "remote-foreignkey-documentation";
86     public static final String JavaDoc OJB_PROPERTY_RETURN_FIELD_REF = "return-field-ref";
87     public static final String JavaDoc OJB_PROPERTY_ROW_READER = "row-reader";
88     public static final String JavaDoc OJB_PROPERTY_SCALE = "scale";
89     public static final String JavaDoc OJB_PROPERTY_SEQUENCE_NAME = "sequence-name";
90     public static final String JavaDoc OJB_PROPERTY_TABLE = "table";
91     public static final String JavaDoc OJB_PROPERTY_TABLE_DOCUMENTATION = "table-documentation";
92     public static final String JavaDoc OJB_PROPERTY_TYPE = "type";
93     public static final String JavaDoc OJB_PROPERTY_UNIQUE = "unique";
94     public static final String JavaDoc OJB_PROPERTY_UPDATE_LOCK = "update-lock";
95     public static final String JavaDoc OJB_PROPERTY_VARIABLE_TYPE = "variable-type";
96     public static final String JavaDoc OJB_PROPERTY_VIRTUAL_FIELD = "virtual-field";
97
98     // torque schema properties
99
public static final String JavaDoc TORQUE_PROPERTY_AUTOINCREMENT = "autoIncrement";
100     public static final String JavaDoc TORQUE_PROPERTY_FOREIGNTABLE = "foreignTable";
101     public static final String JavaDoc TORQUE_PROPERTY_ID = "id";
102     public static final String JavaDoc TORQUE_PROPERTY_JAVANAME = "javaName";
103     public static final String JavaDoc TORQUE_PROPERTY_PRIMARYKEY = "primaryKey";
104     public static final String JavaDoc TORQUE_PROPERTY_RELATION_NAME = "relation-name";
105     public static final String JavaDoc TORQUE_PROPERTY_INV_RELATION_NAME = "inv-relation-name";
106     public static final String JavaDoc TORQUE_PROPERTY_REQUIRED = "required";
107     public static final String JavaDoc TORQUE_PROPERTY_SIZE = "size";
108     public static final String JavaDoc TORQUE_PROPERTY_TYPE = "type";
109     
110     /** Contains which properties are defined for the various defs */
111     private static HashMap JavaDoc _properties = new HashMap JavaDoc();
112
113     static
114     {
115         HashMap JavaDoc classProperties = new HashMap JavaDoc();
116
117         classProperties.put(OJB_PROPERTY_ACCEPT_LOCKS, null);
118         classProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
119         classProperties.put(OJB_PROPERTY_DETERMINE_EXTENTS, null);
120         classProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
121         classProperties.put(OJB_PROPERTY_FACTORY_CLASS, null);
122         classProperties.put(OJB_PROPERTY_FACTORY_METHOD, null);
123         classProperties.put(OJB_PROPERTY_GENERATE_REPOSITORY_INFO, null);
124         classProperties.put(OJB_PROPERTY_GENERATE_TABLE_INFO, null);
125         classProperties.put(OJB_PROPERTY_INCLUDE_INHERITED, null);
126         classProperties.put(OJB_PROPERTY_INITIALIZATION_METHOD, null);
127         classProperties.put(OJB_PROPERTY_ISOLATION_LEVEL, null);
128         classProperties.put(OJB_PROPERTY_OJB_PERSISTENT, null);
129         classProperties.put(OJB_PROPERTY_PROXY, null);
130         classProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT, null);
131         classProperties.put(OJB_PROPERTY_REFRESH, null);
132         classProperties.put(OJB_PROPERTY_ROW_READER, null);
133         classProperties.put(OJB_PROPERTY_TABLE, null);
134         classProperties.put(OJB_PROPERTY_TABLE_DOCUMENTATION, null);
135         
136         _properties.put(ClassDescriptorDef.class, classProperties);
137
138         HashMap JavaDoc fieldProperties = new HashMap JavaDoc();
139
140         fieldProperties.put(OJB_PROPERTY_ACCESS, null);
141         fieldProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
142         fieldProperties.put(OJB_PROPERTY_AUTOINCREMENT, null);
143         fieldProperties.put(OJB_PROPERTY_COLUMN, null);
144         fieldProperties.put(OJB_PROPERTY_COLUMN_DOCUMENTATION, null);
145         fieldProperties.put(OJB_PROPERTY_CONVERSION, null);
146         fieldProperties.put(OJB_PROPERTY_DEFAULT_CONVERSION, null);
147         fieldProperties.put(OJB_PROPERTY_DEFAULT_FETCH, null);
148         fieldProperties.put(OJB_PROPERTY_DEFAULT_JDBC_TYPE, null);
149         fieldProperties.put(OJB_PROPERTY_DEFAULT_PRECISION, null);
150         fieldProperties.put(OJB_PROPERTY_DEFAULT_SCALE, null);
151         fieldProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
152         fieldProperties.put(OJB_PROPERTY_ID, null);
153         fieldProperties.put(OJB_PROPERTY_IGNORE, null);
154         fieldProperties.put(OJB_PROPERTY_INDEXED, null);
155         fieldProperties.put(OJB_PROPERTY_JDBC_TYPE, null);
156         fieldProperties.put(OJB_PROPERTY_LENGTH, null);
157         fieldProperties.put(OJB_PROPERTY_LOCKING, null);
158         fieldProperties.put(OJB_PROPERTY_NULLABLE, null);
159         fieldProperties.put(OJB_PROPERTY_PRECISION, null);
160         fieldProperties.put(OJB_PROPERTY_PRIMARYKEY, null);
161         fieldProperties.put(OJB_PROPERTY_SCALE, null);
162         fieldProperties.put(OJB_PROPERTY_SEQUENCE_NAME, null);
163         fieldProperties.put(OJB_PROPERTY_UPDATE_LOCK, null);
164         fieldProperties.put(OJB_PROPERTY_VIRTUAL_FIELD, null);
165
166         _properties.put(FieldDescriptorDef.class, fieldProperties);
167
168         HashMap JavaDoc referenceProperties = new HashMap JavaDoc();
169
170         referenceProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
171         referenceProperties.put(OJB_PROPERTY_AUTO_DELETE, null);
172         referenceProperties.put(OJB_PROPERTY_AUTO_RETRIEVE, null);
173         referenceProperties.put(OJB_PROPERTY_AUTO_UPDATE, null);
174         referenceProperties.put(OJB_PROPERTY_CLASS_REF, null);
175         referenceProperties.put(OJB_PROPERTY_DATABASE_FOREIGNKEY, null);
176         referenceProperties.put(OJB_PROPERTY_DEFAULT_CLASS_REF, null);
177         referenceProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
178         referenceProperties.put(OJB_PROPERTY_FOREIGNKEY, null);
179         referenceProperties.put(OJB_PROPERTY_IGNORE, null);
180         referenceProperties.put(OJB_PROPERTY_OTM_DEPENDENT, null);
181         referenceProperties.put(OJB_PROPERTY_PROXY, null);
182         referenceProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT, null);
183         referenceProperties.put(OJB_PROPERTY_REFRESH, null);
184         referenceProperties.put(OJB_PROPERTY_VARIABLE_TYPE, null);
185
186         _properties.put(ReferenceDescriptorDef.class, referenceProperties);
187
188         HashMap JavaDoc collectionProperties = new HashMap JavaDoc();
189
190         collectionProperties.put(OJB_PROPERTY_ARRAY_ELEMENT_CLASS_REF, null);
191         collectionProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
192         collectionProperties.put(OJB_PROPERTY_AUTO_DELETE, null);
193         collectionProperties.put(OJB_PROPERTY_AUTO_RETRIEVE, null);
194         collectionProperties.put(OJB_PROPERTY_AUTO_UPDATE, null);
195         collectionProperties.put(OJB_PROPERTY_COLLECTION_CLASS, null);
196         collectionProperties.put(OJB_PROPERTY_DATABASE_FOREIGNKEY, null);
197         collectionProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
198         collectionProperties.put(OJB_PROPERTY_ELEMENT_CLASS_REF, null);
199         collectionProperties.put(OJB_PROPERTY_FOREIGNKEY, null);
200         collectionProperties.put(OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION, null);
201         collectionProperties.put(OJB_PROPERTY_IGNORE, null);
202         collectionProperties.put(OJB_PROPERTY_INDIRECTION_TABLE, null);
203         collectionProperties.put(OJB_PROPERTY_INDIRECTION_TABLE_DOCUMENTATION, null);
204         collectionProperties.put(OJB_PROPERTY_INDIRECTION_TABLE_PRIMARYKEYS, null);
205         collectionProperties.put(OJB_PROPERTY_ORDERBY, null);
206         collectionProperties.put(OJB_PROPERTY_OTM_DEPENDENT, null);
207         collectionProperties.put(OJB_PROPERTY_PROXY, null);
208         collectionProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT, null);
209         collectionProperties.put(OJB_PROPERTY_QUERY_CUSTOMIZER, null);
210         collectionProperties.put(OJB_PROPERTY_QUERY_CUSTOMIZER_ATTRIBUTES, null);
211         collectionProperties.put(OJB_PROPERTY_REFRESH, null);
212         collectionProperties.put(OJB_PROPERTY_REMOTE_FOREIGNKEY, null);
213         collectionProperties.put(OJB_PROPERTY_REMOTE_FOREIGNKEY_DOCUMENTATION, null);
214         collectionProperties.put(OJB_PROPERTY_VARIABLE_TYPE, null);
215
216         _properties.put(CollectionDescriptorDef.class, collectionProperties);
217
218         HashMap JavaDoc indexProperties = new HashMap JavaDoc();
219
220         indexProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
221         indexProperties.put(OJB_PROPERTY_FIELDS, null);
222         indexProperties.put(OJB_PROPERTY_UNIQUE, null);
223
224         _properties.put(IndexDescriptorDef.class, indexProperties);
225
226         HashMap JavaDoc cacheProperties = new HashMap JavaDoc();
227
228         cacheProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
229         cacheProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
230         cacheProperties.put(OJB_PROPERTY_CLASS, null);
231
232         _properties.put(ObjectCacheDef.class, cacheProperties);
233     }
234
235     /**
236      * Checks whether the property of the given name is allowed for the model element.
237      *
238      * @param defClass The class of the model element
239      * @param propertyName The name of the property
240      * @return <code>true</code> if the property is allowed for this type of model elements
241      */

242     public static boolean isPropertyAllowed(Class JavaDoc defClass, String JavaDoc propertyName)
243     {
244         HashMap JavaDoc props = (HashMap JavaDoc)_properties.get(defClass);
245
246         return (props == null ? true : props.containsKey(propertyName));
247     }
248
249     /**
250      * Determines whether the boolean value of the given string value.
251      *
252      * @param value The value
253      * @param defaultValue The boolean value to use if the string value is neither 'true' nor 'false'
254      * @return The boolean value of the string
255      */

256     public static boolean toBoolean(String JavaDoc value, boolean defaultValue)
257     {
258         return "true".equals(value) ? true : ("false".equals(value) ? false : defaultValue);
259     }
260 }
261
Popular Tags