Author: doogie
Date: Fri Nov 13 07:20:15 2009 New Revision: 835764 URL: http://svn.apache.org/viewvc?rev=835764&view=rev Log: Methods to convert dynamic views back to xml. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.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=835764&r1=835763&r2=835764&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 Fri Nov 13 07:20:15 2009 @@ -18,12 +18,18 @@ *******************************************************************************/ package org.ofbiz.entity.model; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember; import org.ofbiz.entity.model.ModelViewEntity.ModelAlias; @@ -77,6 +83,66 @@ return modelViewEntity; } + public String getViewXml(String entityName) throws IOException { + Document doc = UtilXml.makeEmptyXmlDocument(); + Element viewElement = getViewElement(doc, entityName); + return UtilXml.writeXmlDocument(viewElement); + } + + public Element getViewElement(Document doc, String entityName) { + Element viewElement = doc.createElement("view-entity"); + viewElement.setAttribute("entity-name", entityName); + + for (ModelMemberEntity member: memberModelMemberEntities.values()) { + Element memberElement = doc.createElement("member-entity"); + memberElement.setAttribute("entity-alias", member.getEntityAlias()); + memberElement.setAttribute("entity-name", member.getEntityName()); + viewElement.appendChild(memberElement); + } + for (ModelAliasAll aliasAll: aliasAlls) { + Element aliasAllElement = doc.createElement("alias-all"); + aliasAllElement.setAttribute("entity-alias", aliasAll.getEntityAlias()); + if (UtilValidate.isNotEmpty(aliasAll.getPrefix())) aliasAllElement.setAttribute("prefix", aliasAll.getPrefix()); + if (aliasAll.getGroupBy()) aliasAllElement.setAttribute("group-by", "true"); + if (UtilValidate.isNotEmpty(aliasAll.getFunction())) aliasAllElement.setAttribute("function", aliasAll.getFunction()); + for (String excludeField: aliasAll) { + Element excludeElement = doc.createElement("exclude"); + excludeElement.setAttribute("field", excludeField); + aliasAllElement.appendChild(excludeElement); + } + viewElement.appendChild(aliasAllElement); + } + for (ModelAlias alias: aliases) { + Element aliasElement = doc.createElement("alias"); + aliasElement.setAttribute("entity-alias", alias.getEntityAlias()); + aliasElement.setAttribute("name", alias.getName()); + if (!alias.getName().equals(alias.getField())) aliasElement.setAttribute("field", alias.getField()); + String colAlias = ModelUtil.dbNameToVarName(alias.getColAlias()); + if (!alias.getName().equals(colAlias)) aliasElement.setAttribute("col-alias", colAlias); + if (alias.getIsPk() != null) aliasElement.setAttribute("prim-key", alias.getIsPk().toString()); + if (alias.getGroupBy()) aliasElement.setAttribute("group-by", "true"); + if (UtilValidate.isNotEmpty(alias.getFunction())) aliasElement.setAttribute("function", alias.getFunction()); + // TODO: description, complex-alias + viewElement.appendChild(aliasElement); + } + for (ModelViewLink viewLink: viewLinks) { + Element viewLinkElement = doc.createElement("view-link"); + viewLinkElement.setAttribute("entity-alias", viewLink.getEntityAlias()); + if (viewLink.isRelOptional()) viewLinkElement.setAttribute("rel-optional", "true"); + viewLinkElement.setAttribute("rel-entity-alias", viewLink.getRelEntityAlias()); + for (ModelKeyMap keyMap: viewLink) { + Element keyMapElement = doc.createElement("key-map"); + keyMapElement.setAttribute("field-name", keyMap.getFieldName()); + if (!keyMap.getFieldName().equals(keyMap.getRelFieldName())) keyMapElement.setAttribute("rel-field-name", keyMap.getRelFieldName()); + viewLinkElement.appendChild(keyMapElement); + } + // TODO: conditions + viewElement.appendChild(viewLinkElement); + } + // TODO: relations + return viewElement; + } + public String getOneRealEntityName() { // return first entity name for memberModelMemberEntities Map if (this.memberModelMemberEntities.size() == 0) { 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=835764&r1=835763&r2=835764&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 Fri Nov 13 07:20:15 2009 @@ -730,7 +730,7 @@ } } - public static class ModelAliasAll implements Serializable { + public static class ModelAliasAll implements Serializable, Iterable<String> { protected String entityAlias = ""; protected String prefix = ""; protected Set<String> fieldsToExclude = null; @@ -784,6 +784,10 @@ return this.fieldsToExclude.contains(fieldName); } } + + public Iterator<String> iterator() { + return fieldsToExclude.iterator(); + } } public static class ModelAlias implements Serializable { @@ -997,7 +1001,7 @@ } } - public static class ModelViewLink implements Serializable { + public static class ModelViewLink implements Serializable, Iterable<ModelKeyMap> { protected String entityAlias = ""; protected String relEntityAlias = ""; protected boolean relOptional = false; @@ -1063,6 +1067,10 @@ return this.keyMaps.iterator(); } + public Iterator<ModelKeyMap> iterator() { + return this.keyMaps.iterator(); + } + public List<ModelKeyMap> getKeyMapsCopy() { List<ModelKeyMap> newList = FastList.newInstance(); newList.addAll(this.keyMaps); |
Free forum by Nabble | Edit this page |