Author: jonesde
Date: Sat Feb 23 14:45:10 2008 New Revision: 630541 URL: http://svn.apache.org/viewvc?rev=630541&view=rev Log: Changed EOModelBundle entity stuff to use the generic plist out format routines Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java?rev=630541&r1=630540&r2=630541&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java Sat Feb 23 14:45:10 2008 @@ -511,10 +511,9 @@ writer.print(" = "); if (value instanceof Map) { writer.println(); - writePlistPropertyMap((Map<String, Object>) value, indentLevel + 1, writer, false); + writePlistPropertyMap((Map<String, Object>) value, indentLevel, writer, false); } else if (value instanceof List) { - writer.println(); - writePlistPropertyValueList((List<Object>) value, indentLevel + 1, writer); + writePlistPropertyValueList((List<Object>) value, indentLevel, writer); } else { writer.print(value); writer.println(";"); @@ -535,7 +534,7 @@ } public static void writePlistPropertyValueList(List<Object> propertyValueList, int indentLevel, PrintWriter writer) { for (int i = 0; i < indentLevel; i++) writer.print(indentFourString); - writer.println("("); + writer.print("("); Iterator<Object> propertyValueIter = propertyValueList.iterator(); while (propertyValueIter.hasNext()) { 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=630541&r1=630540&r2=630541&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 Sat Feb 23 14:45:10 2008 @@ -34,6 +34,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilXml; @@ -1394,239 +1395,98 @@ * @param helperName */ public void writeEoModelText(PrintWriter writer, String entityPrefix, String helperName, Set<String> entityNameIncludeSet) { - int indent = 4; - StringBuffer indentStrBuf = new StringBuffer(); - for (int i = 0; i < indent; i++) indentStrBuf.append(' '); - String indentString = indentStrBuf.toString(); - if (entityPrefix == null) entityPrefix = ""; if (helperName == null) helperName = "localderby"; ModelFieldTypeReader modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperName); - - writer.println('{'); - writer.print(indentString); - writer.print("externalName = "); - writer.print(this.getTableName(helperName)); - writer.println(";"); - - writer.print(indentString); - writer.print("name = "); - writer.print(this.getEntityName()); - writer.println(";"); + Map<String, Object> topLevelMap = FastMap.newInstance(); - writer.print(indentString); - writer.println("className = EOGenericRecord;"); + topLevelMap.put("name", this.getEntityName()); + topLevelMap.put("externalName", this.getTableName(helperName)); + topLevelMap.put("className", "EOGenericRecord"); // for classProperties add field names AND relationship names to get a nice, complete chart - writer.print(indentString); - writer.print("classProperties = ("); - Iterator<ModelField> cpFieldIter = this.getFieldsIterator(); - while (cpFieldIter.hasNext()) { - ModelField field = cpFieldIter.next(); - writer.print(field.getName()); - if (cpFieldIter.hasNext()) writer.print(", "); - } - Iterator<ModelRelation> cpRelationshipIter = this.getRelationsIterator(); - // put these on a new line if there are any - if (cpRelationshipIter.hasNext()) { - writer.println(","); - writer.print(indentString); - writer.print(indentString); - } - while (cpRelationshipIter.hasNext()) { - ModelRelation relationship = cpRelationshipIter.next(); - writer.print(relationship.getCombinedName()); - if (cpRelationshipIter.hasNext()) writer.print(", "); + List<String> classPropertiesList = FastList.newInstance(); + topLevelMap.put("classProperties", classPropertiesList); + for (ModelField field: this.fields) { + classPropertiesList.add(field.getName()); + } + for (ModelRelation relationship: this.relations) { + classPropertiesList.add(relationship.getCombinedName()); } - writer.println(");"); // attributes - writer.print(indentString); - writer.println("attributes = ("); - Iterator<ModelField> attrFieldIter = this.getFieldsIterator(); - while (attrFieldIter.hasNext()) { - ModelField field = attrFieldIter.next(); + List<Map<String, Object>> attributesList = FastList.newInstance(); + topLevelMap.put("attributes", attributesList); + for (ModelField field: this.fields) { ModelFieldType fieldType = modelFieldTypeReader.getModelFieldType(field.getType()); - - writer.print(indentString); - writer.println("{"); - writer.print(indentString); - writer.print(indentString); - writer.print("name = "); - writer.print(field.getName()); - writer.println(";"); + Map<String, Object> attributeMap = FastMap.newInstance(); + attributesList.add(attributeMap); - writer.print(indentString); - writer.print(indentString); - writer.print("columnName = "); - writer.print(field.getColName()); - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); - writer.print("externalType = "); + attributeMap.put("name", field.getName()); + attributeMap.put("columnName", field.getColName()); + attributeMap.put("valueClassName", fieldType.getJavaType()); + attributeMap.put("name", field.getName()); + String sqlType = fieldType.getSqlType(); if (sqlType.indexOf("(") >= 0) { - writer.print(sqlType.substring(0, sqlType.indexOf("("))); - writer.println(";"); - + attributeMap.put("externalType", sqlType.substring(0, sqlType.indexOf("("))); // since there is a field length set that - writer.print(indentString); - writer.print(indentString); - writer.print("width = "); String widthStr = sqlType.substring(sqlType.indexOf("(") + 1, sqlType.indexOf(")")); - // if there is a comma remove it; the format doesn't seem to support this sort of detail + // if there is a comma split by it for width,precision if (widthStr.indexOf(",") >= 0) { - widthStr = widthStr.substring(0, widthStr.indexOf(",")); + attributeMap.put("width", widthStr.substring(0, widthStr.indexOf(","))); + // since there is a field precision set that + attributeMap.put("precision", widthStr.substring(widthStr.indexOf(",") + 1)); + } else { + attributeMap.put("width", widthStr); } - writer.print(widthStr); - } else { - writer.print(sqlType); - } - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); - writer.print("valueClassName = "); - writer.print(fieldType.getJavaType()); - writer.println(";"); - - /* maybe map this one later, probably not needed for diagramming help anyway - writer.print(indentString); - writer.print(indentString); - writer.print("valueType = "); - writer.print(??); - writer.println(";"); - */ - - writer.print(indentString); - if (attrFieldIter.hasNext()) { - writer.println("},"); } else { - writer.println("}"); + attributeMap.put("externalType", sqlType); } } - writer.print(indentString); - writer.println(");"); - + // primaryKeyAttributes - writer.print(indentString); - writer.print("primaryKeyAttributes = ("); - Iterator<ModelField> pkFieldIter = this.getPksIterator(); - while (pkFieldIter.hasNext()) { - ModelField field = pkFieldIter.next(); - writer.print(field.getName()); - if (pkFieldIter.hasNext()) writer.print(", "); + List<String> primaryKeyAttributesList = FastList.newInstance(); + topLevelMap.put("primaryKeyAttributes", primaryKeyAttributesList); + for (ModelField pkField: this.pks) { + primaryKeyAttributesList.add(pkField.getName()); } - writer.println(");"); // relationships - List<ModelRelation> relRelationshipList = FastList.newInstance(); - Iterator<ModelRelation> buildRelationshipIter = this.getRelationsIterator(); - while (buildRelationshipIter.hasNext()) { - ModelRelation relationship = buildRelationshipIter.next(); - + List<Map<String, Object>> relationshipsMapList = FastList.newInstance(); + for (ModelRelation relationship: this.relations) { if (entityNameIncludeSet.contains(relationship.getRelEntityName())) { - relRelationshipList.add(relationship); - } - } - - if (relRelationshipList.size() > 0) { - writer.print(indentString); - writer.println("relationships = ("); - Iterator<ModelRelation> relRelationshipIter = relRelationshipList.iterator(); - while (relRelationshipIter.hasNext()) { - ModelRelation relationship = relRelationshipIter.next(); - - if (!entityNameIncludeSet.contains(relationship.getRelEntityName())) { - continue; - } - - writer.print(indentString); - writer.println("{"); + Map<String, Object> relationshipMap = FastMap.newInstance(); + relationshipsMapList.add(relationshipMap); - writer.print(indentString); - writer.print(indentString); - writer.print("name = "); - writer.print(relationship.getCombinedName()); - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); - writer.print("destination = "); - writer.print(relationship.getRelEntityName()); - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); + relationshipMap.put("name", relationship.getCombinedName()); + relationshipMap.put("destination", relationship.getRelEntityName()); if ("many".equals(relationship.getType())) { - writer.println("isToMany = Y;"); + relationshipMap.put("isToMany", "Y"); } else { - writer.println("isToMany = N;"); + relationshipMap.put("isToMany", "N"); } - - /* nothing in OFBiz entity models for this yet, but might be nice to add in the future - writer.print(indentString); - writer.print(indentString); - writer.print("isMandatory = "); - writer.print(); - writer.println(";"); - */ + relationshipMap.put("joinSemantic", "EOInnerJoin"); - writer.print(indentString); - writer.print(indentString); - writer.println("joinSemantic = EOInnerJoin;"); + //nothing in OFBiz entity models for this yet, but might be nice to add in the future + //relationshipMap.put("isMandatory", ); - writer.print(indentString); - writer.print(indentString); - writer.println("joins = ("); - Iterator<ModelKeyMap> keyMapIter = relationship.getKeyMapsIterator(); - while (keyMapIter.hasNext()) { - ModelKeyMap keyMap = keyMapIter.next(); - - writer.print(indentString); - writer.print(indentString); - writer.println("{"); - - writer.print(indentString); - writer.print(indentString); - writer.print(indentString); - writer.print("sourceAttribute = "); - writer.print(keyMap.getFieldName()); - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); - writer.print(indentString); - writer.print("destinationAttribute = "); - writer.print(keyMap.getRelFieldName()); - writer.println(";"); - - writer.print(indentString); - writer.print(indentString); - if (keyMapIter.hasNext()) { - writer.println("},"); - } else { - writer.println("}"); - } - } - writer.print(indentString); - writer.print(indentString); - writer.println(");"); - - writer.print(indentString); - if (relRelationshipIter.hasNext()) { - writer.println("},"); - } else { - writer.println("}"); + List<Map<String, Object>> joinsMapList = FastList.newInstance(); + relationshipMap.put("joins", joinsMapList); + for (ModelKeyMap keyMap: relationship.getKeyMapsClone()) { + Map<String, Object> joinsMap = FastMap.newInstance(); + joinsMapList.add(joinsMap); + joinsMap.put("sourceAttribute", keyMap.getFieldName()); + joinsMap.put("destinationAttribute", keyMap.getRelFieldName()); } } - writer.print(indentString); - writer.println(");"); + } + if (relationshipsMapList.size() > 0) { + topLevelMap.put("relationships", relationshipsMapList); } - writer.println("}"); + UtilFormatOut.writePlistPropertyMap(topLevelMap, 0, writer, false); } } 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=630541&r1=630540&r2=630541&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 Sat Feb 23 14:45:10 2008 @@ -19,6 +19,9 @@ package org.ofbiz.entity.model; import java.util.*; + +import javolution.util.FastList; + import org.w3c.dom.*; import org.ofbiz.base.util.*; @@ -151,6 +154,12 @@ /** keyMaps defining how to lookup the relatedTable using columns from this table */ public Iterator<ModelKeyMap> getKeyMapsIterator() { return this.keyMaps.iterator(); + } + + public List<ModelKeyMap> getKeyMapsClone() { + List<ModelKeyMap> kmList = FastList.newInstance(); + kmList.addAll(this.keyMaps); + return kmList; } public int getKeyMapsSize() { Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java?rev=630541&r1=630540&r2=630541&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Sat Feb 23 14:45:10 2008 @@ -52,6 +52,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilProperties.UtilResourceBundle; @@ -814,10 +815,12 @@ Set<String> entityNames = new TreeSet(); if (UtilValidate.isNotEmpty(entityPackageName)) { Map<String, TreeSet<String>> entitiesByPackage = reader.getEntitiesByPackage(UtilMisc.toSet(entityPackageName), null); - Debug.logInfo("entitiesByPackage = " + entitiesByPackage, module); - if (entitiesByPackage.get(entityPackageName) != null) { - entityNames.addAll(entitiesByPackage.get(entityPackageName)); + for (Map.Entry<String, TreeSet<String>> entitiesByPackageMapEntry: entitiesByPackage.entrySet()) { + if (entitiesByPackageMapEntry.getKey().contains(entityPackageName)) { + entityNames.addAll(entitiesByPackageMapEntry.getValue()); + } } + Debug.logInfo("Exporting the following entities: " + entityNames, module); } else if (UtilValidate.isNotEmpty(entityGroupId)) { entityNames.addAll(EntityGroupUtil.getEntityNamesByGroup(entityGroupId, dctx.getDelegator())); } else { @@ -835,23 +838,18 @@ } // write the index.eomodeld file - PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, "index.eomodeld")), "UTF-8"))); - writer.println("{"); - writer.println("EOModelVersion = \"2.1\";"); - writer.println("entities = ("); - Iterator<String> entityNameIter = entityNames.iterator(); - while (entityNameIter.hasNext()) { - String entityName = entityNameIter.next(); - writer.print("{ className = EOGenericRecord; name = "); - writer.print(entityName); - if (entityNameIter.hasNext()) { - writer.println("; },"); - } else { - writer.println("; }"); - } + Map<String, Object> topLevelMap = FastMap.newInstance(); + topLevelMap.put("EOModelVersion", "\"2.1\""); + List<Map<String, Object>> entitiesMapList = FastList.newInstance(); + topLevelMap.put("entities", entitiesMapList); + for (String entityName: entityNames) { + Map<String, Object> entitiesMap = FastMap.newInstance(); + entitiesMapList.add(entitiesMap); + entitiesMap.put("className", "EOGenericRecord"); + entitiesMap.put("name", entityName); } - writer.println(");"); - writer.println("}"); + PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, "index.eomodeld")), "UTF-8"))); + UtilFormatOut.writePlistPropertyMap(topLevelMap, 0, writer, false); writer.close(); // write each <EntityName>.plist file |
Free forum by Nabble | Edit this page |