svn commit: r585838 [2/2] - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r585838 [2/2] - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/

doogie-3
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java?rev=585838&r1=585837&r2=585838&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java Wed Oct 17 20:47:31 2007
@@ -55,9 +55,9 @@
 public class ModelReader implements Serializable {
 
     public static final String module = ModelReader.class.getName();
-    public static UtilCache readers = new UtilCache("entity.ModelReader", 0, 0);
+    public static UtilCache<String, ModelReader> readers = new UtilCache<String, ModelReader>("entity.ModelReader", 0, 0);
 
-    protected Map entityCache = null;
+    protected Map<String, ModelEntity> entityCache = null;
 
     protected int numEntities = 0;
     protected int numViewEntities = 0;
@@ -68,13 +68,13 @@
     protected String modelName;
 
     /** collection of filenames for entity definitions */
-    protected Collection entityResourceHandlers;
+    protected Collection<ResourceHandler> entityResourceHandlers;
 
     /** contains a collection of entity names for each ResourceHandler, populated as they are loaded */
-    protected Map resourceHandlerEntities;
+    protected Map<ResourceHandler, Collection<String>> resourceHandlerEntities;
 
     /** for each entity contains a map to the ResourceHandler that the entity came from */
-    protected Map entityResourceHandlerMap;
+    protected Map<String, ResourceHandler> entityResourceHandlerMap;
 
     public static ModelReader getModelReader(String delegatorName) throws GenericEntityException {
         DelegatorInfo delegatorInfo = EntityConfigUtil.getDelegatorInfo(delegatorName);
@@ -84,12 +84,12 @@
         }
 
         String tempModelName = delegatorInfo.entityModelReader;
-        ModelReader reader = (ModelReader) readers.get(tempModelName);
+        ModelReader reader = readers.get(tempModelName);
 
         if (reader == null) { // don't want to block here
             synchronized (ModelReader.class) {
                 // must check if null again as one of the blocked threads can still enter
-                reader = (ModelReader) readers.get(tempModelName);
+                reader = readers.get(tempModelName);
                 if (reader == null) {
                     reader = new ModelReader(tempModelName);
                     // preload caches...
@@ -114,26 +114,72 @@
         }
 
         // get all of the main resource model stuff, ie specified in the entityengine.xml file
-        List resourceElements = entityModelReaderInfo.resourceElements;
-        Iterator resIter = resourceElements.iterator();
-        while (resIter.hasNext()) {
-            Element resourceElement = (Element) resIter.next();
+        for (Element resourceElement: entityModelReaderInfo.resourceElements) {
             ResourceHandler handler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, resourceElement);
             entityResourceHandlers.add(handler);
         }
         
         // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
-        List componentResourceInfos = ComponentConfig.getAllEntityResourceInfos("model");
-        Iterator componentResourceInfoIter = componentResourceInfos.iterator();
-        while (componentResourceInfoIter.hasNext()) {
-            ComponentConfig.EntityResourceInfo componentResourceInfo = (ComponentConfig.EntityResourceInfo) componentResourceInfoIter.next();
+        for (ComponentConfig.EntityResourceInfo componentResourceInfo: ComponentConfig.getAllEntityResourceInfos("model")) {
             if (modelName.equals(componentResourceInfo.readerName)) {
                 entityResourceHandlers.add(componentResourceInfo.createResourceHandler());
             }
         }
     }
 
-    public Map getEntityCache() throws GenericEntityException {
+    private ModelEntity buildEntity(ResourceHandler entityResourceHandler, Element curEntityElement, int i, ModelInfo def) throws GenericEntityException {
+        boolean isEntity = "entity".equals(curEntityElement.getNodeName());
+        String entityName = UtilXml.checkEmpty(curEntityElement.getAttribute("entity-name")).intern();
+
+        // add entityName to appropriate resourceHandlerEntities collection
+        Collection<String> resourceHandlerEntityNames = resourceHandlerEntities.get(entityResourceHandler);
+
+        if (resourceHandlerEntityNames == null) {
+            resourceHandlerEntityNames = FastList.newInstance();
+            resourceHandlerEntities.put(entityResourceHandler, resourceHandlerEntityNames);
+        }
+        resourceHandlerEntityNames.add(entityName);
+
+        // check to see if entity with same name has already been read
+        if (entityCache.containsKey(entityName)) {
+            Debug.logWarning("WARNING: Entity " + entityName +
+                " is defined more than once, most recent will over-write " +
+                "previous definition(s)", module);
+            Debug.logWarning("WARNING: Entity " + entityName + " was found in " +
+                entityResourceHandler + ", but was already defined in " +
+                entityResourceHandlerMap.get(entityName).toString(), module);
+        }
+
+        // add entityName, entityFileName pair to entityResourceHandlerMap map
+        entityResourceHandlerMap.put(entityName, entityResourceHandler);
+
+        // utilTimer.timerString("  After entityEntityName -- " + i + " --");
+        // ModelEntity entity = createModelEntity(curEntity, utilTimer);
+
+        ModelEntity modelEntity = null;
+        if (isEntity) {
+            modelEntity = createModelEntity(curEntityElement, null, def);
+        } else {
+            modelEntity = createModelViewEntity(curEntityElement, null, def);
+        }
+
+        // utilTimer.timerString("  After createModelEntity -- " + i + " --");
+        if (modelEntity != null) {
+            entityCache.put(entityName, modelEntity);
+            // utilTimer.timerString("  After entityCache.put -- " + i + " --");
+            if (isEntity) {
+                if (Debug.verboseOn()) Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
+            } else {
+                if (Debug.verboseOn()) Debug.logVerbose("-- [ViewEntity]: #" + i + ": " + entityName, module);
+            }
+        } else {
+            Debug.logWarning("-- -- ENTITYGEN ERROR:getModelEntity: Could not create " +
+                "entity for entityName: " + entityName, module);
+        }
+        return modelEntity;
+    }
+
+    public Map<String, ModelEntity> getEntityCache() throws GenericEntityException {
         if (entityCache == null) { // don't want to block here
             synchronized (ModelReader.class) {
                 // must check if null again as one of the blocked threads can still enter
@@ -145,14 +191,12 @@
                     numAutoRelations = 0;
 
                     entityCache = FastMap.newInstance();
-                    List tempViewEntityList = FastList.newInstance();
-                    List tempExtendEntityElementList = FastList.newInstance();
+                    List<ModelViewEntity> tempViewEntityList = FastList.newInstance();
+                    List<Element> tempExtendEntityElementList = FastList.newInstance();
 
                     UtilTimer utilTimer = new UtilTimer();
                     
-                    Iterator rhIter = entityResourceHandlers.iterator();
-                    while (rhIter.hasNext()) {
-                        ResourceHandler entityResourceHandler = (ResourceHandler) rhIter.next();
+                    for (ResourceHandler entityResourceHandler: entityResourceHandlers) {
 
                         // utilTimer.timerString("Before getDocument in file " + entityFileName);
                         Document document = null;
@@ -189,59 +233,11 @@
 
                                 if ((isEntity || isViewEntity) && curChild.getNodeType() == Node.ELEMENT_NODE) {
                                     i++;
-                                    Element curEntityElement = (Element) curChild;
-                                    String entityName = UtilXml.checkEmpty(curEntityElement.getAttribute("entity-name")).intern();
-
-                                    // add entityName to appropriate resourceHandlerEntities collection
-                                    Collection resourceHandlerEntityNames = (Collection) resourceHandlerEntities.get(entityResourceHandler);
-
-                                    if (resourceHandlerEntityNames == null) {
-                                        resourceHandlerEntityNames = FastList.newInstance();
-                                        resourceHandlerEntities.put(entityResourceHandler, resourceHandlerEntityNames);
-                                    }
-                                    resourceHandlerEntityNames.add(entityName);
-
-                                    // check to see if entity with same name has already been read
-                                    if (entityCache.containsKey(entityName)) {
-                                        Debug.logWarning("WARNING: Entity " + entityName +
-                                            " is defined more than once, most recent will over-write " +
-                                            "previous definition(s)", module);
-                                        Debug.logWarning("WARNING: Entity " + entityName + " was found in " +
-                                            entityResourceHandler + ", but was already defined in " +
-                                            entityResourceHandlerMap.get(entityName).toString(), module);
-                                    }
-
-                                    // add entityName, entityFileName pair to entityResourceHandlerMap map
-                                    entityResourceHandlerMap.put(entityName, entityResourceHandler);
-
-                                    // utilTimer.timerString("  After entityEntityName -- " + i + " --");
-                                    // ModelEntity entity = createModelEntity(curEntity, utilTimer);
-
-                                    ModelEntity modelEntity = null;
-                                    if (isEntity) {
-                                        modelEntity = createModelEntity(curEntityElement, null, def);
-                                    } else {
-                                        modelEntity = createModelViewEntity(curEntityElement, null, def);
-                                        // put the view entity in a list to get ready for the second pass to populate fields...
-                                        tempViewEntityList.add(modelEntity);
-                                    }
-
-                                    // utilTimer.timerString("  After createModelEntity -- " + i + " --");
-                                    if (modelEntity != null) {
-                                        entityCache.put(entityName, modelEntity);
-                                        // utilTimer.timerString("  After entityCache.put -- " + i + " --");
-                                        if (isEntity) {
-                                            if (Debug.verboseOn()) Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
-                                        } else {
-                                            if (Debug.verboseOn()) Debug.logVerbose("-- [ViewEntity]: #" + i + ": " + entityName, module);
-                                        }
-                                    } else {
-                                        Debug.logWarning("-- -- ENTITYGEN ERROR:getModelEntity: Could not create " +
-                                            "entity for entityName: " + entityName, module);
-                                    }
-
+                                    ModelEntity modelEntity = buildEntity(entityResourceHandler, (Element) curChild, i, def);
+                                    // put the view entity in a list to get ready for the second pass to populate fields...
+                                    if (isViewEntity) tempViewEntityList.add((ModelViewEntity) modelEntity);
                                 } else if (isExtendEntity && curChild.getNodeType() == Node.ELEMENT_NODE) {
-                                    tempExtendEntityElementList.add(curChild);
+                                    tempExtendEntityElementList.add((Element) curChild);
                                 }
                             } while ((curChild = curChild.getNextSibling()) != null);
                         } else {
@@ -251,9 +247,7 @@
                     }
                     
                     // all entity elements in, now go through extend-entity elements and add their stuff
-                    Iterator tempExtendEntityElementIter = tempExtendEntityElementList.iterator();
-                    while (tempExtendEntityElementIter.hasNext()) {
-                        Element extendEntityElement = (Element) tempExtendEntityElementIter.next();
+                    for (Element extendEntityElement: tempExtendEntityElementList) {
                         String entityName = UtilXml.checkEmpty(extendEntityElement.getAttribute("entity-name"));
                         ModelEntity modelEntity = (ModelEntity) entityCache.get(entityName);
                         if (modelEntity == null) throw new GenericEntityConfException("Entity to extend does not exist: " + entityName);
@@ -262,15 +256,10 @@
 
                     // do a pass on all of the view entities now that all of the entities have
                     // loaded and populate the fields
-                    Iterator tempViewEntityIter = tempViewEntityList.iterator();
-                    while (tempViewEntityIter.hasNext()) {
-                        ModelViewEntity curViewEntity = (ModelViewEntity) tempViewEntityIter.next();
+                    for (ModelViewEntity curViewEntity: tempViewEntityList) {
                         
                         curViewEntity.populateFields(this);
-                        List memberEntities = curViewEntity.getAllModelMemberEntities();
-                        Iterator memberEntityIter = memberEntities.iterator();
-                        while (memberEntityIter.hasNext()) {
-                            ModelViewEntity.ModelMemberEntity mve = (ModelViewEntity.ModelMemberEntity) memberEntityIter.next();
+                        for (ModelViewEntity.ModelMemberEntity mve: curViewEntity.getAllModelMemberEntities()) {
                             
                             ModelEntity me = (ModelEntity) entityCache.get(mve.getEntityName());
                             if (me == null) throw new GenericEntityConfException("View " + curViewEntity.getEntityName() + " references non-existant entity: " + mve.getEntityName());
@@ -279,10 +268,8 @@
                     }
                     
                     // auto-create relationships
-                    TreeSet orderedMessages = new TreeSet();
-                    Iterator entityNamesIter = new TreeSet(this.getEntityNames()).iterator();
-                    while (entityNamesIter.hasNext()) {
-                        String curEntityName = (String) entityNamesIter.next();
+                    TreeSet<String> orderedMessages = new TreeSet<String>();
+                    for (String curEntityName: new TreeSet<String>(this.getEntityNames())) {
                         ModelEntity curModelEntity = this.getModelEntity(curEntityName);
                         if (curModelEntity instanceof ModelViewEntity) {
                             // for view-entities auto-create relationships for all member-entity relationships that have all corresponding fields in the view-entity
@@ -291,11 +278,11 @@
                             // for entities auto-create many relationships for all type one relationships
                             
                             // just in case we add a new relation to the same entity, keep in a separate list and add them at the end
-                            List newSameEntityRelations = FastList.newInstance();
+                            List<ModelRelation> newSameEntityRelations = FastList.newInstance();
                             
-                            Iterator relationsIter = curModelEntity.getRelationsIterator();
+                            Iterator<ModelRelation> relationsIter = curModelEntity.getRelationsIterator();
                             while (relationsIter.hasNext()) {
-                                ModelRelation modelRelation = (ModelRelation) relationsIter.next();
+                                ModelRelation modelRelation = relationsIter.next();
                                 if (("one".equals(modelRelation.getType()) || "one-nofk".equals(modelRelation.getType())) && !modelRelation.isAutoRelation()) {
                                     ModelEntity relatedEnt = null;
                                     try {
@@ -316,7 +303,7 @@
                                         newRel.setRelEntityName(curModelEntity.getEntityName());
                                         newRel.setTitle(targetTitle);
                                         newRel.setAutoRelation(true);
-                                        Set curEntityKeyFields = FastSet.newInstance();
+                                        Set<String> curEntityKeyFields = FastSet.newInstance();
                                         for (int kmn = 0; kmn < modelRelation.getKeyMapsSize(); kmn++) {
                                             ModelKeyMap curkm = modelRelation.getKeyMap(kmn);
                                             ModelKeyMap newkm = new ModelKeyMap();
@@ -331,10 +318,10 @@
                                             newRel.setType("one-nofk");
                                             
                                             // to keep it clean, remove any additional keys that aren't part of the PK
-                                            List curPkFieldNames = curModelEntity.getPkFieldNames();
-                                            Iterator nrkmIter = newRel.getKeyMapsIterator();
+                                            List<String> curPkFieldNames = curModelEntity.getPkFieldNames();
+                                            Iterator<ModelKeyMap> nrkmIter = newRel.getKeyMapsIterator();
                                             while (nrkmIter.hasNext()) {
-                                                ModelKeyMap nrkm = (ModelKeyMap) nrkmIter.next();
+                                                ModelKeyMap nrkm =nrkmIter.next();
                                                 String checkField = nrkm.getRelFieldName();
                                                 if (!curPkFieldNames.contains(checkField)) {
                                                     nrkmIter.remove();
@@ -378,18 +365,15 @@
                             }
                             
                             if (newSameEntityRelations.size() > 0) {
-                                Iterator newRelsIter = newSameEntityRelations.iterator();
-                                while (newRelsIter.hasNext()) {
-                                    ModelRelation newRel = (ModelRelation) newRelsIter.next();
+                                for (ModelRelation newRel: newSameEntityRelations) {
                                     curModelEntity.addRelation(newRel);
                                 }
                             }
                         }
                     }
                     
-                    Iterator omIter = orderedMessages.iterator();
-                    while (omIter.hasNext()) {
-                        Debug.logInfo((String) omIter.next(), module);
+                    for (String message: orderedMessages) {
+                        Debug.logInfo(message, module);
                     }
 
                     Debug.log("FINISHED LOADING ENTITIES - ALL FILES; #Entities=" + numEntities + " #ViewEntities=" +
@@ -406,12 +390,12 @@
      */
     public void rebuildResourceHandlerEntities() {
         resourceHandlerEntities = FastMap.newInstance();
-        Iterator entityResourceIter = entityResourceHandlerMap.entrySet().iterator();
+        Iterator<Map.Entry<String, ResourceHandler>> entityResourceIter = entityResourceHandlerMap.entrySet().iterator();
 
         while (entityResourceIter.hasNext()) {
-            Map.Entry entry = (Map.Entry) entityResourceIter.next();
+            Map.Entry<String, ResourceHandler> entry = entityResourceIter.next();
             // add entityName to appropriate resourceHandlerEntities collection
-            Collection resourceHandlerEntityNames = (Collection) resourceHandlerEntities.get(entry.getValue());
+            Collection<String> resourceHandlerEntityNames = resourceHandlerEntities.get(entry.getValue());
 
             if (resourceHandlerEntityNames == null) {
                 resourceHandlerEntityNames = FastList.newInstance();
@@ -421,14 +405,14 @@
         }
     }
 
-    public Iterator getResourceHandlerEntitiesKeyIterator() {
+    public Iterator<ResourceHandler> getResourceHandlerEntitiesKeyIterator() {
         if (resourceHandlerEntities == null) return null;
         return resourceHandlerEntities.keySet().iterator();
     }
 
-    public Collection getResourceHandlerEntities(ResourceHandler resourceHandler) {
+    public Collection<String> getResourceHandlerEntities(ResourceHandler resourceHandler) {
         if (resourceHandlerEntities == null) return null;
-        return (Collection) resourceHandlerEntities.get(resourceHandler);
+        return resourceHandlerEntities.get(resourceHandler);
     }
 
     public void addEntityToResourceHandler(String entityName, String loaderName, String location) {
@@ -436,7 +420,7 @@
     }
 
     public ResourceHandler getEntityResourceHandler(String entityName) {
-        return (ResourceHandler) entityResourceHandlerMap.get(entityName);
+        return entityResourceHandlerMap.get(entityName);
     }
 
     /** Gets an Entity object based on a definition from the specified XML Entity descriptor file.
@@ -447,11 +431,11 @@
         if (entityName == null) {
             throw new IllegalArgumentException("Tried to find entity definition for a null entityName");
         }
-        Map ec = getEntityCache();
+        Map<String, ModelEntity> ec = getEntityCache();
         if (ec == null) {
             throw new GenericEntityConfException("ERROR: Unable to load Entity Cache");
         }
-        ModelEntity modelEntity = (ModelEntity) ec.get(entityName);
+        ModelEntity modelEntity = ec.get(entityName);
         if (modelEntity == null) {
             throw new GenericModelException("Could not find definition for entity name " + entityName);
         }
@@ -459,7 +443,7 @@
     }
 
     public ModelEntity getModelEntityNoCheck(String entityName) {
-        Map ec = null;
+        Map<String, ModelEntity> ec = null;
         try {
             ec = getEntityCache();
         } catch (GenericEntityException e) {
@@ -468,15 +452,15 @@
         if (ec == null) {
             return null;
         }
-        ModelEntity modelEntity = (ModelEntity) ec.get(entityName);
+        ModelEntity modelEntity = ec.get(entityName);
         return modelEntity;
     }
 
     /** Creates a Iterator with the entityName of each Entity defined in the specified XML Entity Descriptor file.
      * @return A Iterator of entityName Strings
      */
-    public Iterator getEntityNamesIterator() throws GenericEntityException {
-        Collection collection = getEntityNames();
+    public Iterator<String> getEntityNamesIterator() throws GenericEntityException {
+        Collection<String> collection = getEntityNames();
         if (collection != null) {
             return collection.iterator();
         } else {
@@ -487,8 +471,8 @@
     /** Creates a Collection with the entityName of each Entity defined in the specified XML Entity Descriptor file.
      * @return A Collection of entityName Strings
      */
-    public Collection getEntityNames() throws GenericEntityException {
-        Map ec = getEntityCache();
+    public Collection<String> getEntityNames() throws GenericEntityException {
+        Map<String, ModelEntity> ec = getEntityCache();
         if (ec == null) {
             throw new GenericEntityConfException("ERROR: Unable to load Entity Cache");
         }
@@ -516,8 +500,7 @@
     }
 
     public ModelField findModelField(ModelEntity entity, String fieldName) {
-        for (int i = 0; i < entity.fields.size(); i++) {
-            ModelField field = (ModelField) entity.fields.get(i);
+        for (ModelField field: entity.fields) {
             if (field.name.compareTo(fieldName) == 0) {
                 return field;
             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java?rev=585838&r1=585837&r2=585838&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java Wed Oct 17 20:47:31 2007
@@ -42,7 +42,7 @@
     protected String fkName;
 
     /** keyMaps defining how to lookup the relatedTable using columns from this table */
-    protected List keyMaps = new ArrayList();
+    protected List<ModelKeyMap> keyMaps = new ArrayList<ModelKeyMap>();
 
     /** the main entity of this relation */
     protected ModelEntity mainEntity = null;
@@ -58,7 +58,7 @@
     }
 
     /** Default Constructor */
-    public ModelRelation(String type, String title, String relEntityName, String fkName, List keyMaps) {
+    public ModelRelation(String type, String title, String relEntityName, String fkName, List<ModelKeyMap> keyMaps) {
         this.title = title;
         if (title == null) title = "";
         this.type = type;
@@ -144,7 +144,7 @@
     }
 
     /** keyMaps defining how to lookup the relatedTable using columns from this table */
-    public Iterator getKeyMapsIterator() {
+    public Iterator<ModelKeyMap> getKeyMapsIterator() {
         return this.keyMaps.iterator();
     }
 
@@ -153,7 +153,7 @@
     }
 
     public ModelKeyMap getKeyMap(int index) {
-        return (ModelKeyMap) this.keyMaps.get(index);
+        return this.keyMaps.get(index);
     }
 
     public void addKeyMap(ModelKeyMap keyMap) {
@@ -161,14 +161,12 @@
     }
 
     public ModelKeyMap removeKeyMap(int index) {
-        return (ModelKeyMap) this.keyMaps.remove(index);
+        return this.keyMaps.remove(index);
     }
 
     /** Find a KeyMap with the specified fieldName */
     public ModelKeyMap findKeyMap(String fieldName) {
-        for (int i = 0; i < keyMaps.size(); i++) {
-            ModelKeyMap keyMap = (ModelKeyMap) keyMaps.get(i);
-
+        for (ModelKeyMap keyMap: keyMaps) {
             if (keyMap.fieldName.equals(fieldName)) return keyMap;
         }
         return null;
@@ -176,9 +174,7 @@
 
     /** Find a KeyMap with the specified relFieldName */
     public ModelKeyMap findKeyMapByRelated(String relFieldName) {
-        for (int i = 0; i < keyMaps.size(); i++) {
-            ModelKeyMap keyMap = (ModelKeyMap) keyMaps.get(i);
-
+        for (ModelKeyMap keyMap: keyMaps) {
             if (keyMap.relFieldName.equals(relFieldName))
                 return keyMap;
         }
@@ -195,9 +191,9 @@
         int i = 0;
 
         for (; i < keyMaps.size() - 1; i++) {
-            returnString = returnString + ((ModelKeyMap) keyMaps.get(i)).fieldName + separator;
+            returnString = returnString + keyMaps.get(i).fieldName + separator;
         }
-        returnString = returnString + ((ModelKeyMap) keyMaps.get(i)).fieldName + afterLast;
+        returnString = returnString + keyMaps.get(i).fieldName + afterLast;
         return returnString;
     }
 
@@ -208,7 +204,7 @@
         StringBuilder returnString = new StringBuilder( keyMaps.size() * 10 );
         int i=0;
         while (true) {
-            ModelKeyMap kmap = (ModelKeyMap) keyMaps.get(i);
+            ModelKeyMap kmap = keyMaps.get(i);
             returnString.append( ModelUtil.upperFirstChar( kmap.fieldName));
 
             i++;
@@ -230,7 +226,7 @@
         StringBuilder returnString = new StringBuilder( keyMaps.size() * 10 );
         int i=0;
         while (true) {
-            ModelKeyMap kmap = (ModelKeyMap) keyMaps.get(i);
+            ModelKeyMap kmap = keyMaps.get(i);
             returnString.append( ModelUtil.upperFirstChar( kmap.relFieldName ));
 
             i++;
@@ -257,6 +253,7 @@
         this.isAutoRelation = isAutoRelation;
     }
     
+    // FIXME: CCE
     public boolean equals(Object other) {
         ModelRelation otherRel = (ModelRelation) other;
         
@@ -264,8 +261,8 @@
         if (!otherRel.title.equals(this.title)) return false;
         if (!otherRel.relEntityName.equals(this.relEntityName)) return false;
         
-        Set thisKeyNames = new HashSet(this.keyMaps);
-        Set otherKeyNames = new HashSet(otherRel.keyMaps);
+        Set<ModelKeyMap> thisKeyNames = new HashSet<ModelKeyMap>(this.keyMaps);
+        Set<ModelKeyMap> otherKeyNames = new HashSet<ModelKeyMap>(otherRel.keyMaps);
         if (!thisKeyNames.containsAll(otherKeyNames)) return false;
         if (!otherKeyNames.containsAll(thisKeyNames)) return false;
         
@@ -284,9 +281,9 @@
             root.setAttribute("fk-name", this.getFkName());
         }
 
-        Iterator kmIter = this.getKeyMapsIterator();
+        Iterator<ModelKeyMap> kmIter = this.getKeyMapsIterator();
         while (kmIter != null && kmIter.hasNext()) {
-            ModelKeyMap km = (ModelKeyMap) kmIter.next();
+            ModelKeyMap km = kmIter.next();
             root.appendChild(km.toXmlElement(document));
         }
 

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=585838&r1=585837&r2=585838&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Wed Oct 17 20:47:31 2007
@@ -33,6 +33,7 @@
 import org.ofbiz.base.util.UtilTimer;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.jdbc.SqlJdbcUtil;
 import org.w3c.dom.Element;
@@ -44,7 +45,7 @@
 public class ModelViewEntity extends ModelEntity {
     public static final String module = ModelViewEntity.class.getName();
 
-    public static Map functionPrefixMap = FastMap.newInstance();
+    public static Map<String, String> functionPrefixMap = FastMap.newInstance();
     static {
         functionPrefixMap.put("min", "MIN(");
         functionPrefixMap.put("max", "MAX(");
@@ -57,27 +58,27 @@
     }
 
     /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */
-    protected Map memberModelMemberEntities = FastMap.newInstance();
+    protected Map<String, ModelMemberEntity> memberModelMemberEntities = FastMap.newInstance();
 
     /** A list of all ModelMemberEntity entries; this is mainly used to preserve the original order of member entities from the XML file */
-    protected List allModelMemberEntities = FastList.newInstance();
+    protected List<ModelMemberEntity> allModelMemberEntities = FastList.newInstance();
 
     /** Contains member-entity ModelEntities: key is alias, value is ModelEntity; populated with fields */
-    protected Map memberModelEntities = null;
+    protected Map<String, ModelEntity> memberModelEntities = null;
 
     /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */
-    protected List aliasAlls = FastList.newInstance();
+    protected List<ModelAliasAll> aliasAlls = FastList.newInstance();
 
     /** List of aliases with information in addition to what is in the standard field list */
-    protected List aliases = FastList.newInstance();
+    protected List<ModelAlias> aliases = FastList.newInstance();
 
     /** List of view links to define how entities are connected (or "joined") */
-    protected List viewLinks = FastList.newInstance();
+    protected List<ModelViewLink> viewLinks = FastList.newInstance();
 
     /** A List of the Field objects for the View Entity, one for each GROUP BY field */
-    protected List groupBys = FastList.newInstance();
+    protected List<ModelField> groupBys = FastList.newInstance();
 
-    protected Map conversions = FastMap.newInstance();
+    protected Map<String, Map<String, ModelConversion>> conversions = FastMap.newInstance();
 
     public ModelViewEntity(ModelReader reader, Element entityElement, UtilTimer utilTimer, ModelInfo def) {
         super(reader, entityElement, def);
@@ -86,10 +87,7 @@
         this.populateBasicInfo(entityElement);
 
         if (utilTimer != null) utilTimer.timerString("  createModelViewEntity: before \"member-entity\"s");
-        List memberEntityList = UtilXml.childElementList(entityElement, "member-entity");
-        Iterator memberEntityIter = memberEntityList.iterator();
-        while (memberEntityIter.hasNext()) {
-            Element memberEntityElement = (Element) memberEntityIter.next();
+        for (Element memberEntityElement: UtilXml.childElementList(entityElement, "member-entity")) {
             String alias = UtilXml.checkEmpty(memberEntityElement.getAttribute("entity-alias")).intern();
             String name = UtilXml.checkEmpty(memberEntityElement.getAttribute("entity-name")).intern();
             if (name.length() <= 0 || alias.length() <= 0) {
@@ -102,27 +100,18 @@
 
         // when reading aliases and alias-alls, just read them into the alias list, there will be a pass
         // after loading all entities to go back and fill in all of the ModelField entries
-        List aliasAllList = UtilXml.childElementList(entityElement, "alias-all");
-        Iterator aliasAllIter = aliasAllList.iterator();
-        while (aliasAllIter.hasNext()) {
-            Element aliasElement = (Element) aliasAllIter.next();
+        for (Element aliasElement: UtilXml.childElementList(entityElement, "alias-all")) {
             ModelViewEntity.ModelAliasAll aliasAll = new ModelAliasAll(aliasElement);
             this.aliasAlls.add(aliasAll);
         }
 
         if (utilTimer != null) utilTimer.timerString("  createModelViewEntity: before aliases");
-        List aliasList = UtilXml.childElementList(entityElement, "alias");
-        Iterator aliasIter = aliasList.iterator();
-        while (aliasIter.hasNext()) {
-            Element aliasElement = (Element) aliasIter.next();
+        for (Element aliasElement: UtilXml.childElementList(entityElement, "alias")) {
             ModelViewEntity.ModelAlias alias = new ModelAlias(aliasElement);
             this.aliases.add(alias);
         }
         
-        List viewLinkList = UtilXml.childElementList(entityElement, "view-link");
-        Iterator viewLinkIter = viewLinkList.iterator();
-        while (viewLinkIter.hasNext()) {
-            Element viewLinkElement = (Element) viewLinkIter.next();
+        for (Element viewLinkElement: UtilXml.childElementList(entityElement, "view-link")) {
             ModelViewLink viewLink = new ModelViewLink(viewLinkElement);
             this.addViewLink(viewLink);
         }
@@ -141,10 +130,10 @@
         this.defaultResourceName = dynamicViewEntity.getDefaultResourceName();
         
         // member-entities
-        Iterator modelMemberEntitiesEntryIter = dynamicViewEntity.getModelMemberEntitiesEntryIter();
+        Iterator<Map.Entry<String, ModelMemberEntity>> modelMemberEntitiesEntryIter = dynamicViewEntity.getModelMemberEntitiesEntryIter();
         while (modelMemberEntitiesEntryIter.hasNext()) {
-            Map.Entry entry = (Map.Entry) modelMemberEntitiesEntryIter.next();
-            this.addMemberModelMemberEntity((ModelMemberEntity) entry.getValue());
+            Map.Entry<String, ModelMemberEntity> entry = modelMemberEntitiesEntryIter.next();
+            this.addMemberModelMemberEntity(entry.getValue());
         }
         
         // alias-alls
@@ -164,16 +153,16 @@
         this.populateFieldsBasic(modelReader);
     }
 
-    public Map getMemberModelMemberEntities() {
+    public Map<String, ModelMemberEntity> getMemberModelMemberEntities() {
         return this.memberModelMemberEntities;
     }
 
-    public List getAllModelMemberEntities() {
+    public List<ModelMemberEntity> getAllModelMemberEntities() {
         return this.allModelMemberEntities;
     }
 
     public ModelMemberEntity getMemberModelMemberEntity(String alias) {
-        return (ModelMemberEntity) this.memberModelMemberEntities.get(alias);
+        return this.memberModelMemberEntities.get(alias);
     }
 
     public ModelEntity getMemberModelEntity(String alias) {
@@ -181,7 +170,7 @@
             this.memberModelEntities = FastMap.newInstance();
             populateFields(this.getModelReader());
         }
-        return (ModelEntity) this.memberModelEntities.get(alias);
+        return this.memberModelEntities.get(alias);
     }
 
     public void addMemberModelMemberEntity(ModelMemberEntity modelMemberEntity) {
@@ -190,7 +179,7 @@
     }
 
     public void removeMemberModelMemberEntity(String alias) {
-        ModelMemberEntity modelMemberEntity = (ModelMemberEntity) this.memberModelMemberEntities.remove(alias);
+        ModelMemberEntity modelMemberEntity = this.memberModelMemberEntities.remove(alias);
 
         if (modelMemberEntity == null) return;
         this.allModelMemberEntities.remove(modelMemberEntity);
@@ -209,13 +198,13 @@
 
     /** List of aliases with information in addition to what is in the standard field list */
     public ModelAlias getAlias(int index) {
-        return (ModelAlias) this.aliases.get(index);
+        return this.aliases.get(index);
     }
     
     public ModelAlias getAlias(String name) {
-        Iterator aliasIter = getAliasesIterator();
+        Iterator<ModelAlias> aliasIter = getAliasesIterator();
         while (aliasIter.hasNext()) {
-            ModelAlias alias = (ModelAlias) aliasIter.next();
+            ModelAlias alias = aliasIter.next();
             if (alias.name.equals(name)) {
                 return alias;
             }
@@ -227,28 +216,26 @@
         return this.aliases.size();
     }
 
-    public Iterator getAliasesIterator() {
+    public Iterator<ModelAlias> getAliasesIterator() {
         return this.aliases.iterator();
     }
 
-    public List getAliasesCopy() {
-        List newList = FastList.newInstance();
+    public List<ModelAlias> getAliasesCopy() {
+        List<ModelAlias> newList = FastList.newInstance();
         newList.addAll(this.aliases);
         return newList;
     }
 
-    public List getGroupBysCopy() {
+    public List<ModelField> getGroupBysCopy() {
         return getGroupBysCopy(null);
     }
 
-    public List getGroupBysCopy(List selectFields) {
-        List newList = FastList.newInstance();
+    public List<ModelField> getGroupBysCopy(List<ModelField> selectFields) {
+        List<ModelField> newList = FastList.newInstance();
         if (UtilValidate.isEmpty(selectFields)) {
             newList.addAll(this.groupBys);
         } else {
-            Iterator groupBysIt = this.groupBys.iterator();
-            while (groupBysIt.hasNext()) {
-                ModelField groupByField = (ModelField)groupBysIt.next();
+            for (ModelField groupByField: this.groupBys) {
                 if (selectFields.contains(groupByField)) {
                     newList.add(groupByField);
                 }
@@ -259,19 +246,19 @@
 
     /** List of view links to define how entities are connected (or "joined") */
     public ModelViewLink getViewLink(int index) {
-        return (ModelViewLink) this.viewLinks.get(index);
+        return this.viewLinks.get(index);
     }
 
     public int getViewLinksSize() {
         return this.viewLinks.size();
     }
 
-    public Iterator getViewLinksIterator() {
+    public Iterator<ModelViewLink> getViewLinksIterator() {
         return this.viewLinks.iterator();
     }
 
-    public List getViewLinksCopy() {
-        List newList = FastList.newInstance();
+    public List<ModelViewLink> getViewLinksCopy() {
+        List<ModelViewLink> newList = FastList.newInstance();
         newList.addAll(this.viewLinks);
         return newList;
     }
@@ -284,16 +271,16 @@
         return colNameString(Arrays.asList(flds), separator, afterLast, alias);
     }
 
-    public String colNameString(List flds, String separator, String afterLast, boolean alias) {
+    public String colNameString(List<ModelField> flds, String separator, String afterLast, boolean alias) {
         StringBuilder returnString = new StringBuilder();
 
         if (flds.size() < 1) {
             return "";
         }
 
-        Iterator fldsIt = flds.iterator();
+        Iterator<ModelField> fldsIt = flds.iterator();
         while (fldsIt.hasNext()) {
-            ModelField field = (ModelField) fldsIt.next();
+            ModelField field = fldsIt.next();
             returnString.append(field.colName);
             if (alias) {
                 ModelAlias modelAlias = this.getAlias(field.name);
@@ -317,7 +304,7 @@
     }
 
     public ModelEntity getAliasedEntity(String entityAlias, ModelReader modelReader) {
-        ModelMemberEntity modelMemberEntity = (ModelMemberEntity) this.memberModelMemberEntities.get(entityAlias);
+        ModelMemberEntity modelMemberEntity = this.memberModelMemberEntities.get(entityAlias);
         if (modelMemberEntity == null) {
             Debug.logError("No member entity with alias " + entityAlias + " found in view-entity " + this.getEntityName() + "; this view-entity will NOT be usable...", module);
             return null;
@@ -352,20 +339,18 @@
             this.memberModelEntities = FastMap.newInstance();
         }
 
-        Iterator meIter = memberModelMemberEntities.entrySet().iterator();
-        while (meIter.hasNext()) {
-            Map.Entry entry = (Map.Entry) meIter.next();
+        for (Map.Entry<String, ModelMemberEntity> entry: memberModelMemberEntities.entrySet()) {
 
-            ModelMemberEntity modelMemberEntity = (ModelMemberEntity) entry.getValue();
+            ModelMemberEntity modelMemberEntity = entry.getValue();
             String aliasedEntityName = modelMemberEntity.getEntityName();
             ModelEntity aliasedEntity = modelReader.getModelEntityNoCheck(aliasedEntityName);
             if (aliasedEntity == null) {
                 continue;
             }
             memberModelEntities.put(entry.getKey(), aliasedEntity);
-            Iterator aliasedFieldIterator = aliasedEntity.getFieldsIterator();
+            Iterator<ModelField> aliasedFieldIterator = aliasedEntity.getFieldsIterator();
             while (aliasedFieldIterator.hasNext()) {
-                ModelField aliasedModelField = (ModelField) aliasedFieldIterator.next();
+                ModelField aliasedModelField = aliasedFieldIterator.next();
                 ModelField newModelField = new ModelField();
                 for (int i = 0; i < aliasedModelField.getValidatorsSize(); i++) {
                     newModelField.addValidator(aliasedModelField.getValidator(i));
@@ -380,8 +365,7 @@
 
         expandAllAliasAlls(modelReader);
 
-        for (int i = 0; i < aliases.size(); i++) {
-            ModelAlias alias = (ModelAlias) aliases.get(i);
+        for (ModelAlias alias: aliases) {
             ModelField field = new ModelField();
             field.setModelEntity(this);
             field.name = alias.name;
@@ -438,7 +422,7 @@
             }
 
             if (UtilValidate.isNotEmpty(alias.function)) {
-                String prefix = (String) functionPrefixMap.get(alias.function);
+                String prefix = functionPrefixMap.get(alias.function);
                 if (prefix == null) {
                     Debug.logWarning("Specified alias function [" + alias.function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module);
                 } else {
@@ -456,12 +440,12 @@
             throw new RuntimeException("Cannot create View Entity: " + errMsg);
         }
         
-        Map aliasConversions = (Map) conversions.get(member.getEntityName());
+        Map<String, ModelConversion> aliasConversions = conversions.get(member.getEntityName());
         if (aliasConversions == null) {
             aliasConversions = FastMap.newInstance();
             conversions.put(member.getEntityName(), aliasConversions);
         }
-        ModelConversion conversion = (ModelConversion) aliasConversions.get(aliasName);
+        ModelConversion conversion = aliasConversions.get(aliasName);
         if (conversion == null) {
             conversion = new ModelConversion(aliasName, member);
             aliasConversions.put(aliasName, conversion);
@@ -470,10 +454,10 @@
     }
 
     public void populateReverseLinks() {
-        Map containedModelFields = FastMap.newInstance();
-        Iterator it = getAliasesIterator();
+        Map<String, List<String>> containedModelFields = FastMap.newInstance();
+        Iterator<ModelAlias> it = getAliasesIterator();
         while (it.hasNext()) {
-            ModelViewEntity.ModelAlias alias = (ModelViewEntity.ModelAlias) it.next();
+            ModelViewEntity.ModelAlias alias = it.next();
             if (alias.isComplexAlias()) {
                 // TODO: conversion for complex-alias needs to be implemented for cache and in-memory eval stuff to work correctly
                 Debug.logWarning("Conversion for complex-alias needs to be implemented for cache and in-memory eval stuff to work correctly, will not work for alias: " + alias.getName() + " of view-entity " + this.getEntityName(), module);
@@ -482,7 +466,7 @@
                 conversion.addConversion(alias.getField(), alias.getName());
             }
 
-            List aliases = (List) containedModelFields.get(alias.getField());
+            List<String> aliases = containedModelFields.get(alias.getField());
             if (aliases == null) {
                 aliases = FastList.newInstance();
                 containedModelFields.put(alias.getField(), aliases);
@@ -490,38 +474,36 @@
             aliases.add(alias.getName());
         }
 
-        it = getViewLinksIterator();
-        while (it.hasNext()) {
-            ModelViewEntity.ModelViewLink link = (ModelViewEntity.ModelViewLink) it.next();
+        Iterator<ModelViewLink> it2 = getViewLinksIterator();
+        while (it2.hasNext()) {
+            ModelViewEntity.ModelViewLink link = it2.next();
 
             String leftAlias = link.getEntityAlias();
             String rightAlias = link.getRelEntityAlias();
             ModelConversion leftConversion = getOrCreateModelConversion(leftAlias);
             ModelConversion rightConversion = getOrCreateModelConversion(rightAlias);
-            Iterator it2 = link.getKeyMapsIterator();
+            Iterator<ModelKeyMap> it3 = link.getKeyMapsIterator();
             Debug.logVerbose(leftAlias + "<->" + rightAlias, module);
-            while (it2.hasNext()) {
-                ModelKeyMap mkm = (ModelKeyMap) it2.next();
+            while (it3.hasNext()) {
+                ModelKeyMap mkm = it3.next();
                 String leftFieldName = mkm.getFieldName();
                 String rightFieldName = mkm.getRelFieldName();
-                rightConversion.addAllAliasConversions((List) containedModelFields.get(leftFieldName), rightFieldName);
-                leftConversion.addAllAliasConversions((List) containedModelFields.get(rightFieldName), leftFieldName);
+                rightConversion.addAllAliasConversions(containedModelFields.get(leftFieldName), rightFieldName);
+                leftConversion.addAllAliasConversions(containedModelFields.get(rightFieldName), leftFieldName);
             }
         }
-        it = conversions.entrySet().iterator();
         int[] currentIndex = new int[conversions.size()];
         int[] maxIndex = new int[conversions.size()];
         ModelConversion[][] allConversions = new ModelConversion[conversions.size()][];
         int i = 0;
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
-            Map aliasConversions = (Map) entry.getValue();
+        for (Map<String, ModelConversion> aliasConversions: conversions.values()) {
             currentIndex[i] = 0;
             maxIndex[i] = aliasConversions.size();
             allConversions[i] = new ModelConversion[aliasConversions.size()];
-            Iterator it2 = aliasConversions.values().iterator();
-            for (int j = 0; it2.hasNext() && j < aliasConversions.size(); j++) {
-                allConversions[i][j] = (ModelConversion) it2.next();
+            int j = 0;
+            for (ModelConversion conversion: aliasConversions.values()) {
+                allConversions[i][j] = conversion;
+                j++;
             }
             i++;
         }
@@ -547,13 +529,11 @@
         Debug.logVerbose(this + ":" + conversions, module);
     }
 
-    public List convert(String fromEntityName, Map data) {
-        Map foo = (Map) conversions.get(fromEntityName);
+    public List<Map<String, Object>> convert(String fromEntityName, Map<String, Object> data) {
+        Map<String, ModelConversion> foo = conversions.get(fromEntityName);
         if (foo == null) return null;
-        Iterator it = foo.values().iterator();
-        List values = FastList.newInstance();
-        while (it.hasNext()) {
-            ModelConversion conversion = (ModelConversion) it.next();
+        List<Map<String, Object>> values = FastList.newInstance();
+        for (ModelConversion conversion: foo.values()) {
             values.add(conversion.convert(data));
         }
         return values;
@@ -563,14 +543,12 @@
      * Go through all aliasAlls and create an alias for each field of each member entity
      */
     private void expandAllAliasAlls(ModelReader modelReader) {
-        Iterator aliasAllIter = aliasAlls.iterator();
-        while (aliasAllIter.hasNext()) {
-            ModelAliasAll aliasAll = (ModelAliasAll) aliasAllIter.next();
+        for (ModelAliasAll aliasAll: aliasAlls) {
             String prefix = aliasAll.getPrefix();
             String function = aliasAll.getFunction();
             boolean groupBy = aliasAll.getGroupBy();
 
-            ModelMemberEntity modelMemberEntity = (ModelMemberEntity) memberModelMemberEntities.get(aliasAll.getEntityAlias());
+            ModelMemberEntity modelMemberEntity = memberModelMemberEntities.get(aliasAll.getEntityAlias());
             if (modelMemberEntity == null) {
                 Debug.logError("Member entity referred to in alias-all not found, ignoring: " + aliasAll.getEntityAlias(), module);
                 continue;
@@ -583,16 +561,14 @@
                 continue;
             }
 
-            List entFieldList = aliasedEntity.getAllFieldNames();
+            List<String> entFieldList = aliasedEntity.getAllFieldNames();
             if (entFieldList == null) {
                 Debug.logError("Entity referred to in member-entity " + aliasAll.getEntityAlias() + " has no fields, ignoring: " + aliasedEntityName, module);
                 continue;
             }
 
-            Iterator fieldnamesIterator = entFieldList.iterator();
-            while (fieldnamesIterator.hasNext()) {
+            for (String fieldName: entFieldList) {
                 // now merge the lists, leaving out any that duplicate an existing alias name
-                String fieldName = (String) fieldnamesIterator.next();
                 String aliasName = fieldName;
                 ModelField modelField = aliasedEntity.getField(fieldName);
                 if (modelField.getIsAutoCreatedInternal()) {
@@ -616,9 +592,9 @@
                 if (existingAlias != null) {
                     //log differently if this is part of a view-link key-map because that is a common case when a field will be auto-expanded multiple times
                     boolean isInViewLink = false;
-                    Iterator viewLinkIter = this.getViewLinksIterator();
+                    Iterator<ModelViewLink> viewLinkIter = this.getViewLinksIterator();
                     while (viewLinkIter.hasNext() && !isInViewLink) {
-                        ModelViewLink modelViewLink = (ModelViewLink) viewLinkIter.next();
+                        ModelViewLink modelViewLink = viewLinkIter.next();
                         boolean isRel = false;
                         if (modelViewLink.getRelEntityAlias().equals(aliasAll.getEntityAlias())) {
                             isRel = true;
@@ -626,9 +602,9 @@
                             // not the rel-entity-alias or the entity-alias, so move along
                             continue;
                         }
-                        Iterator keyMapIter = modelViewLink.getKeyMapsIterator();
+                        Iterator<ModelKeyMap> keyMapIter = modelViewLink.getKeyMapsIterator();
                         while (keyMapIter.hasNext() && !isInViewLink) {
-                            ModelKeyMap modelKeyMap = (ModelKeyMap) keyMapIter.next();
+                            ModelKeyMap modelKeyMap = keyMapIter.next();
                             if (!isRel && modelKeyMap.getFieldName().equals(fieldName)) {
                                 isInViewLink = true;
                             } else if (isRel && modelKeyMap.getRelFieldName().equals(fieldName)) {
@@ -686,7 +662,7 @@
     public static class ModelAliasAll implements Serializable {
         protected String entityAlias = "";
         protected String prefix = "";
-        protected Set fieldsToExclude = null;
+        protected Set<String> fieldsToExclude = null;
         protected boolean groupBy = false;
         // is specified this alias is a calculated value; can be: min, max, sum, avg, count, count-distinct
         protected String function = null;
@@ -704,12 +680,10 @@
             this.groupBy = "true".equals(UtilXml.checkEmpty(aliasAllElement.getAttribute("group-by")));
             this.function = UtilXml.checkEmpty(aliasAllElement.getAttribute("function"));
             
-            List excludes = UtilXml.childElementList(aliasAllElement, "exclude");
+            List<? extends Element> excludes = UtilXml.childElementList(aliasAllElement, "exclude");
             if (excludes != null && excludes.size() > 0) {
-                this.fieldsToExclude = new HashSet();
-                Iterator excludeIter = excludes.iterator();
-                while (excludeIter.hasNext()) {
-                    Element excludeElement = (Element) excludeIter.next();
+                this.fieldsToExclude = new HashSet<String>();
+                for (Element excludeElement: excludes) {
                     this.fieldsToExclude.add(excludeElement.getAttribute("field").intern());
                 }
             }
@@ -854,7 +828,7 @@
     }
     
     public static class ComplexAlias implements ComplexAliasMember {
-        protected List complexAliasMembers = FastList.newInstance();
+        protected List<ComplexAliasMember> complexAliasMembers = FastList.newInstance();
         protected String operator;
         
         public ComplexAlias(String operator) {
@@ -864,10 +838,7 @@
         public ComplexAlias(Element complexAliasElement) {
             this.operator = complexAliasElement.getAttribute("operator").intern();
             // handle all complex-alias and complex-alias-field sub-elements
-            List subElements = UtilXml.childElementList(complexAliasElement);
-            Iterator subElementIter = subElements.iterator();
-            while (subElementIter.hasNext()) {
-                Element subElement = (Element) subElementIter.next();
+            for (Element subElement: UtilXml.childElementList(complexAliasElement)) {
                 String nodeName = subElement.getNodeName();
                 if ("complex-alias".equals(nodeName)) {
                     this.addComplexAliasMember(new ComplexAlias(subElement));
@@ -885,13 +856,13 @@
             if (complexAliasMembers.size() == 0) {
                 return;
             } else if (complexAliasMembers.size() == 1) {
-                ComplexAliasMember complexAliasMember = (ComplexAliasMember) complexAliasMembers.iterator().next();
+                ComplexAliasMember complexAliasMember = complexAliasMembers.iterator().next();
                 complexAliasMember.makeAliasColName(colNameBuffer, fieldTypeBuffer, modelViewEntity, modelReader);
             } else {
                 colNameBuffer.append('(');
-                Iterator complexAliasMemberIter = complexAliasMembers.iterator();
+                Iterator<ComplexAliasMember> complexAliasMemberIter = complexAliasMembers.iterator();
                 while (complexAliasMemberIter.hasNext()) {
-                    ComplexAliasMember complexAliasMember = (ComplexAliasMember) complexAliasMemberIter.next();
+                    ComplexAliasMember complexAliasMember = complexAliasMemberIter.next();
                     complexAliasMember.makeAliasColName(colNameBuffer, fieldTypeBuffer, modelViewEntity, modelReader);
                     if (complexAliasMemberIter.hasNext()) {
                         colNameBuffer.append(' ');
@@ -938,7 +909,7 @@
             }
 
             if (UtilValidate.isNotEmpty(function)) {
-                String prefix = (String) functionPrefixMap.get(function);
+                String prefix = functionPrefixMap.get(function);
                 if (prefix == null) {
                     Debug.logWarning("Specified alias function [" + function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module);
                 } else {
@@ -959,7 +930,7 @@
         protected String entityAlias = "";
         protected String relEntityAlias = "";
         protected boolean relOptional = false;
-        protected List keyMaps = FastList.newInstance();
+        protected List<ModelKeyMap> keyMaps = FastList.newInstance();
 
         protected ModelViewLink() {}
 
@@ -982,7 +953,7 @@
             this(entityAlias, relEntityAlias, relOptional, Arrays.asList(keyMaps));
         }
 
-        public ModelViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List keyMaps) {
+        public ModelViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List<ModelKeyMap> keyMaps) {
             this.entityAlias = entityAlias;
             this.relEntityAlias = relEntityAlias;
             if (relOptional != null) {
@@ -1004,19 +975,19 @@
         }
 
         public ModelKeyMap getKeyMap(int index) {
-            return (ModelKeyMap) this.keyMaps.get(index);
+            return this.keyMaps.get(index);
         }
 
         public int getKeyMapsSize() {
             return this.keyMaps.size();
         }
 
-        public Iterator getKeyMapsIterator() {
+        public Iterator<ModelKeyMap> getKeyMapsIterator() {
             return this.keyMaps.iterator();
         }
 
-        public List getKeyMapsCopy() {
-            List newList = FastList.newInstance();
+        public List<ModelKeyMap> getKeyMapsCopy() {
+            List<ModelKeyMap> newList = FastList.newInstance();
             newList.addAll(this.keyMaps);
             return newList;
         }
@@ -1025,15 +996,15 @@
     public class ModelConversion implements Serializable {
         protected String aliasName;
         protected ModelEntity fromModelEntity;
-        protected Map fieldMap = FastMap.newInstance();
-        protected Set wildcards = new HashSet();
+        protected Map<String, String> fieldMap = FastMap.newInstance();
+        protected Set<String> wildcards = new HashSet<String>();
 
         public ModelConversion(String aliasName, ModelEntity fromModelEntity) {
             this.aliasName = aliasName;
             this.fromModelEntity = fromModelEntity;
-            Iterator it = getFieldsIterator();
+            Iterator<ModelField> it = getFieldsIterator();
             while (it.hasNext()) {
-                ModelField field = (ModelField) it.next();
+                ModelField field = it.next();
                 wildcards.add(field.getName());
             }
         }
@@ -1058,16 +1029,13 @@
             return aliasName + "(" + fromModelEntity.getEntityName() + ")";
         }
 
-        public Map convert(Map values) {
-            Map newValues = FastMap.newInstance();
-            Iterator it = fieldMap.entrySet().iterator();
-            while (it.hasNext()) {
-                Map.Entry entry = (Map.Entry) it.next();
-                newValues.put(entry.getValue(), values.get((String) entry.getKey()));
+        public Map<String, Object> convert(Map<String, Object> values) {
+            Map<String, Object> newValues = FastMap.newInstance();
+            for (Map.Entry<String, String> entry: fieldMap.entrySet()) {
+                newValues.put(entry.getValue(), values.get(entry.getKey()));
             }
-            it = wildcards.iterator();
-            while (it.hasNext()) {
-                newValues.put((String) it.next(), EntityOperator.WILDCARD);
+            for (String key: wildcards) {
+                newValues.put(key, EntityOperator.WILDCARD);
             }
             return newValues;
         }
@@ -1076,11 +1044,10 @@
             addAllAliasConversions(Arrays.asList(aliases), fieldName);
         }
 
-        public void addAllAliasConversions(List aliases, String fieldName) {
+        public void addAllAliasConversions(List<String> aliases, String fieldName) {
             if (aliases != null) {
-                Iterator it3 = aliases.iterator();
-                while (it3.hasNext()) {
-                    addConversion(fieldName, (String) it3.next());
+                for (String alias: aliases) {
+                    addConversion(fieldName, alias);
                 }
             }
         }