001: package xdoclet.modules.ojb.model;
002:
003: import java.util.HashMap;
004:
005: /* Copyright 2004-2005 The Apache Software Foundation
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: /**
021: * Helper class for dealing with properties of the descriptor defs.
022: */
023: public abstract class PropertyHelper {
024: // ojb repository properties
025: public static final String OJB_PROPERTY_ACCEPT_LOCKS = "accept-locks";
026: public static final String OJB_PROPERTY_ACCESS = "access";
027: public static final String OJB_PROPERTY_ARGUMENTS = "arguments";
028: public static final String OJB_PROPERTY_ARRAY_ELEMENT_CLASS_REF = "array-element-class-ref";
029: public static final String OJB_PROPERTY_ATTRIBUTES = "attributes";
030: public static final String OJB_PROPERTY_AUTOINCREMENT = "autoincrement";
031: public static final String OJB_PROPERTY_AUTO_DELETE = "auto-delete";
032: public static final String OJB_PROPERTY_AUTO_RETRIEVE = "auto-retrieve";
033: public static final String OJB_PROPERTY_AUTO_UPDATE = "auto-update";
034: public static final String OJB_PROPERTY_CLASS = "class";
035: public static final String OJB_PROPERTY_CLASS_REF = "class-ref";
036: public static final String OJB_PROPERTY_COLLECTION_CLASS = "collection-class";
037: public static final String OJB_PROPERTY_COLUMN = "column";
038: public static final String OJB_PROPERTY_COLUMN_DOCUMENTATION = "column-documentation";
039: public static final String OJB_PROPERTY_CONVERSION = "conversion";
040: public static final String OJB_PROPERTY_DATABASE_FOREIGNKEY = "database-foreignkey";
041: public static final String OJB_PROPERTY_DEFAULT_CLASS_REF = "default-class-ref";
042: public static final String OJB_PROPERTY_DEFAULT_CONVERSION = "default-conversion";
043: public static final String OJB_PROPERTY_DEFAULT_FETCH = "default-fetch";
044: public static final String OJB_PROPERTY_DEFAULT_JDBC_TYPE = "default-jdbc-type";
045: public static final String OJB_PROPERTY_DEFAULT_PRECISION = "default-precision";
046: public static final String OJB_PROPERTY_DEFAULT_SCALE = "default-scale";
047: public static final String OJB_PROPERTY_DETERMINE_EXTENTS = "determine-extents";
048: public static final String OJB_PROPERTY_DOCUMENTATION = "documentation";
049: public static final String OJB_PROPERTY_ELEMENT_CLASS_REF = "element-class-ref";
050: public static final String OJB_PROPERTY_FACTORY_CLASS = "factory-class";
051: public static final String OJB_PROPERTY_FACTORY_METHOD = "factory-method";
052: public static final String OJB_PROPERTY_FIELD_REF = "field-ref";
053: public static final String OJB_PROPERTY_FIELDS = "fields";
054: public static final String OJB_PROPERTY_FOREIGNKEY = "foreignkey";
055: public static final String OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION = "foreignkey-documentation";
056: public static final String OJB_PROPERTY_GENERATE_REPOSITORY_INFO = "generate-repository-info";
057: public static final String OJB_PROPERTY_GENERATE_TABLE_INFO = "generate-table-info";
058: public static final String OJB_PROPERTY_ID = "id";
059: public static final String OJB_PROPERTY_INDEXED = "indexed";
060: public static final String OJB_PROPERTY_IGNORE = "ignore";
061: public static final String OJB_PROPERTY_INCLUDE_INHERITED = "include-inherited";
062: public static final String OJB_PROPERTY_INDIRECTION_TABLE = "indirection-table";
063: public static final String OJB_PROPERTY_INDIRECTION_TABLE_DOCUMENTATION = "indirection-table-documentation";
064: public static final String OJB_PROPERTY_INDIRECTION_TABLE_PRIMARYKEYS = "indirection-table-primarykeys";
065: public static final String OJB_PROPERTY_INITIALIZATION_METHOD = "initialization-method";
066: public static final String OJB_PROPERTY_ISOLATION_LEVEL = "isolation-level";
067: public static final String OJB_PROPERTY_JAVA_TYPE = "java-type";
068: public static final String OJB_PROPERTY_JDBC_TYPE = "jdbc-type";
069: public static final String OJB_PROPERTY_LENGTH = "length";
070: public static final String OJB_PROPERTY_LOCKING = "locking";
071: public static final String OJB_PROPERTY_NAME = "name";
072: public static final String OJB_PROPERTY_NULLABLE = "nullable";
073: public static final String OJB_PROPERTY_OJB_PERSISTENT = "ojb-persistent";
074: public static final String OJB_PROPERTY_ORDERBY = "orderby";
075: public static final String OJB_PROPERTY_OTM_DEPENDENT = "otm-dependent";
076: public static final String OJB_PROPERTY_PRIMARYKEY = "primarykey";
077: public static final String OJB_PROPERTY_PRECISION = "precision";
078: public static final String OJB_PROPERTY_PROXY = "proxy";
079: public static final String OJB_PROPERTY_PROXY_PREFETCHING_LIMIT = "proxy-prefetching-limit";
080: public static final String OJB_PROPERTY_QUERY_CUSTOMIZER = "query-customizer";
081: public static final String OJB_PROPERTY_QUERY_CUSTOMIZER_ATTRIBUTES = "query-customizer-attributes";
082: public static final String OJB_PROPERTY_REFRESH = "refresh";
083: public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY = "remote-foreignkey";
084: public static final String OJB_PROPERTY_REMOTE_FOREIGNKEY_DOCUMENTATION = "remote-foreignkey-documentation";
085: public static final String OJB_PROPERTY_RETURN_FIELD_REF = "return-field-ref";
086: public static final String OJB_PROPERTY_ROW_READER = "row-reader";
087: public static final String OJB_PROPERTY_SCALE = "scale";
088: public static final String OJB_PROPERTY_SEQUENCE_NAME = "sequence-name";
089: public static final String OJB_PROPERTY_TABLE = "table";
090: public static final String OJB_PROPERTY_TABLE_DOCUMENTATION = "table-documentation";
091: public static final String OJB_PROPERTY_TYPE = "type";
092: public static final String OJB_PROPERTY_UNIQUE = "unique";
093: public static final String OJB_PROPERTY_UPDATE_LOCK = "update-lock";
094: public static final String OJB_PROPERTY_VARIABLE_TYPE = "variable-type";
095: public static final String OJB_PROPERTY_VIRTUAL_FIELD = "virtual-field";
096:
097: // torque schema properties
098: public static final String TORQUE_PROPERTY_AUTOINCREMENT = "autoIncrement";
099: public static final String TORQUE_PROPERTY_FOREIGNTABLE = "foreignTable";
100: public static final String TORQUE_PROPERTY_ID = "id";
101: public static final String TORQUE_PROPERTY_JAVANAME = "javaName";
102: public static final String TORQUE_PROPERTY_PRIMARYKEY = "primaryKey";
103: public static final String TORQUE_PROPERTY_RELATION_NAME = "relation-name";
104: public static final String TORQUE_PROPERTY_INV_RELATION_NAME = "inv-relation-name";
105: public static final String TORQUE_PROPERTY_REQUIRED = "required";
106: public static final String TORQUE_PROPERTY_SIZE = "size";
107: public static final String TORQUE_PROPERTY_TYPE = "type";
108:
109: /** Contains which properties are defined for the various defs */
110: private static HashMap _properties = new HashMap();
111:
112: static {
113: HashMap classProperties = new HashMap();
114:
115: classProperties.put(OJB_PROPERTY_ACCEPT_LOCKS, null);
116: classProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
117: classProperties.put(OJB_PROPERTY_DETERMINE_EXTENTS, null);
118: classProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
119: classProperties.put(OJB_PROPERTY_FACTORY_CLASS, null);
120: classProperties.put(OJB_PROPERTY_FACTORY_METHOD, null);
121: classProperties
122: .put(OJB_PROPERTY_GENERATE_REPOSITORY_INFO, null);
123: classProperties.put(OJB_PROPERTY_GENERATE_TABLE_INFO, null);
124: classProperties.put(OJB_PROPERTY_INCLUDE_INHERITED, null);
125: classProperties.put(OJB_PROPERTY_INITIALIZATION_METHOD, null);
126: classProperties.put(OJB_PROPERTY_ISOLATION_LEVEL, null);
127: classProperties.put(OJB_PROPERTY_OJB_PERSISTENT, null);
128: classProperties.put(OJB_PROPERTY_PROXY, null);
129: classProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT, null);
130: classProperties.put(OJB_PROPERTY_REFRESH, null);
131: classProperties.put(OJB_PROPERTY_ROW_READER, null);
132: classProperties.put(OJB_PROPERTY_TABLE, null);
133: classProperties.put(OJB_PROPERTY_TABLE_DOCUMENTATION, null);
134:
135: _properties.put(ClassDescriptorDef.class, classProperties);
136:
137: HashMap fieldProperties = new HashMap();
138:
139: fieldProperties.put(OJB_PROPERTY_ACCESS, null);
140: fieldProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
141: fieldProperties.put(OJB_PROPERTY_AUTOINCREMENT, null);
142: fieldProperties.put(OJB_PROPERTY_COLUMN, null);
143: fieldProperties.put(OJB_PROPERTY_COLUMN_DOCUMENTATION, null);
144: fieldProperties.put(OJB_PROPERTY_CONVERSION, null);
145: fieldProperties.put(OJB_PROPERTY_DEFAULT_CONVERSION, null);
146: fieldProperties.put(OJB_PROPERTY_DEFAULT_FETCH, null);
147: fieldProperties.put(OJB_PROPERTY_DEFAULT_JDBC_TYPE, null);
148: fieldProperties.put(OJB_PROPERTY_DEFAULT_PRECISION, null);
149: fieldProperties.put(OJB_PROPERTY_DEFAULT_SCALE, null);
150: fieldProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
151: fieldProperties.put(OJB_PROPERTY_ID, null);
152: fieldProperties.put(OJB_PROPERTY_IGNORE, null);
153: fieldProperties.put(OJB_PROPERTY_INDEXED, null);
154: fieldProperties.put(OJB_PROPERTY_JDBC_TYPE, null);
155: fieldProperties.put(OJB_PROPERTY_LENGTH, null);
156: fieldProperties.put(OJB_PROPERTY_LOCKING, null);
157: fieldProperties.put(OJB_PROPERTY_NULLABLE, null);
158: fieldProperties.put(OJB_PROPERTY_PRECISION, null);
159: fieldProperties.put(OJB_PROPERTY_PRIMARYKEY, null);
160: fieldProperties.put(OJB_PROPERTY_SCALE, null);
161: fieldProperties.put(OJB_PROPERTY_SEQUENCE_NAME, null);
162: fieldProperties.put(OJB_PROPERTY_UPDATE_LOCK, null);
163: fieldProperties.put(OJB_PROPERTY_VIRTUAL_FIELD, null);
164:
165: _properties.put(FieldDescriptorDef.class, fieldProperties);
166:
167: HashMap referenceProperties = new HashMap();
168:
169: referenceProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
170: referenceProperties.put(OJB_PROPERTY_AUTO_DELETE, null);
171: referenceProperties.put(OJB_PROPERTY_AUTO_RETRIEVE, null);
172: referenceProperties.put(OJB_PROPERTY_AUTO_UPDATE, null);
173: referenceProperties.put(OJB_PROPERTY_CLASS_REF, null);
174: referenceProperties.put(OJB_PROPERTY_DATABASE_FOREIGNKEY, null);
175: referenceProperties.put(OJB_PROPERTY_DEFAULT_CLASS_REF, null);
176: referenceProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
177: referenceProperties.put(OJB_PROPERTY_FOREIGNKEY, null);
178: referenceProperties.put(OJB_PROPERTY_IGNORE, null);
179: referenceProperties.put(OJB_PROPERTY_OTM_DEPENDENT, null);
180: referenceProperties.put(OJB_PROPERTY_PROXY, null);
181: referenceProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT,
182: null);
183: referenceProperties.put(OJB_PROPERTY_REFRESH, null);
184: referenceProperties.put(OJB_PROPERTY_VARIABLE_TYPE, null);
185:
186: _properties.put(ReferenceDescriptorDef.class,
187: referenceProperties);
188:
189: HashMap collectionProperties = new HashMap();
190:
191: collectionProperties.put(OJB_PROPERTY_ARRAY_ELEMENT_CLASS_REF,
192: null);
193: collectionProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
194: collectionProperties.put(OJB_PROPERTY_AUTO_DELETE, null);
195: collectionProperties.put(OJB_PROPERTY_AUTO_RETRIEVE, null);
196: collectionProperties.put(OJB_PROPERTY_AUTO_UPDATE, null);
197: collectionProperties.put(OJB_PROPERTY_COLLECTION_CLASS, null);
198: collectionProperties
199: .put(OJB_PROPERTY_DATABASE_FOREIGNKEY, null);
200: collectionProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
201: collectionProperties.put(OJB_PROPERTY_ELEMENT_CLASS_REF, null);
202: collectionProperties.put(OJB_PROPERTY_FOREIGNKEY, null);
203: collectionProperties.put(OJB_PROPERTY_FOREIGNKEY_DOCUMENTATION,
204: null);
205: collectionProperties.put(OJB_PROPERTY_IGNORE, null);
206: collectionProperties.put(OJB_PROPERTY_INDIRECTION_TABLE, null);
207: collectionProperties.put(
208: OJB_PROPERTY_INDIRECTION_TABLE_DOCUMENTATION, null);
209: collectionProperties.put(
210: OJB_PROPERTY_INDIRECTION_TABLE_PRIMARYKEYS, null);
211: collectionProperties.put(OJB_PROPERTY_ORDERBY, null);
212: collectionProperties.put(OJB_PROPERTY_OTM_DEPENDENT, null);
213: collectionProperties.put(OJB_PROPERTY_PROXY, null);
214: collectionProperties.put(OJB_PROPERTY_PROXY_PREFETCHING_LIMIT,
215: null);
216: collectionProperties.put(OJB_PROPERTY_QUERY_CUSTOMIZER, null);
217: collectionProperties.put(
218: OJB_PROPERTY_QUERY_CUSTOMIZER_ATTRIBUTES, null);
219: collectionProperties.put(OJB_PROPERTY_REFRESH, null);
220: collectionProperties.put(OJB_PROPERTY_REMOTE_FOREIGNKEY, null);
221: collectionProperties.put(
222: OJB_PROPERTY_REMOTE_FOREIGNKEY_DOCUMENTATION, null);
223: collectionProperties.put(OJB_PROPERTY_VARIABLE_TYPE, null);
224:
225: _properties.put(CollectionDescriptorDef.class,
226: collectionProperties);
227:
228: HashMap indexProperties = new HashMap();
229:
230: indexProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
231: indexProperties.put(OJB_PROPERTY_FIELDS, null);
232: indexProperties.put(OJB_PROPERTY_UNIQUE, null);
233:
234: _properties.put(IndexDescriptorDef.class, indexProperties);
235:
236: HashMap cacheProperties = new HashMap();
237:
238: cacheProperties.put(OJB_PROPERTY_ATTRIBUTES, null);
239: cacheProperties.put(OJB_PROPERTY_DOCUMENTATION, null);
240: cacheProperties.put(OJB_PROPERTY_CLASS, null);
241:
242: _properties.put(ObjectCacheDef.class, cacheProperties);
243: }
244:
245: /**
246: * Checks whether the property of the given name is allowed for the model element.
247: *
248: * @param defClass The class of the model element
249: * @param propertyName The name of the property
250: * @return <code>true</code> if the property is allowed for this type of model elements
251: */
252: public static boolean isPropertyAllowed(Class defClass,
253: String propertyName) {
254: HashMap props = (HashMap) _properties.get(defClass);
255:
256: return (props == null ? true : props.containsKey(propertyName));
257: }
258:
259: /**
260: * Determines whether the boolean value of the given string value.
261: *
262: * @param value The value
263: * @param defaultValue The boolean value to use if the string value is neither 'true' nor 'false'
264: * @return The boolean value of the string
265: */
266: public static boolean toBoolean(String value, boolean defaultValue) {
267: return "true".equals(value) ? true
268: : ("false".equals(value) ? false : defaultValue);
269: }
270: }
|