Author: doogie
Date: Wed Oct 17 20:47:31 2007 New Revision: 585838 URL: http://svn.apache.org/viewvc?rev=585838&view=rev Log: Java 1.5 markup for entity model. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelIndex.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelKeyMap.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java Wed Oct 17 20:47:31 2007 @@ -52,19 +52,19 @@ protected String title = ""; /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */ - protected Map memberModelMemberEntities = new HashMap(); + protected Map<String, ModelMemberEntity> memberModelMemberEntities = new HashMap<String, ModelMemberEntity>(); /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */ - protected List aliasAlls = new ArrayList(); + protected List<ModelAliasAll> aliasAlls = new ArrayList<ModelAliasAll>(); /** List of aliases with information in addition to what is in the standard field list */ - protected List aliases = new ArrayList(); + protected List<ModelAlias> aliases = new ArrayList<ModelAlias>(); /** List of view links to define how entities are connected (or "joined") */ - protected List viewLinks = new ArrayList(); + protected List<ModelViewLink> viewLinks = new ArrayList<ModelViewLink>(); /** relations defining relationships between this entity and other entities */ - protected List relations = new ArrayList(); + protected List<ModelRelation> relations = new ArrayList<ModelRelation>(); public DynamicViewEntity() { } @@ -80,7 +80,7 @@ return null; } - ModelMemberEntity modelMemberEntity = (ModelMemberEntity) ((Map.Entry) this.memberModelMemberEntities.entrySet().iterator().next()).getValue(); + ModelMemberEntity modelMemberEntity = this.memberModelMemberEntities.entrySet().iterator().next().getValue(); return modelMemberEntity.getEntityName(); } @@ -153,7 +153,7 @@ this.memberModelMemberEntities.put(entityAlias, modelMemberEntity); } - public Iterator getModelMemberEntitiesEntryIter() { + public Iterator<Map.Entry<String, ModelMemberEntity>> getModelMemberEntitiesEntryIter() { return this.memberModelMemberEntities.entrySet().iterator(); } @@ -162,7 +162,7 @@ this.aliasAlls.add(aliasAll); } - public void addAllAliasAllsToList(List addList) { + public void addAllAliasAllsToList(List<ModelAliasAll> addList) { addList.addAll(this.aliasAlls); } @@ -190,25 +190,25 @@ this.aliases.add(alias); } - public void addAllAliasesToList(List addList) { + public void addAllAliasesToList(List<ModelAlias> addList) { addList.addAll(this.aliases); } - public void addViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List modelKeyMaps) { + public void addViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List<ModelKeyMap> modelKeyMaps) { ModelViewLink modelViewLink = new ModelViewLink(entityAlias, relEntityAlias, relOptional, modelKeyMaps); this.viewLinks.add(modelViewLink); } - public void addAllViewLinksToList(List addList) { + public void addAllViewLinksToList(List<ModelViewLink> addList) { addList.addAll(this.viewLinks); } - public void addRelation(String type, String title, String relEntityName, List modelKeyMaps) { + public void addRelation(String type, String title, String relEntityName, List<ModelKeyMap> modelKeyMaps) { ModelRelation relation = new ModelRelation(type, title, relEntityName, null, modelKeyMaps); this.relations.add(relation); } - public void addAllRelationsToList(List addList) { + public void addAllRelationsToList(List<ModelRelation> addList) { addList.addAll(this.relations); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Wed Oct 17 20:47:31 2007 @@ -81,23 +81,23 @@ protected Integer sequenceBankSize = null; /** A List of the Field objects for the Entity */ - protected List fields = FastList.newInstance(); - protected Map fieldsMap = null; + protected List<ModelField> fields = FastList.newInstance(); + protected Map<String, ModelField> fieldsMap = null; /** A List of the Field objects for the Entity, one for each Primary Key */ - protected List pks = FastList.newInstance(); + protected List<ModelField> pks = FastList.newInstance(); /** A List of the Field objects for the Entity, one for each NON Primary Key */ - protected List nopks = FastList.newInstance(); + protected List<ModelField> nopks = FastList.newInstance(); /** relations defining relationships between this entity and other entities */ - protected List relations = FastList.newInstance(); + protected List<ModelRelation> relations = FastList.newInstance(); /** indexes on fields/columns in this entity */ - protected List indexes = FastList.newInstance(); + protected List<ModelIndex> indexes = FastList.newInstance(); /** map of ModelViewEntities that references this model */ - protected Map viewEntities = FastMap.newInstance(); + protected Map<String, ModelViewEntity> viewEntities = FastMap.newInstance(); /** An indicator to specify if this entity requires locking for updates */ protected boolean doLock = false; @@ -132,10 +132,7 @@ this.populateBasicInfo(entityElement); if (utilTimer != null) utilTimer.timerString(" createModelEntity: before fields"); - List fieldElementList = UtilXml.childElementList(entityElement, "field"); - Iterator fieldElementIter = fieldElementList.iterator(); - while (fieldElementIter.hasNext()) { - Element fieldElement = (Element) fieldElementIter.next(); + for (Element fieldElement: UtilXml.childElementList(entityElement, "field")) { ModelField field = reader.createModelField(fieldElement); if (field != null) { field.setModelEntity(this); @@ -186,10 +183,7 @@ } if (utilTimer != null) utilTimer.timerString(" createModelEntity: before prim-keys"); - List pkElementList = UtilXml.childElementList(entityElement, "prim-key"); - Iterator pkElementIter = pkElementList.iterator(); - while (pkElementIter.hasNext()) { - Element pkElement = (Element) pkElementIter.next(); + for (Element pkElement: UtilXml.childElementList(entityElement, "prim-key")) { ModelField field = reader.findModelField(this, pkElement.getAttribute("field").intern()); if (field != null) { this.pks.add(field); @@ -202,8 +196,7 @@ // now that we have the pks and the fields, make the nopks vector this.nopks = FastList.newInstance(); - for (int ind = 0; ind < this.fields.size(); ind++) { - ModelField field = (ModelField) this.fields.get(ind); + for (ModelField field: this.fields) { if (!field.isPk) this.nopks.add(field); } @@ -213,7 +206,7 @@ } /** DB Names Constructor */ - public ModelEntity(String tableName, Map colMap, ModelFieldTypeReader modelFieldTypeReader, boolean isCaseSensitive) { + public ModelEntity(String tableName, Map<String, DatabaseUtil.ColumnCheckInfo> colMap, ModelFieldTypeReader modelFieldTypeReader, boolean isCaseSensitive) { // if there is a dot in the name, remove it and everything before it, should be the schema name this.tableName = tableName; int dotIndex = this.tableName.indexOf("."); @@ -221,10 +214,8 @@ this.tableName = this.tableName.substring(dotIndex + 1); } this.entityName = ModelUtil.dbNameToClassName(this.tableName); - Iterator columnEntryIter = colMap.entrySet().iterator(); - while (columnEntryIter.hasNext()) { - Map.Entry columnEntry = (Map.Entry) columnEntryIter.next(); - DatabaseUtil.ColumnCheckInfo ccInfo = (DatabaseUtil.ColumnCheckInfo) columnEntry.getValue(); + for (Map.Entry<String, DatabaseUtil.ColumnCheckInfo> columnEntry: colMap.entrySet()) { + DatabaseUtil.ColumnCheckInfo ccInfo = columnEntry.getValue(); ModelField newField = new ModelField(ccInfo, modelFieldTypeReader); this.fields.add(newField); } @@ -254,10 +245,7 @@ protected void populateRelated(ModelReader reader, Element entityElement) { - List relationElementList = UtilXml.childElementList(entityElement, "relation"); - Iterator relationElementIter = relationElementList.iterator(); - while (relationElementIter.hasNext()) { - Element relationElement = (Element) relationElementIter.next(); + for (Element relationElement: UtilXml.childElementList(entityElement, "relation")) { ModelRelation relation = reader.createRelation(this, relationElement); if (relation != null) { relation.setModelEntity(this); @@ -268,20 +256,17 @@ protected void populateIndexes(Element entityElement) { - List indexElementList = UtilXml.childElementList(entityElement, "index"); - Iterator indexElementIter = indexElementList.iterator(); - while (indexElementIter.hasNext()) { - Element indexElement = (Element) indexElementIter.next(); + for (Element indexElement: UtilXml.childElementList(entityElement, "index")) { ModelIndex index = new ModelIndex(this, indexElement); index.setModelEntity(this); this.indexes.add(index); } } - public boolean containsAllPkFieldNames(Set fieldNames) { - Iterator pksIter = this.getPksIterator(); + public boolean containsAllPkFieldNames(Set<String> fieldNames) { + Iterator<ModelField> pksIter = this.getPksIterator(); while (pksIter.hasNext()) { - ModelField pkField = (ModelField) pksIter.next(); + ModelField pkField = pksIter.next(); if (!fieldNames.contains(pkField.getName())) { return false; } @@ -291,10 +276,7 @@ public void addExtendEntity(ModelReader reader, Element extendEntityElement) { - List fieldElementList = UtilXml.childElementList(extendEntityElement, "field"); - Iterator fieldElementIter = fieldElementList.iterator(); - while (fieldElementIter.hasNext()) { - Element fieldElement = (Element) fieldElementIter.next(); + for (Element fieldElement: UtilXml.childElementList(extendEntityElement, "field")) { // TODO: should we look for existing fields of the same name here? for now just add to list... ModelField field = reader.createModelField(fieldElement); if (field != null) { @@ -420,9 +402,8 @@ public void updatePkLists() { pks = FastList.newInstance(); nopks = FastList.newInstance(); - for (int i = 0; i < fields.size(); i++) { - ModelField field = (ModelField) fields.get(i); + for (ModelField field: fields) { if (field.isPk) pks.add(field); else @@ -432,21 +413,15 @@ public boolean isField(String fieldName) { if (fieldName == null) return false; - for (int i = 0; i < fields.size(); i++) { - ModelField field = (ModelField) fields.get(i); - + for (ModelField field: fields) { if (field.name.equals(fieldName)) return true; } return false; } - public boolean areFields(Collection fieldNames) { + public boolean areFields(Collection<String> fieldNames) { if (fieldNames == null) return false; - Iterator iter = fieldNames.iterator(); - - while (iter.hasNext()) { - String fieldName = (String) iter.next(); - + for (String fieldName: fieldNames) { if (!isField(fieldName)) return false; } return true; @@ -460,32 +435,32 @@ * @deprecated */ public ModelField getPk(int index) { - return (ModelField) this.pks.get(index); + return this.pks.get(index); } public ModelField getOnlyPk() { if (this.pks.size() == 1) { - return (ModelField) this.pks.get(0); + return this.pks.get(0); } else { throw new IllegalArgumentException("Error in getOnlyPk, the [" + this.getEntityName() + "] entity has more than one pk!"); } } - public Iterator getPksIterator() { + public Iterator<ModelField> getPksIterator() { return this.pks.iterator(); } - public List getPksCopy() { - List newList = FastList.newInstance(); + public List<ModelField> getPksCopy() { + List<ModelField> newList = FastList.newInstance(); newList.addAll(this.pks); return newList; } public String getFirstPkFieldName() { - List pkFieldNames = this.getPkFieldNames(); + List<String> pkFieldNames = this.getPkFieldNames(); String idFieldName = null; if (pkFieldNames != null && pkFieldNames.size() > 0) { - idFieldName = (String) pkFieldNames.get(0); + idFieldName = pkFieldNames.get(0); } return idFieldName; } @@ -498,15 +473,15 @@ * @deprecated */ public ModelField getNopk(int index) { - return (ModelField) this.nopks.get(index); + return this.nopks.get(index); } - public Iterator getNopksIterator() { + public Iterator<ModelField> getNopksIterator() { return this.nopks.iterator(); } - public List getNopksCopy() { - List newList = FastList.newInstance(); + public List<ModelField> getNopksCopy() { + List<ModelField> newList = FastList.newInstance(); newList.addAll(this.nopks); return newList; } @@ -519,15 +494,15 @@ * @deprecated */ public ModelField getField(int index) { - return (ModelField) this.fields.get(index); + return this.fields.get(index); } - public Iterator getFieldsIterator() { + public Iterator<ModelField> getFieldsIterator() { return this.fields.iterator(); } - public List getFieldsCopy() { - List newList = FastList.newInstance(); + public List<ModelField> getFieldsCopy() { + List<ModelField> newList = FastList.newInstance(); newList.addAll(this.fields); return newList; } @@ -544,20 +519,20 @@ if (fieldsMap == null) { createFieldsMap(); } - ModelField modelField = (ModelField) fieldsMap.get(fieldName); + ModelField modelField = fieldsMap.get(fieldName); if (modelField == null) { // sometimes weird things happen and this getField method is called before the fields are all populated, so before moving on just re-create the fieldsMap again real quick... // the purpose of the fieldsMap is for speed, but if failures are a little slower, no biggie createFieldsMap(); - modelField = (ModelField) fieldsMap.get(fieldName); + modelField = fieldsMap.get(fieldName); } return modelField; } protected synchronized void createFieldsMap() { - Map tempMap = FastMap.newInstance(); + Map<String, ModelField> tempMap = FastMap.newInstance(); for (int i = 0; i < fields.size(); i++) { - ModelField field = (ModelField) fields.get(i); + ModelField field = fields.get(i); tempMap.put(field.name, field); } fieldsMap = tempMap; @@ -578,7 +553,7 @@ public ModelField removeField(int index) { ModelField field = null; - field = (ModelField) fields.remove(index); + field = fields.remove(index); if (field == null) return null; if (field.isPk) { @@ -593,8 +568,10 @@ if (fieldName == null) return null; ModelField field = null; + // FIXME: when the field is removed, i is still incremented + // while not correct, this doesn't cause any problems for (int i = 0; i < fields.size(); i++) { - field = (ModelField) fields.get(i); + field = fields.get(i); if (field.name.equals(fieldName)) { fields.remove(i); if (field.isPk) { @@ -608,29 +585,27 @@ return field; } - public List getAllFieldNames() { + public List<String> getAllFieldNames() { return getFieldNamesFromFieldVector(fields); } - public List getPkFieldNames() { + public List<String> getPkFieldNames() { return getFieldNamesFromFieldVector(pks); } - public List getNoPkFieldNames() { + public List<String> getNoPkFieldNames() { return getFieldNamesFromFieldVector(nopks); } - public List getFieldNamesFromFieldVector(ModelField... modelFields) { + public List<String> getFieldNamesFromFieldVector(ModelField... modelFields) { return getFieldNamesFromFieldVector(Arrays.asList(modelFields)); } - public List getFieldNamesFromFieldVector(List modelFields) { - List nameList = FastList.newInstance(); + public List<String> getFieldNamesFromFieldVector(List<ModelField> modelFields) { + List<String> nameList = FastList.newInstance(); if (modelFields == null || modelFields.size() <= 0) return nameList; - for (int i = 0; i < modelFields.size(); i++) { - ModelField field = (ModelField) modelFields.get(i); - + for (ModelField field: modelFields) { nameList.add(field.name); } return nameList; @@ -642,9 +617,9 @@ public int getRelationsOneSize() { int numRels = 0; - Iterator relationsIter = this.getRelationsIterator(); + Iterator<ModelRelation> relationsIter = this.getRelationsIterator(); while (relationsIter.hasNext()) { - ModelRelation modelRelation = (ModelRelation) relationsIter.next(); + ModelRelation modelRelation = relationsIter.next(); if ("one".equals(modelRelation.getType())) { numRels++; } @@ -653,17 +628,16 @@ } public ModelRelation getRelation(int index) { - return (ModelRelation) this.relations.get(index); + return this.relations.get(index); } - public Iterator getRelationsIterator() { + public Iterator<ModelRelation> getRelationsIterator() { return this.relations.iterator(); } public ModelRelation getRelation(String relationName) { if (relationName == null) return null; - for (int i = 0; i < relations.size(); i++) { - ModelRelation relation = (ModelRelation) relations.get(i); + for (ModelRelation relation: relations) { if (relationName.equals(relation.title + relation.relEntityName)) return relation; } return null; @@ -675,7 +649,7 @@ } public ModelRelation removeRelation(int index) { - return (ModelRelation) this.relations.remove(index); + return this.relations.remove(index); } public int getIndexesSize() { @@ -683,17 +657,16 @@ } public ModelIndex getIndex(int index) { - return (ModelIndex) this.indexes.get(index); + return this.indexes.get(index); } - public Iterator getIndexesIterator() { + public Iterator<ModelIndex> getIndexesIterator() { return this.indexes.iterator(); } public ModelIndex getIndex(String indexName) { if (indexName == null) return null; - for (int i = 0; i < indexes.size(); i++) { - ModelIndex index = (ModelIndex) indexes.get(i); + for (ModelIndex index: indexes) { if (indexName.equals(index.getName())) return index; } return null; @@ -705,7 +678,7 @@ } public ModelIndex removeIndex(int index) { - return (ModelIndex) this.indexes.remove(index); + return this.indexes.remove(index); } public int getViewEntitiesSize() { @@ -713,10 +686,10 @@ } public ModelViewEntity getViewEntity(String viewEntityName) { - return (ModelViewEntity) this.viewEntities.get(viewEntityName); + return this.viewEntities.get(viewEntityName); } - public Iterator getViewConvertorsIterator() { + public Iterator<Map.Entry<String, ModelViewEntity>> getViewConvertorsIterator() { return this.viewEntities.entrySet().iterator(); } @@ -724,25 +697,25 @@ this.viewEntities.put(view.getEntityName(), view); } - public List convertToViewValues(String viewEntityName, GenericEntity entity) { + public List<? extends Map<String, Object>> convertToViewValues(String viewEntityName, GenericEntity entity) { if (entity == null || entity == GenericEntity.NULL_ENTITY || entity == GenericValue.NULL_VALUE) return UtilMisc.toList(entity); - ModelViewEntity view = (ModelViewEntity) this.viewEntities.get(viewEntityName); + ModelViewEntity view = this.viewEntities.get(viewEntityName); return view.convert(getEntityName(), entity); } public ModelViewEntity removeViewEntity(String viewEntityName) { - return (ModelViewEntity) this.viewEntities.remove(viewEntityName); + return this.viewEntities.remove(viewEntityName); } public ModelViewEntity removeViewEntity(ModelViewEntity viewEntity) { return removeViewEntity(viewEntity.getEntityName()); } - public String nameString(List flds) { + public String nameString(List<ModelField> flds) { return nameString(flds, ", ", ""); } - public String nameString(List flds, String separator, String afterLast) { + public String nameString(List<ModelField> flds, String separator, String afterLast) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -752,10 +725,10 @@ int i = 0; for (; i < flds.size() - 1; i++) { - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); returnString.append(separator); } - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); returnString.append(afterLast); return returnString.toString(); } @@ -764,7 +737,7 @@ return typeNameString(Arrays.asList(flds)); } - public String typeNameString(List flds) { + public String typeNameString(List<ModelField> flds) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -774,13 +747,13 @@ int i = 0; for (; i < flds.size() - 1; i++) { - ModelField curField = (ModelField) flds.get(i); + ModelField curField = flds.get(i); returnString.append(curField.type); returnString.append(" "); returnString.append(curField.name); returnString.append(", "); } - ModelField curField = (ModelField) flds.get(i); + ModelField curField = flds.get(i); returnString.append(curField.type); returnString.append(" "); returnString.append(curField.name); @@ -816,10 +789,10 @@ } public String fieldsStringList(String eachString, String separator, ModelField... flds) { - return fieldsStringList(Arrays.asList(flds), eachString, separator); + return fieldsStringList(Arrays.asList(flds), eachString, separator, false, false); } - public String fieldsStringList(List flds, String eachString, String separator) { + public String fieldsStringList(List<ModelField> flds, String eachString, String separator) { return fieldsStringList(flds, eachString, separator, false, false); } @@ -827,7 +800,7 @@ return fieldsStringList(Arrays.asList(flds), eachString, separator, appendIndex, false); } - public String fieldsStringList(List flds, String eachString, String separator, boolean appendIndex) { + public String fieldsStringList(List<ModelField> flds, String eachString, String separator, boolean appendIndex) { return fieldsStringList(flds, eachString, separator, appendIndex, false); } @@ -835,7 +808,7 @@ return fieldsStringList(Arrays.asList(flds), eachString, separator, appendIndex, onlyNonPK); } - public String fieldsStringList(List flds, String eachString, String separator, boolean appendIndex, boolean onlyNonPK) { + public String fieldsStringList(List<ModelField> flds, String eachString, String separator, boolean appendIndex, boolean onlyNonPK) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -845,7 +818,7 @@ int i = 0; for (; i < flds.size(); i++) { - if (onlyNonPK && ((ModelField) flds.get(i)).isPk) continue; + if (onlyNonPK && flds.get(i).isPk) continue; returnString.append(eachString); if (appendIndex) returnString.append(i + 1); if (i < flds.size() - 1) returnString.append(separator); @@ -857,7 +830,7 @@ return colNameString(Arrays.asList(flds)); } - public String colNameString(List flds) { + public String colNameString(List<ModelField> flds) { return colNameString(flds, ", ", "", false); } @@ -865,16 +838,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 (fldsIt.hasNext()) { returnString.append(separator); @@ -889,7 +862,7 @@ return classNameString(Arrays.asList(flds)); } - public String classNameString(List flds) { + public String classNameString(List<ModelField> flds) { return classNameString(flds, ", ", ""); } @@ -897,7 +870,7 @@ return classNameString(Arrays.asList(flds), separator, afterLast); } - public String classNameString(List flds, String separator, String afterLast) { + public String classNameString(List<ModelField> flds, String separator, String afterLast) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -907,10 +880,10 @@ int i = 0; for (; i < flds.size() - 1; i++) { - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append(separator); } - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append(afterLast); return returnString.toString(); } @@ -919,7 +892,7 @@ return finderQueryString(Arrays.asList(flds)); } - public String finderQueryString(List flds) { + public String finderQueryString(List<ModelField> flds) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -928,12 +901,12 @@ int i = 0; for (; i < flds.size() - 1; i++) { - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append(" like {"); returnString.append(i); returnString.append("} AND "); } - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append(" like {"); returnString.append(i); returnString.append("}"); @@ -944,7 +917,7 @@ return httpArgList(Arrays.asList(flds)); } - public String httpArgList(List flds) { + public String httpArgList(List<ModelField> flds) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -956,17 +929,17 @@ returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); returnString.append(" + \"&\" + "); } returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); return returnString.toString(); } @@ -974,7 +947,7 @@ return httpArgListFromClass(Arrays.asList(flds)); } - public String httpArgListFromClass(List flds) { + public String httpArgListFromClass(List<ModelField> flds) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -987,21 +960,21 @@ returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(entityName)); returnString.append(".get"); - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append("() + \"&\" + "); } returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(entityName)); returnString.append(".get"); - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append("()"); return returnString.toString(); } @@ -1010,7 +983,7 @@ return httpArgListFromClass(Arrays.asList(flds), entityNameSuffix); } - public String httpArgListFromClass(List flds, String entityNameSuffix) { + public String httpArgListFromClass(List<ModelField> flds, String entityNameSuffix) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -1023,23 +996,23 @@ returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(entityName)); returnString.append(entityNameSuffix); returnString.append(".get"); - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append("() + \"&\" + "); } returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(entityName)); returnString.append(entityNameSuffix); returnString.append(".get"); - returnString.append(ModelUtil.upperFirstChar(((ModelField) flds.get(i)).name)); + returnString.append(ModelUtil.upperFirstChar(flds.get(i).name)); returnString.append("()"); return returnString.toString(); } @@ -1048,7 +1021,7 @@ return httpRelationArgList(Arrays.asList(flds), relation); } - public String httpRelationArgList(List flds, ModelRelation relation) { + public String httpRelationArgList(List<ModelField> flds, ModelRelation relation) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -1058,13 +1031,13 @@ int i = 0; for (; i < flds.size() - 1; i++) { - ModelKeyMap keyMap = relation.findKeyMapByRelated(((ModelField) flds.get(i)).name); + ModelKeyMap keyMap = relation.findKeyMapByRelated(flds.get(i).name); if (keyMap != null) { returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(relation.mainEntity.entityName)); returnString.append(".get"); @@ -1074,13 +1047,13 @@ Debug.logWarning("-- -- ENTITYGEN ERROR:httpRelationArgList: Related Key in Key Map not found for name: " + ((ModelField) flds.get(i)).name + " related entity: " + relation.relEntityName + " main entity: " + relation.mainEntity.entityName + " type: " + relation.type, module); } } - ModelKeyMap keyMap = relation.findKeyMapByRelated(((ModelField) flds.get(i)).name); + ModelKeyMap keyMap = relation.findKeyMapByRelated(flds.get(i).name); if (keyMap != null) { returnString.append("\""); returnString.append(tableName); returnString.append("_"); - returnString.append(((ModelField) flds.get(i)).colName); + returnString.append(flds.get(i).colName); returnString.append("=\" + "); returnString.append(ModelUtil.lowerFirstChar(relation.mainEntity.entityName)); returnString.append(".get"); @@ -1112,7 +1085,7 @@ return typeNameStringRelatedNoMapped(Arrays.asList(flds), relation); } - public String typeNameStringRelatedNoMapped(List flds, ModelRelation relation) { + public String typeNameStringRelatedNoMapped(List<ModelField> flds, ModelRelation relation) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -1121,18 +1094,18 @@ int i = 0; - if (relation.findKeyMapByRelated(((ModelField) flds.get(i)).name) == null) { - returnString.append(((ModelField) flds.get(i)).type); + if (relation.findKeyMapByRelated(flds.get(i).name) == null) { + returnString.append(flds.get(i).type); returnString.append(" "); - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); } i++; for (; i < flds.size(); i++) { - if (relation.findKeyMapByRelated(((ModelField) flds.get(i)).name) == null) { + if (relation.findKeyMapByRelated(flds.get(i).name) == null) { if (returnString.length() > 0) returnString.append(", "); - returnString.append(((ModelField) flds.get(i)).type); + returnString.append(flds.get(i).type); returnString.append(" "); - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); } } return returnString.toString(); @@ -1142,7 +1115,7 @@ return typeNameStringRelatedAndMain(Arrays.asList(flds), relation); } - public String typeNameStringRelatedAndMain(List flds, ModelRelation relation) { + public String typeNameStringRelatedAndMain(List<ModelField> flds, ModelRelation relation) { StringBuilder returnString = new StringBuilder(); if (flds.size() < 1) { @@ -1152,20 +1125,20 @@ int i = 0; for (; i < flds.size() - 1; i++) { - ModelKeyMap keyMap = relation.findKeyMapByRelated(((ModelField) flds.get(i)).name); + ModelKeyMap keyMap = relation.findKeyMapByRelated(flds.get(i).name); if (keyMap != null) { returnString.append(keyMap.fieldName); returnString.append(", "); } else { - returnString.append(((ModelField) flds.get(i)).name); + returnString.append(flds.get(i).name); returnString.append(", "); } } - ModelKeyMap keyMap = relation.findKeyMapByRelated(((ModelField) flds.get(i)).name); + ModelKeyMap keyMap = relation.findKeyMapByRelated(flds.get(i).name); if (keyMap != null) returnString.append(keyMap.fieldName); - else returnString.append(((ModelField) flds.get(i)).name); + else returnString.append(flds.get(i).name); return returnString.toString(); } @@ -1206,10 +1179,10 @@ return this.getEntityName().compareTo(otherModelEntity.getEntityName()); } - public void convertFieldMapInPlace(Map inContext, GenericDelegator delegator) { - Iterator modelFields = this.getFieldsIterator(); + public void convertFieldMapInPlace(Map<String, Object> inContext, GenericDelegator delegator) { + Iterator<ModelField> modelFields = this.getFieldsIterator(); while (modelFields.hasNext()) { - ModelField modelField = (ModelField) modelFields.next(); + ModelField modelField = modelFields.next(); String fieldName = modelField.getName(); Object oldValue = inContext.get(fieldName); if (oldValue != null) { @@ -1330,18 +1303,18 @@ } // append field elements - Iterator fieldIter = this.getFieldsIterator(); + Iterator<ModelField> fieldIter = this.getFieldsIterator(); while (fieldIter != null && fieldIter.hasNext()) { - ModelField field = (ModelField) fieldIter.next(); + ModelField field = fieldIter.next(); if (!field.getIsAutoCreatedInternal()) { root.appendChild(field.toXmlElement(document)); } } // append PK elements - Iterator pkIter = this.getPksIterator(); + Iterator<ModelField> pkIter = this.getPksIterator(); while (pkIter != null && pkIter.hasNext()) { - ModelField pk = (ModelField) pkIter.next(); + ModelField pk = pkIter.next(); Element pkey = document.createElement("prim-key"); pkey.setAttribute("field", pk.getName()); root.appendChild(pkey); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java Wed Oct 17 20:47:31 2007 @@ -39,22 +39,20 @@ public static final String module = ModelEntityChecker.class.getName(); - public static void checkEntities(GenericDelegator delegator, List warningList) throws GenericEntityException { + public static void checkEntities(GenericDelegator delegator, List<String> warningList) throws GenericEntityException { ModelReader reader = delegator.getModelReader(); - TreeSet reservedWords = new TreeSet(); + TreeSet<String> reservedWords = new TreeSet<String>(); initReservedWords(reservedWords); - Map packages = FastMap.newInstance(); - TreeSet packageNames = new TreeSet(); - TreeSet tableNames = new TreeSet(); + Map<String, TreeSet<String>> packages = FastMap.newInstance(); + TreeSet<String> packageNames = new TreeSet<String>(); + TreeSet<String> tableNames = new TreeSet<String>(); //put the entityNames TreeSets in a HashMap by packageName - Collection ec = reader.getEntityNames(); - TreeSet entityNames = new TreeSet(ec); - Iterator ecIter = ec.iterator(); - while (ecIter.hasNext()) { - String eName = (String) ecIter.next(); + Collection<String> ec = reader.getEntityNames(); + TreeSet<String> entityNames = new TreeSet<String>(ec); + for (String eName: ec) { ModelEntity ent = reader.getModelEntity(eName); //make sure the table name is in the list of all table names, if @@ -62,9 +60,9 @@ if (UtilValidate.isNotEmpty(ent.getPlainTableName())) tableNames.add(ent.getPlainTableName()); - TreeSet entities = (TreeSet) packages.get(ent.getPackageName()); + TreeSet<String> entities = packages.get(ent.getPackageName()); if (entities == null) { - entities = new TreeSet(); + entities = new TreeSet<String>(); packages.put(ent.getPackageName(), entities); packageNames.add(ent.getPackageName()); } @@ -73,16 +71,12 @@ //int numberOfEntities = ec.size(); int numberShowed = 0; - TreeSet fkNames = new TreeSet(); - TreeSet indexNames = new TreeSet(); + TreeSet<String> fkNames = new TreeSet<String>(); + TreeSet<String> indexNames = new TreeSet<String>(); - Iterator piter = packageNames.iterator(); - while (piter.hasNext()) { - String pName = (String) piter.next(); - TreeSet entities = (TreeSet) packages.get(pName); - Iterator i = entities.iterator(); - while (i.hasNext()) { - String entityName = (String) i.next(); + for (String pName: packageNames) { + TreeSet<String> entities = packages.get(pName); + for (String entityName: entities) { String helperName = delegator.getEntityHelperName(entityName); String groupName = delegator.getEntityGroupName(entityName); ModelEntity entity = reader.getModelEntity(entityName); @@ -99,10 +93,10 @@ if (entity.getPlainTableName() != null && reservedWords.contains(entity.getPlainTableName().toUpperCase())) { warningList.add("[TableNameRW] Table name [" + entity.getPlainTableName() + "] of entity " + entity.getEntityName() + " is a reserved word."); } - TreeSet ufields = new TreeSet(); - Iterator fieldIter = entity.getFieldsIterator(); + TreeSet<String> ufields = new TreeSet<String>(); + Iterator<ModelField> fieldIter = entity.getFieldsIterator(); while (fieldIter.hasNext()) { - ModelField field = (ModelField) fieldIter.next(); + ModelField field = fieldIter.next(); ModelFieldType type = delegator.getEntityFieldType(entity,field.getType()); if (ufields.contains(field.getName())) { @@ -129,9 +123,9 @@ } } if (entity.getRelationsSize() > 0) { - Iterator indexIter = entity.getIndexesIterator(); + Iterator<ModelIndex> indexIter = entity.getIndexesIterator(); while (indexIter.hasNext()) { - ModelIndex index = (ModelIndex) indexIter.next(); + ModelIndex index = indexIter.next(); if (indexNames.contains(index.getName())) { warningList.add("[IndexDuplicateName] Index on entity " @@ -162,7 +156,7 @@ } } - TreeSet relations = new TreeSet(); + TreeSet<String> relations = new TreeSet<String>(); for (int r = 0; r < entity.getRelationsSize(); r++) { ModelRelation relation = entity.getRelation(r); @@ -220,9 +214,9 @@ + " does not match the number of keymaps (" + relation.getKeyMapsSize() + ") for relation of type one \"" + relation.getTitle() + relation.getRelEntityName() + "\" of entity " + entity.getEntityName() + "."); - Iterator pksIter = relatedEntity.getPksIterator(); + Iterator<ModelField> pksIter = relatedEntity.getPksIterator(); while (pksIter.hasNext()) { - ModelField pk = (ModelField) pksIter.next(); + ModelField pk = pksIter.next(); if (relation.findKeyMapByRelated(pk.getName()) == null) { warningList.add("[RelationOneRelatedPrimaryKeyMissing] The primary key \"" + pk.getName() + "\" of related entity " + relation.getRelEntityName() @@ -500,7 +494,7 @@ "ZEROFILL", "ZONE" }; - public static void initReservedWords(TreeSet reservedWords) { + public static void initReservedWords(TreeSet<String> reservedWords) { //create extensive list of reserved words int asize = rwArray.length; Debug.log("[initReservedWords] array length=" + asize); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java Wed Oct 17 20:47:31 2007 @@ -45,7 +45,7 @@ protected boolean isAutoCreatedInternal = false; /** validators to be called when an update is done */ - protected List validators = new ArrayList(); + protected List<String> validators = new ArrayList<String>(); /** The description for documentation purposes */ protected String description = ""; @@ -152,7 +152,7 @@ /** validators to be called when an update is done */ public String getValidator(int index) { - return (String) this.validators.get(index); + return this.validators.get(index); } public int getValidatorsSize() { @@ -164,7 +164,7 @@ } public String removeValidator(int index) { - return (String) this.validators.remove(index); + return this.validators.remove(index); } /** The description for documentation purposes */ @@ -201,10 +201,10 @@ root.setAttribute("encrypt", "true"); } - Iterator valIter = this.validators.iterator(); + Iterator<String> valIter = this.validators.iterator(); if (valIter != null) { while (valIter.hasNext()) { - String validator = (String) valIter.next(); + String validator = valIter.next(); Element val = document.createElement("validate"); val.setAttribute("name", validator); root.appendChild(val); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldType.java Wed Oct 17 20:47:31 2007 @@ -43,7 +43,7 @@ protected String sqlTypeAlias = null; /** validators to be called when an update is done */ - protected List validators = new ArrayList(); + protected List<ModelFieldValidator> validators = new ArrayList<ModelFieldValidator>(); /** Default Constructor */ public ModelFieldType() {} @@ -87,7 +87,7 @@ } /** validators to be called when an update is done */ - public List getValidators() { + public List<ModelFieldValidator> getValidators() { return this.validators; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java Wed Oct 17 20:47:31 2007 @@ -44,9 +44,9 @@ public class ModelFieldTypeReader implements Serializable { public static final String module = ModelFieldTypeReader.class.getName(); - public static UtilCache readers = new UtilCache("entity.ModelFieldTypeReader", 0, 0); + public static UtilCache<String, ModelFieldTypeReader> readers = new UtilCache<String, ModelFieldTypeReader>("entity.ModelFieldTypeReader", 0, 0); - public Map fieldTypeCache = null; + public Map<String, ModelFieldType> fieldTypeCache = null; public int numEntities = 0; public int numFields = 0; @@ -63,13 +63,13 @@ } String tempModelName = datasourceInfo.fieldTypeName; - ModelFieldTypeReader reader = (ModelFieldTypeReader) readers.get(tempModelName); + ModelFieldTypeReader reader = readers.get(tempModelName); if (reader == null) // don't want to block here { synchronized (ModelFieldTypeReader.class) { // must check if null again as one of the blocked threads can still enter - reader = (ModelFieldTypeReader) readers.get(tempModelName); + reader = readers.get(tempModelName); if (reader == null) { reader = new ModelFieldTypeReader(tempModelName); readers.put(tempModelName, reader); @@ -92,14 +92,14 @@ getFieldTypeCache(); } - public Map getFieldTypeCache() { + public Map<String, ModelFieldType> getFieldTypeCache() { if (fieldTypeCache == null) // don't want to block here { synchronized (ModelFieldTypeReader.class) { // must check if null again as one of the blocked threads can still enter if (fieldTypeCache == null) // now it's safe { - fieldTypeCache = new HashMap(); + fieldTypeCache = new HashMap<String, ModelFieldType>(); UtilTimer utilTimer = new UtilTimer(); // utilTimer.timerString("Before getDocument"); @@ -163,8 +163,8 @@ /** Creates a Collection with all of the ModelFieldType names * @return A Collection of ModelFieldType names */ - public Collection getFieldTypeNames() { - Map ftc = getFieldTypeCache(); + public Collection<String> getFieldTypeNames() { + Map<String, ModelFieldType> ftc = getFieldTypeCache(); return ftc.keySet(); } @@ -172,8 +172,8 @@ /** Creates a Collection with all of the ModelFieldTypes * @return A Collection of ModelFieldTypes */ - public Collection getFieldTypes() { - Map ftc = getFieldTypeCache(); + public Collection<ModelFieldType> getFieldTypes() { + Map<String, ModelFieldType> ftc = getFieldTypeCache(); return ftc.values(); } @@ -183,10 +183,10 @@ * @return An FieldType object describing the specified fieldType of the specified descriptor file. */ public ModelFieldType getModelFieldType(String fieldTypeName) { - Map ftc = getFieldTypeCache(); + Map<String, ModelFieldType> ftc = getFieldTypeCache(); if (ftc != null) - return (ModelFieldType) ftc.get(fieldTypeName); + return ftc.get(fieldTypeName); else return null; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java Wed Oct 17 20:47:31 2007 @@ -52,13 +52,13 @@ public class ModelGroupReader implements Serializable { public static final String module = ModelGroupReader.class.getName(); - public static UtilCache readers = new UtilCache("entity.ModelGroupReader", 0, 0); + public static UtilCache<String, ModelGroupReader> readers = new UtilCache<String, ModelGroupReader>("entity.ModelGroupReader", 0, 0); - private Map groupCache = null; - private Set groupNames = null; + private Map<String, String> groupCache = null; + private Set<String> groupNames = null; public String modelName; - public List entityGroupResourceHandlers = new LinkedList(); + public List<ResourceHandler> entityGroupResourceHandlers = new LinkedList<ResourceHandler>(); public static ModelGroupReader getModelGroupReader(String delegatorName) throws GenericEntityConfException { DelegatorInfo delegatorInfo = EntityConfigUtil.getDelegatorInfo(delegatorName); @@ -68,12 +68,12 @@ } String tempModelName = delegatorInfo.entityGroupReader; - ModelGroupReader reader = (ModelGroupReader) readers.get(tempModelName); + ModelGroupReader reader = readers.get(tempModelName); if (reader == null) { // don't want to block here synchronized (ModelGroupReader.class) { // must check if null again as one of the blocked threads can still enter - reader = (ModelGroupReader) readers.get(tempModelName); + reader = readers.get(tempModelName); if (reader == null) { reader = new ModelGroupReader(tempModelName); readers.put(tempModelName, reader); @@ -90,17 +90,12 @@ if (entityGroupReaderInfo == null) { throw new GenericEntityConfException("Cound not find an entity-group-reader with the name " + modelName); } - Iterator resourceElementIter = entityGroupReaderInfo.resourceElements.iterator(); - while (resourceElementIter.hasNext()) { - Element resourceElement = (Element) resourceElementIter.next(); + for (Element resourceElement: entityGroupReaderInfo.resourceElements) { this.entityGroupResourceHandlers.add(new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, resourceElement)); } // get all of the component resource group stuff, ie specified in each ofbiz-component.xml file - List componentResourceInfos = ComponentConfig.getAllEntityResourceInfos("group"); - Iterator componentResourceInfoIter = componentResourceInfos.iterator(); - while (componentResourceInfoIter.hasNext()) { - ComponentConfig.EntityResourceInfo componentResourceInfo = (ComponentConfig.EntityResourceInfo) componentResourceInfoIter.next(); + for (ComponentConfig.EntityResourceInfo componentResourceInfo: ComponentConfig.getAllEntityResourceInfos("group")) { if (modelName.equals(componentResourceInfo.readerName)) { this.entityGroupResourceHandlers.add(componentResourceInfo.createResourceHandler()); } @@ -110,23 +105,21 @@ getGroupCache(); } - public Map getGroupCache() { + public Map<String, String> getGroupCache() { if (this.groupCache == null) // don't want to block here { synchronized (ModelGroupReader.class) { // must check if null again as one of the blocked threads can still enter if (this.groupCache == null) { // now it's safe - this.groupCache = new HashMap(); - this.groupNames = new TreeSet(); + this.groupCache = new HashMap<String, String>(); + this.groupNames = new TreeSet<String>(); UtilTimer utilTimer = new UtilTimer(); // utilTimer.timerString("[ModelGroupReader.getGroupCache] Before getDocument"); int i = 0; - Iterator entityGroupResourceHandlerIter = this.entityGroupResourceHandlers.iterator(); - while (entityGroupResourceHandlerIter.hasNext()) { - ResourceHandler entityGroupResourceHandler = (ResourceHandler) entityGroupResourceHandlerIter.next(); + for (ResourceHandler entityGroupResourceHandler: this.entityGroupResourceHandlers) { Document document = null; try { @@ -178,10 +171,10 @@ * @return A group name */ public String getEntityGroupName(String entityName) { - Map gc = getGroupCache(); + Map<String, String> gc = getGroupCache(); if (gc != null) - return (String) gc.get(entityName); + return gc.get(entityName); else return null; } @@ -189,28 +182,23 @@ /** Creates a Collection with all of the groupNames defined in the specified XML Entity Group Descriptor file. * @return A Collection of groupNames Strings */ - public Collection getGroupNames() { + public Collection<String> getGroupNames() { getGroupCache(); if (this.groupNames == null) return null; - return new ArrayList(this.groupNames); + return new ArrayList<String>(this.groupNames); } /** Creates a Collection with names of all of the entities for a given group * @param groupName * @return A Collection of entityName Strings */ - public Collection getEntityNamesByGroup(String groupName) { - Map gc = getGroupCache(); - Collection enames = new LinkedList(); + public Collection<String> getEntityNamesByGroup(String groupName) { + Map<String, String> gc = getGroupCache(); + Collection<String> enames = new LinkedList<String>(); if (groupName == null || groupName.length() <= 0) return enames; if (gc == null || gc.size() < 0) return enames; - Set gcEntries = gc.entrySet(); - Iterator gcIter = gcEntries.iterator(); - - while (gcIter.hasNext()) { - Map.Entry entry = (Map.Entry) gcIter.next(); - + for (Map.Entry<String, String> entry: gc.entrySet()) { if (groupName.equals(entry.getValue())) enames.add(entry.getKey()); } return enames; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelIndex.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelIndex.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelIndex.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelIndex.java Wed Oct 17 20:47:31 2007 @@ -36,7 +36,7 @@ protected boolean unique; /** list of the field names included in this index */ - protected List fieldNames = new ArrayList(); + protected List<String> fieldNames = new ArrayList<String>(); /** Default Constructor */ public ModelIndex() { @@ -97,7 +97,7 @@ setModelEntity(mainEntity); } - public Iterator getIndexFieldsIterator() { + public Iterator<String> getIndexFieldsIterator() { return this.fieldNames.iterator(); } @@ -106,7 +106,7 @@ } public String getIndexField(int index) { - return (String) this.fieldNames.get(index); + return this.fieldNames.get(index); } public void addIndexField(String fieldName) { @@ -114,7 +114,7 @@ } public String removeIndexField(int index) { - return (String) this.fieldNames.remove(index); + return this.fieldNames.remove(index); } public Element toXmlElement(Document document) { @@ -124,9 +124,7 @@ root.setAttribute("unique", "true"); } - Iterator fnIter = this.fieldNames.iterator(); - while (fnIter != null && fnIter.hasNext()) { - String fieldName = (String) fnIter.next(); + for (String fieldName: this.fieldNames) { Element fn = document.createElement("index-field"); fn.setAttribute("name", fieldName); root.appendChild(fn); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelKeyMap.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelKeyMap.java?rev=585838&r1=585837&r2=585838&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelKeyMap.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelKeyMap.java Wed Oct 17 20:47:31 2007 @@ -74,16 +74,16 @@ } // ======= Some Convenience Oriented Factory Methods ======= - public static List makeKeyMapList(String fieldName1) { + public static List<ModelKeyMap> makeKeyMapList(String fieldName1) { return UtilMisc.toList(new ModelKeyMap(fieldName1, null)); } - public static List makeKeyMapList(String fieldName1, String relFieldName1) { + public static List<ModelKeyMap> makeKeyMapList(String fieldName1, String relFieldName1) { return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1)); } - public static List makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2) { + public static List<ModelKeyMap> makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2) { return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1), new ModelKeyMap(fieldName2, relFieldName2)); } - public static List makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2, String fieldName3, String relFieldName3) { + public static List<ModelKeyMap> makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2, String fieldName3, String relFieldName3) { return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1), new ModelKeyMap(fieldName2, relFieldName2), new ModelKeyMap(fieldName3, relFieldName3)); } |
Free forum by Nabble | Edit this page |