KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > model > ModelReader


1 /*
2  * $Id: ModelReader.java 5720 2005-09-13 03:10:59Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.entity.model;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.TreeSet JavaDoc;
33
34 import javolution.util.FastList;
35 import javolution.util.FastMap;
36 import javolution.util.FastSet;
37
38 import org.ofbiz.base.component.ComponentConfig;
39 import org.ofbiz.base.config.GenericConfigException;
40 import org.ofbiz.base.config.MainResourceHandler;
41 import org.ofbiz.base.config.ResourceHandler;
42 import org.ofbiz.base.util.Debug;
43 import org.ofbiz.base.util.UtilTimer;
44 import org.ofbiz.base.util.UtilXml;
45 import org.ofbiz.base.util.cache.UtilCache;
46 import org.ofbiz.entity.GenericEntityConfException;
47 import org.ofbiz.entity.GenericEntityException;
48 import org.ofbiz.entity.GenericModelException;
49 import org.ofbiz.entity.config.DelegatorInfo;
50 import org.ofbiz.entity.config.EntityConfigUtil;
51 import org.ofbiz.entity.config.EntityModelReaderInfo;
52 import org.w3c.dom.Document JavaDoc;
53 import org.w3c.dom.Element JavaDoc;
54 import org.w3c.dom.Node JavaDoc;
55
56 /**
57  * Generic Entity - Entity Definition Reader
58  *
59  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
60  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
61  * @version $Rev: 5720 $
62  * @since 2.0
63  */

64 public class ModelReader implements Serializable JavaDoc {
65
66     public static final String JavaDoc module = ModelReader.class.getName();
67     public static UtilCache readers = new UtilCache("entity.ModelReader", 0, 0);
68
69     protected Map JavaDoc entityCache = null;
70
71     protected int numEntities = 0;
72     protected int numViewEntities = 0;
73     protected int numFields = 0;
74     protected int numRelations = 0;
75     protected int numAutoRelations = 0;
76
77     protected String JavaDoc modelName;
78
79     /** collection of filenames for entity definitions */
80     protected Collection JavaDoc entityResourceHandlers;
81
82     /** contains a collection of entity names for each ResourceHandler, populated as they are loaded */
83     protected Map JavaDoc resourceHandlerEntities;
84
85     /** for each entity contains a map to the ResourceHandler that the entity came from */
86     protected Map JavaDoc entityResourceHandlerMap;
87
88     public static ModelReader getModelReader(String JavaDoc delegatorName) throws GenericEntityException {
89         DelegatorInfo delegatorInfo = EntityConfigUtil.getDelegatorInfo(delegatorName);
90
91         if (delegatorInfo == null) {
92             throw new GenericEntityConfException("Could not find a delegator with the name " + delegatorName);
93         }
94
95         String JavaDoc tempModelName = delegatorInfo.entityModelReader;
96         ModelReader reader = (ModelReader) readers.get(tempModelName);
97
98         if (reader == null) { // don't want to block here
99
synchronized (ModelReader.class) {
100                 // must check if null again as one of the blocked threads can still enter
101
reader = (ModelReader) readers.get(tempModelName);
102                 if (reader == null) {
103                     reader = new ModelReader(tempModelName);
104                     // preload caches...
105
reader.getEntityCache();
106                     readers.put(tempModelName, reader);
107                 }
108             }
109         }
110         return reader;
111     }
112
113     public ModelReader(String JavaDoc modelName) throws GenericEntityException {
114         this.modelName = modelName;
115         entityResourceHandlers = FastList.newInstance();
116         resourceHandlerEntities = FastMap.newInstance();
117         entityResourceHandlerMap = FastMap.newInstance();
118
119         EntityModelReaderInfo entityModelReaderInfo = EntityConfigUtil.getEntityModelReaderInfo(modelName);
120
121         if (entityModelReaderInfo == null) {
122             throw new GenericEntityConfException("Cound not find an entity-model-reader with the name " + modelName);
123         }
124
125         // get all of the main resource model stuff, ie specified in the entityengine.xml file
126
List JavaDoc resourceElements = entityModelReaderInfo.resourceElements;
127         Iterator JavaDoc resIter = resourceElements.iterator();
128         while (resIter.hasNext()) {
129             Element JavaDoc resourceElement = (Element JavaDoc) resIter.next();
130             ResourceHandler handler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, resourceElement);
131             entityResourceHandlers.add(handler);
132         }
133         
134         // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
135
List JavaDoc componentResourceInfos = ComponentConfig.getAllEntityResourceInfos("model");
136         Iterator JavaDoc componentResourceInfoIter = componentResourceInfos.iterator();
137         while (componentResourceInfoIter.hasNext()) {
138             ComponentConfig.EntityResourceInfo componentResourceInfo = (ComponentConfig.EntityResourceInfo) componentResourceInfoIter.next();
139             if (modelName.equals(componentResourceInfo.readerName)) {
140                 entityResourceHandlers.add(componentResourceInfo.createResourceHandler());
141             }
142         }
143     }
144
145     public Map JavaDoc getEntityCache() throws GenericEntityException {
146         if (entityCache == null) { // don't want to block here
147
synchronized (ModelReader.class) {
148                 // must check if null again as one of the blocked threads can still enter
149
if (entityCache == null) { // now it's safe
150
numEntities = 0;
151                     numViewEntities = 0;
152                     numFields = 0;
153                     numRelations = 0;
154                     numAutoRelations = 0;
155
156                     entityCache = FastMap.newInstance();
157                     List JavaDoc tempViewEntityList = FastList.newInstance();
158
159                     UtilTimer utilTimer = new UtilTimer();
160                     
161                     Iterator JavaDoc rhIter = entityResourceHandlers.iterator();
162                     while (rhIter.hasNext()) {
163                         ResourceHandler entityResourceHandler = (ResourceHandler) rhIter.next();
164
165                         // utilTimer.timerString("Before getDocument in file " + entityFileName);
166
Document JavaDoc document = null;
167
168                         try {
169                             document = entityResourceHandler.getDocument();
170                         } catch (GenericConfigException e) {
171                             throw new GenericEntityConfException("Error getting document from resource handler", e);
172                         }
173                         if (document == null) {
174                             throw new GenericEntityConfException("Could not get document for " + entityResourceHandler.toString());
175                         }
176
177                         // utilTimer.timerString("Before getDocumentElement in " + entityResourceHandler.toString());
178
Element JavaDoc docElement = document.getDocumentElement();
179
180                         if (docElement == null) {
181                             entityCache = null;
182                             return null;
183                         }
184                         docElement.normalize();
185                         Node JavaDoc curChild = docElement.getFirstChild();
186
187                         ModelInfo def = new ModelInfo();
188                         def.populateFromElements(docElement);
189                         int i = 0;
190
191                         if (curChild != null) {
192                             utilTimer.timerString("Before start of entity loop in " + entityResourceHandler.toString());
193                             do {
194                                 boolean isEntity = "entity".equals(curChild.getNodeName());
195                                 boolean isViewEntity = "view-entity".equals(curChild.getNodeName());
196
197                                 if ((isEntity || isViewEntity) && curChild.getNodeType() == Node.ELEMENT_NODE) {
198                                     i++;
199                                     Element JavaDoc curEntity = (Element JavaDoc) curChild;
200                                     String JavaDoc entityName = UtilXml.checkEmpty(curEntity.getAttribute("entity-name"));
201
202                                     // add entityName to appropriate resourceHandlerEntities collection
203
Collection JavaDoc resourceHandlerEntityNames = (Collection JavaDoc) resourceHandlerEntities.get(entityResourceHandler);
204
205                                     if (resourceHandlerEntityNames == null) {
206                                         resourceHandlerEntityNames = FastList.newInstance();
207                                         resourceHandlerEntities.put(entityResourceHandler, resourceHandlerEntityNames);
208                                     }
209                                     resourceHandlerEntityNames.add(entityName);
210
211                                     // check to see if entity with same name has already been read
212
if (entityCache.containsKey(entityName)) {
213                                         Debug.logWarning("WARNING: Entity " + entityName +
214                                             " is defined more than once, most recent will over-write " +
215                                             "previous definition(s)", module);
216                                         Debug.logWarning("WARNING: Entity " + entityName + " was found in " +
217                                             entityResourceHandler + ", but was already defined in " +
218                                             entityResourceHandlerMap.get(entityName).toString(), module);
219                                     }
220
221                                     // add entityName, entityFileName pair to entityResourceHandlerMap map
222
entityResourceHandlerMap.put(entityName, entityResourceHandler);
223
224                                     // utilTimer.timerString(" After entityEntityName -- " + i + " --");
225
// ModelEntity entity = createModelEntity(curEntity, utilTimer);
226

227                                     ModelEntity entity = null;
228
229                                     if (isEntity) {
230                                         entity = createModelEntity(curEntity, null, def);
231                                     } else {
232                                         entity = createModelViewEntity(curEntity, null, def);
233                                         // put the view entity in a list to get ready for the second pass to populate fields...
234
tempViewEntityList.add(entity);
235                                     }
236
237                                     // utilTimer.timerString(" After createModelEntity -- " + i + " --");
238
if (entity != null) {
239                                         entityCache.put(entityName, entity);
240                                         // utilTimer.timerString(" After entityCache.put -- " + i + " --");
241
if (isEntity) {
242                                             if (Debug.verboseOn()) Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
243                                         } else {
244                                             if (Debug.verboseOn()) Debug.logVerbose("-- [ViewEntity]: #" + i + ": " + entityName, module);
245                                         }
246                                     } else {
247                                         Debug.logWarning("-- -- ENTITYGEN ERROR:getModelEntity: Could not create " +
248                                             "entity for entityName: " + entityName, module);
249                                     }
250
251                                 }
252                             } while ((curChild = curChild.getNextSibling()) != null);
253                         } else {
254                             Debug.logWarning("No child nodes found.", module);
255                         }
256                         utilTimer.timerString("Finished " + entityResourceHandler.toString() + " - Total Entities: " + i + " FINISHED");
257                     }
258
259                     // do a pass on all of the view entities now that all of the entities have
260
// loaded and populate the fields
261
for (int velInd = 0; velInd < tempViewEntityList.size(); velInd++) {
262                         ModelViewEntity curViewEntity = (ModelViewEntity) tempViewEntityList.get(velInd);
263                         curViewEntity.populateFields(this);
264                         List JavaDoc memberEntities = curViewEntity.getAllModelMemberEntities();
265                         for (int j = 0; j < memberEntities.size(); j++) {
266                             ModelViewEntity.ModelMemberEntity mve = (ModelViewEntity.ModelMemberEntity) memberEntities.get(j);
267                             ModelEntity me = (ModelEntity) entityCache.get(mve.getEntityName());
268                             if (me == null) throw new GenericEntityConfException("View " + curViewEntity.getEntityName() + " references non-existant entity: " + mve.getEntityName());
269                             me.addViewEntity(curViewEntity);
270                         }
271                     }
272                     
273                     // auto-create relationships
274
TreeSet JavaDoc orderedMessages = new TreeSet JavaDoc();
275                     Iterator JavaDoc entityNamesIter = new TreeSet JavaDoc(this.getEntityNames()).iterator();
276                     while (entityNamesIter.hasNext()) {
277                         String JavaDoc curEntityName = (String JavaDoc) entityNamesIter.next();
278                         ModelEntity curModelEntity = this.getModelEntity(curEntityName);
279                         if (curModelEntity instanceof ModelViewEntity) {
280                             // for view-entities auto-create relationships for all member-entity relationships that have all corresponding fields in the view-entity
281

282                         } else {
283                             // for entities auto-create many relationships for all type one relationships
284

285                             // just in case we add a new relation to the same entity, keep in a separate list and add them at the end
286
List JavaDoc newSameEntityRelations = FastList.newInstance();
287                             
288                             Iterator JavaDoc relationsIter = curModelEntity.getRelationsIterator();
289                             while (relationsIter.hasNext()) {
290                                 ModelRelation modelRelation = (ModelRelation) relationsIter.next();
291                                 if (("one".equals(modelRelation.getType()) || "one-nofk".equals(modelRelation.getType())) && !modelRelation.isAutoRelation()) {
292                                     ModelEntity relatedEnt = null;
293                                     try {
294                                         relatedEnt = this.getModelEntity(modelRelation.getRelEntityName());
295                                     } catch (GenericModelException e) {
296                                         throw new GenericModelException("Error getting related entity [" + modelRelation.getRelEntityName() + "] definition from entity [" + curEntityName + "]", e);
297                                     }
298                                     if (relatedEnt != null) {
299                                         // don't do relationship to the same entity, unless title is "Parent", then do a "Child" automatically
300
String JavaDoc targetTitle = modelRelation.getTitle();
301                                         if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName()) && "Parent".equals(targetTitle)) {
302                                             targetTitle = "Child";
303                                         }
304                                         
305                                         // create the new relationship even if one exists so we can show what we are looking for in the info message
306
ModelRelation newRel = new ModelRelation();
307                                         newRel.setModelEntity(relatedEnt);
308                                         newRel.setRelEntityName(curModelEntity.getEntityName());
309                                         newRel.setTitle(targetTitle);
310                                         newRel.setAutoRelation(true);
311                                         Set JavaDoc curEntityKeyFields = FastSet.newInstance();
312                                         for (int kmn = 0; kmn < modelRelation.getKeyMapsSize(); kmn++) {
313                                             ModelKeyMap curkm = modelRelation.getKeyMap(kmn);
314                                             ModelKeyMap newkm = new ModelKeyMap();
315                                             newRel.addKeyMap(newkm);
316                                             newkm.setFieldName(curkm.getRelFieldName());
317                                             newkm.setRelFieldName(curkm.getFieldName());
318                                             curEntityKeyFields.add(curkm.getFieldName());
319                                         }
320                                         // decide whether it should be one or many by seeing if the key map represents the complete pk of the relEntity
321
if (curModelEntity.containsAllPkFieldNames(curEntityKeyFields)) {
322                                             // always use one-nofk, we don't want auto-fks getting in for these automatic ones
323
newRel.setType("one-nofk");
324                                             
325                                             // to keep it clean, remove any additional keys that aren't part of the PK
326
List JavaDoc curPkFieldNames = curModelEntity.getPkFieldNames();
327                                             Iterator JavaDoc nrkmIter = newRel.getKeyMapsIterator();
328                                             while (nrkmIter.hasNext()) {
329                                                 ModelKeyMap nrkm = (ModelKeyMap) nrkmIter.next();
330                                                 String JavaDoc checkField = nrkm.getRelFieldName();
331                                                 if (!curPkFieldNames.contains(checkField)) {
332                                                     nrkmIter.remove();
333                                                 }
334                                             }
335                                         } else {
336                                             newRel.setType("many");
337                                         }
338                                         
339                                         ModelRelation existingRelation = relatedEnt.getRelation(targetTitle + curModelEntity.getEntityName());
340                                         if (existingRelation == null) {
341                                             numAutoRelations++;
342                                             if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName())) {
343                                                 newSameEntityRelations.add(newRel);
344                                             } else {
345                                                 relatedEnt.addRelation(newRel);
346                                             }
347                                         } else {
348                                             if (newRel.equals(existingRelation)) {
349                                                 // don't warn if the target title+entity = current title+entity
350
if (!(targetTitle + curModelEntity.getEntityName()).equals(modelRelation.getTitle() + modelRelation.getRelEntityName())) {
351                                                     //String errorMsg = "Relation already exists to entity [] with title [" + targetTitle + "],from entity []";
352
String JavaDoc message = "Entity [" + relatedEnt.getPackageName() + ":" + relatedEnt.getEntityName() + "] already has identical relationship to entity [" +
353                                                             curModelEntity.getEntityName() + "] title [" + targetTitle + "]; would auto-create: type [" +
354                                                             newRel.getType() + "] and fields [" + newRel.keyMapString(",", "") + "]";
355                                                     orderedMessages.add(message);
356                                                 }
357                                             } else {
358                                                 String JavaDoc message = "Existing relationship with the same name, but different specs found from what would be auto-created for Entity [" + relatedEnt.getEntityName() + "] ant relationship to entity [" +
359                                                         curModelEntity.getEntityName() + "] title [" + targetTitle + "]; would auto-create: type [" +
360                                                         newRel.getType() + "] and fields [" + newRel.keyMapString(",", "") + "]";
361                                                 //Debug.logInfo(message, module);
362
}
363                                         }
364                                     } else {
365                                         String JavaDoc errorMsg = "Could not find related entity ["
366                                                 + modelRelation.getRelEntityName() + "], no reverse relation added.";
367                                         Debug.logWarning(errorMsg, module);
368                                     }
369                                 }
370                             }
371                             
372                             if (newSameEntityRelations.size() > 0) {
373                                 Iterator JavaDoc newRelsIter = newSameEntityRelations.iterator();
374                                 while (newRelsIter.hasNext()) {
375                                     ModelRelation newRel = (ModelRelation) newRelsIter.next();
376                                     curModelEntity.addRelation(newRel);
377                                 }
378                             }
379                         }
380                     }
381                     
382                     Iterator JavaDoc omIter = orderedMessages.iterator();
383                     while (omIter.hasNext()) {
384                         Debug.logInfo((String JavaDoc) omIter.next(), module);
385                     }
386
387                     Debug.log("FINISHED LOADING ENTITIES - ALL FILES; #Entities=" + numEntities + " #ViewEntities=" +
388                         numViewEntities + " #Fields=" + numFields + " #Relationships=" + numRelations + " #AutoRelationships=" + numAutoRelations, module);
389                 }
390             }
391         }
392         return entityCache;
393     }
394
395     /** rebuilds the resourceHandlerEntities Map of Collections based on the current
396      * entityResourceHandlerMap Map, must be done whenever a manual change is made to the
397      * entityResourceHandlerMap Map after the initial load to make them consistent again.
398      */

399     public void rebuildResourceHandlerEntities() {
400         resourceHandlerEntities = FastMap.newInstance();
401         Iterator JavaDoc entityResourceIter = entityResourceHandlerMap.entrySet().iterator();
402
403         while (entityResourceIter.hasNext()) {
404             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entityResourceIter.next();
405             // add entityName to appropriate resourceHandlerEntities collection
406
Collection JavaDoc resourceHandlerEntityNames = (Collection JavaDoc) resourceHandlerEntities.get(entry.getValue());
407
408             if (resourceHandlerEntityNames == null) {
409                 resourceHandlerEntityNames = FastList.newInstance();
410                 resourceHandlerEntities.put(entry.getValue(), resourceHandlerEntityNames);
411             }
412             resourceHandlerEntityNames.add(entry.getKey());
413         }
414     }
415
416     public Iterator JavaDoc getResourceHandlerEntitiesKeyIterator() {
417         if (resourceHandlerEntities == null) return null;
418         return resourceHandlerEntities.keySet().iterator();
419     }
420
421     public Collection JavaDoc getResourceHandlerEntities(ResourceHandler resourceHandler) {
422         if (resourceHandlerEntities == null) return null;
423         return (Collection JavaDoc) resourceHandlerEntities.get(resourceHandler);
424     }
425
426     public void addEntityToResourceHandler(String JavaDoc entityName, String JavaDoc loaderName, String JavaDoc location) {
427         entityResourceHandlerMap.put(entityName, new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, loaderName, location));
428     }
429
430     public ResourceHandler getEntityResourceHandler(String JavaDoc entityName) {
431         return (ResourceHandler) entityResourceHandlerMap.get(entityName);
432     }
433
434     /** Gets an Entity object based on a definition from the specified XML Entity descriptor file.
435      * @param entityName The entityName of the Entity definition to use.
436      * @return An Entity object describing the specified entity of the specified descriptor file.
437      */

438     public ModelEntity getModelEntity(String JavaDoc entityName) throws GenericEntityException {
439         if (entityName == null) {
440             throw new IllegalArgumentException JavaDoc("Tried to find entity definition for a null entityName");
441         }
442         Map JavaDoc ec = getEntityCache();
443         if (ec == null) {
444             throw new GenericEntityConfException("ERROR: Unable to load Entity Cache");
445         }
446         ModelEntity modelEntity = (ModelEntity) ec.get(entityName);
447         if (modelEntity == null) {
448             throw new GenericModelException("Could not find definition for entity name " + entityName);
449         }
450         return modelEntity;
451     }
452
453     public ModelEntity getModelEntityNoCheck(String JavaDoc entityName) {
454         Map JavaDoc ec = null;
455         try {
456             ec = getEntityCache();
457         } catch (GenericEntityException e) {
458             Debug.logError(e, "Error getting entity cache", module);
459         }
460         if (ec == null) {
461             return null;
462         }
463         ModelEntity modelEntity = (ModelEntity) ec.get(entityName);
464         return modelEntity;
465     }
466
467     /** Creates a Iterator with the entityName of each Entity defined in the specified XML Entity Descriptor file.
468      * @return A Iterator of entityName Strings
469      */

470     public Iterator JavaDoc getEntityNamesIterator() throws GenericEntityException {
471         Collection JavaDoc collection = getEntityNames();
472         if (collection != null) {
473             return collection.iterator();
474         } else {
475             return null;
476         }
477     }
478
479     /** Creates a Collection with the entityName of each Entity defined in the specified XML Entity Descriptor file.
480      * @return A Collection of entityName Strings
481      */

482     public Collection JavaDoc getEntityNames() throws GenericEntityException {
483         Map JavaDoc ec = getEntityCache();
484         if (ec == null) {
485             throw new GenericEntityConfException("ERROR: Unable to load Entity Cache");
486         }
487         return ec.keySet();
488     }
489
490     ModelEntity createModelEntity(Element JavaDoc entityElement, UtilTimer utilTimer, ModelInfo def) {
491         if (entityElement == null) return null;
492         this.numEntities++;
493         ModelEntity entity = new ModelEntity(this, entityElement, utilTimer, def);
494         return entity;
495     }
496
497     ModelEntity createModelViewEntity(Element JavaDoc entityElement, UtilTimer utilTimer, ModelInfo def) {
498         if (entityElement == null) return null;
499         this.numViewEntities++;
500         ModelViewEntity entity = new ModelViewEntity(this, entityElement, utilTimer, def);
501         return entity;
502     }
503
504     public ModelRelation createRelation(ModelEntity entity, Element JavaDoc relationElement) {
505         this.numRelations++;
506         ModelRelation relation = new ModelRelation(entity, relationElement);
507         return relation;
508     }
509
510     public ModelField findModelField(ModelEntity entity, String JavaDoc fieldName) {
511         for (int i = 0; i < entity.fields.size(); i++) {
512             ModelField field = (ModelField) entity.fields.get(i);
513             if (field.name.compareTo(fieldName) == 0) {
514                 return field;
515             }
516         }
517         return null;
518     }
519
520     public ModelField createModelField(String JavaDoc name, String JavaDoc type, String JavaDoc colName, boolean isPk) {
521         this.numFields++;
522         ModelField field = new ModelField(name, type, colName, isPk);
523         return field;
524     }
525     
526     public ModelField createModelField(Element JavaDoc fieldElement) {
527         if (fieldElement == null) {
528             return null;
529         }
530
531         this.numFields++;
532         ModelField field = new ModelField(fieldElement);
533         return field;
534     }
535 }
536
Popular Tags