You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2008/03/06 03:08:12 UTC
svn commit: r634119 - in /ofbiz/trunk/framework:
base/src/base/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/model/
service/src/org/ofbiz/service/group/ webtools/src/org/ofbiz/webtools/
webtools/src/org/ofbiz/webtools/artifactinfo/
Author: jonesde
Date: Wed Mar 5 18:08:10 2008
New Revision: 634119
URL: http://svn.apache.org/viewvc?rev=634119&view=rev
Log:
Moved plist stuff to its own file; added simple class to look for stuff in Java code, amazingly seems to be working to find entities/seseems to be working to find entities/services in java services
Added:
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java (with props)
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java (with props)
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/service/src/org/ofbiz/service/group/ServiceGroupEngine.java
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.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=634119&r1=634118&r2=634119&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 Wed Mar 5 18:08:10 2008
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -15,23 +15,13 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *******************************************************************************/
+ */
package org.ofbiz.base.util;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
-import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
-import java.util.Map;
/**
* General output formatting functions - mainly for helping in JSPs
@@ -40,9 +30,6 @@
public static final String module = UtilFormatOut.class.getName();
- /** simple 4 char indentation */
- public static final String indentFourString = " ";
-
public static String safeToString(Object obj) {
if (obj != null) {
return obj.toString();
@@ -509,122 +496,5 @@
}
public static String makeSqlSafe(String unsafeString) {
return unsafeString.replaceAll("'","''");
- }
-
- public static void writePlistProperty(String name, Object value, int indentLevel, PrintWriter writer) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.print(name);
- writer.print(" = ");
- if (value instanceof Map) {
- writer.println();
- writePlistPropertyMap((Map<String, Object>) value, indentLevel, writer, false);
- } else if (value instanceof List) {
- writePlistPropertyValueList((List<Object>) value, indentLevel, writer);
- } else {
- writer.print(value);
- writer.println(";");
- }
- }
- public static void writePlistPropertyMap(Map<String, Object> propertyMap, int indentLevel, PrintWriter writer, boolean appendComma) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println("{");
- for (Map.Entry<String, Object> property: propertyMap.entrySet()) {
- writePlistProperty(property.getKey(), property.getValue(), indentLevel + 1, writer);
- }
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- if (appendComma) {
- writer.println("},");
- } else {
- writer.println("}");
- }
- }
- public static void writePlistPropertyValueList(List<Object> propertyValueList, int indentLevel, PrintWriter writer) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.print("(");
-
- Iterator<Object> propertyValueIter = propertyValueList.iterator();
- while (propertyValueIter.hasNext()) {
- Object propertyValue = propertyValueIter.next();
- if (propertyValue instanceof Map) {
- Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
- writePlistPropertyMap(propertyMap, indentLevel + 1, writer, propertyValueIter.hasNext());
- } else {
- writer.print(propertyValue);
- if (propertyValueIter.hasNext()) writer.print(", ");
- }
- }
-
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println(");");
- }
-
- public static void writePlistPropertyXml(String name, Object value, int indentLevel, PrintWriter writer) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.print("<key>");
- writer.print(name);
- writer.println("</key>");
- if (value instanceof Map) {
- writePlistPropertyMapXml((Map<String, Object>) value, indentLevel, writer);
- } else if (value instanceof List) {
- writePlistPropertyValueListXml((List<Object>) value, indentLevel, writer);
- } else {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.print("<string>");
- writer.print(value);
- writer.println("</string>");
- }
- }
- public static void writePlistPropertyMapXml(Map<String, Object> propertyMap, int indentLevel, PrintWriter writer) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println("<dict>");
- for (Map.Entry<String, Object> property: propertyMap.entrySet()) {
- writePlistPropertyXml(property.getKey(), property.getValue(), indentLevel + 1, writer);
- }
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println("</dict>");
- }
- public static void writePlistPropertyValueListXml(List<Object> propertyValueList, int indentLevel, PrintWriter writer) {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println("<array>");
-
- indentLevel++;
- Iterator<Object> propertyValueIter = propertyValueList.iterator();
- while (propertyValueIter.hasNext()) {
- Object propertyValue = propertyValueIter.next();
- if (propertyValue instanceof Map) {
- Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
- writePlistPropertyMapXml(propertyMap, indentLevel, writer);
- } else {
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.print("<string>");
- writer.print(propertyValue);
- writer.println("</string>");
- }
- }
- indentLevel--;
-
- for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
- writer.println("</array>");
- }
-
- /**
- * Writes model information in the Apple EOModelBundle format.
- *
- * For document structure and definition see: http://developer.apple.com/documentation/InternetWeb/Reference/WO_BundleReference/Articles/EOModelBundle.html
- *
- * @param eoModelMap
- * @param eomodeldFullPath
- * @param filename
- * @throws FileNotFoundException
- * @throws UnsupportedEncodingException
- */
- public static void writePlistFile(Map<String, Object> eoModelMap, String eomodeldFullPath, String filename, boolean useXml) throws FileNotFoundException, UnsupportedEncodingException {
- PrintWriter plistWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, filename)), "UTF-8")));
- if (useXml) {
- UtilFormatOut.writePlistPropertyMapXml(eoModelMap, 0, plistWriter);
- } else {
- UtilFormatOut.writePlistPropertyMap(eoModelMap, 0, plistWriter, false);
- }
- plistWriter.close();
}
}
Added: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java?rev=634119&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java (added)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java Wed Mar 5 18:08:10 2008
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.base.util;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Set;
+
+import javolution.util.FastSet;
+
+import org.ofbiz.base.component.ComponentConfig;
+
+
+/**
+ * Java Source Parsing Utilities
+ *
+ * NOTE: the approach here is not the best and it may be better to use a parser, line one based on antlr, or using a Java Bytecode parser to look at .class files.
+ *
+ */
+public class UtilJavaParse {
+
+ public static final String module = UtilJavaParse.class.getName();
+
+ public static String findRealPathAndFileForClass(String fullyQualifiedClassName) {
+ // search through the component directories, in the src directory for each, using the class path as the path within it
+
+ String sourceSubPath = fullyQualifiedClassName.substring(0, fullyQualifiedClassName.lastIndexOf(".")).replace('.', File.separatorChar);
+ String classFileName = fullyQualifiedClassName.substring(fullyQualifiedClassName.lastIndexOf(".")+1) + ".java";
+
+ Collection<ComponentConfig> allComponentConfigs = ComponentConfig.getAllComponents();
+ for (ComponentConfig cc: allComponentConfigs) {
+ String rootDirectory = cc.getRootLocation();
+ if (!rootDirectory.endsWith(File.separatorChar + "")) rootDirectory += File.separatorChar;
+ rootDirectory += "src" + File.separatorChar;
+
+ File rootDirFile = new File(rootDirectory);
+ if (!rootDirFile.exists()) {
+ // no src directory, move along
+ continue;
+ }
+
+ String classDir = rootDirectory + sourceSubPath;
+ File classDirFile = new File(classDir);
+ if (!classDirFile.exists()) {
+ // no src class sub-directory, move along
+ continue;
+ }
+
+ String fullPathAndFile = classDir + File.separatorChar + classFileName;
+ File classFile = new File(fullPathAndFile);
+ if (classFile.exists()) {
+ Debug.logInfo("In findRealPathAndFileForClass for [" + fullyQualifiedClassName + "]: [" + fullPathAndFile + "]", module);
+ return fullPathAndFile;
+ }
+ }
+
+ return null;
+ }
+
+ public static int findServiceMethodBlockStart(String methodName, String javaFile) {
+ Debug.logInfo("In findServiceMethodBlockStart for " + methodName, module);
+
+ // starts with something like this: public static Map exportServiceEoModelBundle(DispatchContext dctx, Map context) {
+
+ // start with the main pattern
+ int methodNameIndex = javaFile.indexOf("public static Map " + methodName + "(DispatchContext dctx, Map context) {");
+ // try a little less... and some nice messy variations...
+ if (methodNameIndex < 0) methodNameIndex = javaFile.indexOf(" Map " + methodName + "(DispatchContext ");
+ if (methodNameIndex < 0) methodNameIndex = javaFile.indexOf(" Map " + methodName + "(DispatchContext ");
+ if (methodNameIndex < 0) methodNameIndex = javaFile.indexOf(" Map " + methodName + " (DispatchContext ");
+ if (methodNameIndex < 0) methodNameIndex = javaFile.indexOf(" Map " + methodName + "( DispatchContext ");
+ if (methodNameIndex < 0) methodNameIndex = javaFile.indexOf(" Map " + methodName + " ( DispatchContext ");
+
+ // not found!
+ if (methodNameIndex < 0) return -1;
+
+ // find the open brace and return its position
+ return javaFile.indexOf("{", methodNameIndex);
+ }
+
+ public static int findEndOfBlock(int blockStart, String javaFile) {
+ //Debug.logInfo("In findEndOfBlock for blockStart " + blockStart, module);
+
+ int nextOpen = javaFile.indexOf("{", blockStart+1);
+ int nextClose = javaFile.indexOf("}", blockStart+1);
+
+ // if no close, end with couldn't find
+ if (nextClose < 0) return -1;
+ // while nextOpen is found and is before the next close, then recurse (list
+ while (nextOpen > -1 && nextOpen < nextClose) {
+ int endOfSubBlock = findEndOfBlock(nextOpen, javaFile);
+ if (endOfSubBlock < 0) return -1;
+ nextOpen = javaFile.indexOf("{", endOfSubBlock+1);
+ nextClose = javaFile.indexOf("}", endOfSubBlock+1);
+ //Debug.logInfo("In loop in findEndOfBlock for nextOpen=" + nextOpen + ", nextClose=" + nextClose + ", endOfSubBlock=" + endOfSubBlock, module);
+ }
+
+ // at this point there should be no nextOpen or nextOpen is after the nextClose, meaning we're at the end of the block
+ return nextClose;
+ }
+
+ public static Set<String> serviceMethodNames = FastSet.newInstance();
+ static {
+ serviceMethodNames.add("runSync");
+ serviceMethodNames.add("runSyncIgnore");
+ serviceMethodNames.add("runAsync");
+ serviceMethodNames.add("runAsyncWait");
+ serviceMethodNames.add("registerCallback");
+ serviceMethodNames.add("schedule"); // NOTE: the service name may be the 1st, 2nd or 3rd param for variations on this
+ serviceMethodNames.add("addRollbackService");
+ serviceMethodNames.add("addCommitService");
+ }
+ public static Set<String> findServiceCallsInBlock(int blockStart, int blockEnd, String javaFile) {
+ Set<String> serviceNameSet = FastSet.newInstance();
+
+ int dispatcherIndex = javaFile.indexOf("dispatcher.", blockStart+1);
+ while (dispatcherIndex > 0 && dispatcherIndex < blockEnd) {
+ // verify it is a call we're looking for
+ int openParenIndex = javaFile.indexOf("(", dispatcherIndex);
+ String curMethodName = javaFile.substring(dispatcherIndex + 11, openParenIndex).trim();
+ if (serviceMethodNames.contains(curMethodName)) {
+ // find the service name
+ int openQuoteIndex = javaFile.indexOf("\"", openParenIndex);
+ int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex+1);
+ String serviceName = javaFile.substring(openQuoteIndex+1, closeQuoteIndex).trim();
+ //Debug.logInfo("In findServiceCallsInBlock found serviceName [" + serviceName + "]", module);
+
+ serviceNameSet.add(serviceName);
+ }
+
+ dispatcherIndex = javaFile.indexOf("dispatcher.", openParenIndex);
+ }
+
+ return serviceNameSet;
+ }
+
+ public static Set<String> entityMethodNames = FastSet.newInstance();
+ static {
+ entityMethodNames.add("getModelEntity");
+ entityMethodNames.add("getEntityGroupName");
+ entityMethodNames.add("getModelEntitiesByGroup");
+ entityMethodNames.add("getModelEntityMapByGroup");
+ entityMethodNames.add("getGroupHelperName");
+ entityMethodNames.add("getEntityHelperName");
+ entityMethodNames.add("getEntityHelper");
+
+ entityMethodNames.add("makeValue");
+ entityMethodNames.add("makeValueSingle");
+ entityMethodNames.add("makeValidValue");
+ entityMethodNames.add("makePK");
+ entityMethodNames.add("makePKSingle");
+
+ entityMethodNames.add("create");
+ entityMethodNames.add("createSingle");
+ entityMethodNames.add("removeByAnd");
+ entityMethodNames.add("removeByCondition");
+
+ entityMethodNames.add("create");
+ entityMethodNames.add("createSingle");
+ entityMethodNames.add("removeByAnd");
+ entityMethodNames.add("removeByCondition");
+ entityMethodNames.add("storeByCondition");
+ entityMethodNames.add("removeAll");
+ entityMethodNames.add("findOne");
+ entityMethodNames.add("findByPrimaryKey");
+ entityMethodNames.add("findByPrimaryKeySingle");
+ entityMethodNames.add("findByPrimaryKeyCache");
+ entityMethodNames.add("findByPrimaryKeyCacheSingle");
+ entityMethodNames.add("findAll");
+ entityMethodNames.add("findAllCache");
+ entityMethodNames.add("findByAnd");
+ entityMethodNames.add("findByOr");
+ entityMethodNames.add("findByAndCache");
+ entityMethodNames.add("findByLike");
+ entityMethodNames.add("findByCondition");
+ entityMethodNames.add("findByConditionCache");
+ entityMethodNames.add("findListIteratorByCondition");
+ entityMethodNames.add("find");
+ entityMethodNames.add("findList");
+ entityMethodNames.add("findCountByAnd");
+ entityMethodNames.add("findCountByCondition");
+ }
+ public static Set<String> findEntityUseInBlock(int blockStart, int blockEnd, String javaFile) {
+ Set<String> entityNameSet = FastSet.newInstance();
+
+ int delegatorIndex = javaFile.indexOf("delegator.", blockStart+1);
+ while (delegatorIndex > 0 && delegatorIndex < blockEnd) {
+ // verify it is a call we're looking for
+ int openParenIndex = javaFile.indexOf("(", delegatorIndex);
+ String curMethodName = javaFile.substring(delegatorIndex + 10, openParenIndex).trim();
+ if (entityMethodNames.contains(curMethodName)) {
+ // find the entity name
+ int openQuoteIndex = javaFile.indexOf("\"", openParenIndex);
+ int closeQuoteIndex = javaFile.indexOf("\"", openQuoteIndex+1);
+ String entityName = javaFile.substring(openQuoteIndex+1, closeQuoteIndex).trim();
+ //Debug.logInfo("In findServiceCallsInBlock found valid entityName [" + entityName + "]", module);
+
+ entityNameSet.add(entityName);
+ }
+
+ delegatorIndex = javaFile.indexOf("delegator.", openParenIndex);
+ }
+
+ return entityNameSet;
+ }
+}
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java?rev=634119&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java (added)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java Wed Mar 5 18:08:10 2008
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.base.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * File Utilities
+ *
+ */
+public class UtilPlist {
+
+ public static final String module = UtilPlist.class.getName();
+
+ /** simple 4 char indentation */
+ public static final String indentFourString = " ";
+
+ public static void writePlistProperty(String name, Object value, int indentLevel, PrintWriter writer) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.print(name);
+ writer.print(" = ");
+ if (value instanceof Map) {
+ writer.println();
+ writePlistPropertyMap((Map<String, Object>) value, indentLevel, writer, false);
+ } else if (value instanceof List) {
+ writePlistPropertyValueList((List<Object>) value, indentLevel, writer);
+ } else {
+ writer.print(value);
+ writer.println(";");
+ }
+ }
+ public static void writePlistPropertyMap(Map<String, Object> propertyMap, int indentLevel, PrintWriter writer, boolean appendComma) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println("{");
+ for (Map.Entry<String, Object> property: propertyMap.entrySet()) {
+ writePlistProperty(property.getKey(), property.getValue(), indentLevel + 1, writer);
+ }
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ if (appendComma) {
+ writer.println("},");
+ } else {
+ writer.println("}");
+ }
+ }
+ public static void writePlistPropertyValueList(List<Object> propertyValueList, int indentLevel, PrintWriter writer) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.print("(");
+
+ Iterator<Object> propertyValueIter = propertyValueList.iterator();
+ while (propertyValueIter.hasNext()) {
+ Object propertyValue = propertyValueIter.next();
+ if (propertyValue instanceof Map) {
+ Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
+ writePlistPropertyMap(propertyMap, indentLevel + 1, writer, propertyValueIter.hasNext());
+ } else {
+ writer.print(propertyValue);
+ if (propertyValueIter.hasNext()) writer.print(", ");
+ }
+ }
+
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println(");");
+ }
+
+ public static void writePlistPropertyXml(String name, Object value, int indentLevel, PrintWriter writer) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.print("<key>");
+ writer.print(name);
+ writer.println("</key>");
+ if (value instanceof Map) {
+ writePlistPropertyMapXml((Map<String, Object>) value, indentLevel, writer);
+ } else if (value instanceof List) {
+ writePlistPropertyValueListXml((List<Object>) value, indentLevel, writer);
+ } else {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.print("<string>");
+ writer.print(value);
+ writer.println("</string>");
+ }
+ }
+ public static void writePlistPropertyMapXml(Map<String, Object> propertyMap, int indentLevel, PrintWriter writer) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println("<dict>");
+ for (Map.Entry<String, Object> property: propertyMap.entrySet()) {
+ writePlistPropertyXml(property.getKey(), property.getValue(), indentLevel + 1, writer);
+ }
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println("</dict>");
+ }
+ public static void writePlistPropertyValueListXml(List<Object> propertyValueList, int indentLevel, PrintWriter writer) {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println("<array>");
+
+ indentLevel++;
+ Iterator<Object> propertyValueIter = propertyValueList.iterator();
+ while (propertyValueIter.hasNext()) {
+ Object propertyValue = propertyValueIter.next();
+ if (propertyValue instanceof Map) {
+ Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
+ writePlistPropertyMapXml(propertyMap, indentLevel, writer);
+ } else {
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.print("<string>");
+ writer.print(propertyValue);
+ writer.println("</string>");
+ }
+ }
+ indentLevel--;
+
+ for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+ writer.println("</array>");
+ }
+
+ /**
+ * Writes model information in the Apple EOModelBundle format.
+ *
+ * For document structure and definition see: http://developer.apple.com/documentation/InternetWeb/Reference/WO_BundleReference/Articles/EOModelBundle.html
+ *
+ * @param eoModelMap
+ * @param eomodeldFullPath
+ * @param filename
+ * @throws FileNotFoundException
+ * @throws UnsupportedEncodingException
+ */
+ public static void writePlistFile(Map<String, Object> eoModelMap, String eomodeldFullPath, String filename, boolean useXml) throws FileNotFoundException, UnsupportedEncodingException {
+ PrintWriter plistWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, filename)), "UTF-8")));
+ if (useXml) {
+ writePlistPropertyMapXml(eoModelMap, 0, plistWriter);
+ } else {
+ writePlistPropertyMap(eoModelMap, 0, plistWriter, false);
+ }
+ plistWriter.close();
+ }
+}
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=634119&r1=634118&r2=634119&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 Mar 5 18:08:10 2008
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *******************************************************************************/
+ */
package org.ofbiz.entity.model;
import java.io.PrintWriter;
@@ -29,16 +29,15 @@
import javolution.util.FastList;
import javolution.util.FastMap;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+
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.UtilPlist;
import org.ofbiz.base.util.UtilTimer;
-import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericEntityException;
@@ -46,6 +45,8 @@
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
import org.ofbiz.entity.jdbc.DatabaseUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* Generic Entity - Entity model class
@@ -1398,7 +1399,7 @@
if (entityPrefix == null) entityPrefix = "";
if (helperName == null) helperName = "localderby";
- UtilFormatOut.writePlistPropertyMap(this.createEoModelMap(entityPrefix, helperName, entityNameIncludeSet, entityModelReader), 0, writer, false);
+ UtilPlist.writePlistPropertyMap(this.createEoModelMap(entityPrefix, helperName, entityNameIncludeSet, entityModelReader), 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=634119&r1=634118&r2=634119&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 Mar 5 18:08:10 2008
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -15,16 +15,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *******************************************************************************/
+ */
package org.ofbiz.entity.model;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
import javolution.util.FastList;
-import org.w3c.dom.*;
-
-import org.ofbiz.base.util.*;
+import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* Generic Entity - Relation model class
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java?rev=634119&r1=634118&r2=634119&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java Wed Mar 5 18:08:10 2008
@@ -46,8 +46,9 @@
if (groupModel == null) {
groupModel = ServiceGroupReader.getGroupModel(this.getLocation(modelService));
}
- if (groupModel == null)
+ if (groupModel == null) {
throw new GenericServiceException("GroupModel was null; not a valid ServiceGroup!");
+ }
return groupModel.run(dispatcher, localName, context);
}
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=634119&r1=634118&r2=634119&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Wed Mar 5 18:08:10 2008
@@ -55,8 +55,8 @@
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilDateTime;
-import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilPlist;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilURL;
import org.ofbiz.base.util.UtilValidate;
@@ -859,12 +859,12 @@
entitiesMap.put("className", "EOGenericRecord");
entitiesMap.put("name", entityName);
}
- UtilFormatOut.writePlistFile(topLevelMap, eomodeldFullPath, "index.eomodeld", true);
+ UtilPlist.writePlistFile(topLevelMap, eomodeldFullPath, "index.eomodeld", true);
// write each <EntityName>.plist file
for (String curEntityName: entityNames) {
ModelEntity modelEntity = reader.getModelEntity(curEntityName);
- UtilFormatOut.writePlistFile(modelEntity.createEoModelMap(entityNamePrefix, datasourceName, entityNames, reader), eomodeldFullPath, curEntityName +".plist", true);
+ UtilPlist.writePlistFile(modelEntity.createEoModelMap(entityNamePrefix, datasourceName, entityNames, reader), eomodeldFullPath, curEntityName +".plist", true);
}
return ServiceUtil.returnSuccess("Exported eomodeld file for " + entityNames.size() + " entities to: " + eomodeldFullPath);
Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java?rev=634119&r1=634118&r2=634119&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java Wed Mar 5 18:08:10 2008
@@ -29,6 +29,7 @@
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelReader;
@@ -50,7 +51,7 @@
*/
public class ArtifactInfoFactory {
- protected static Map<String, ArtifactInfoFactory> artifactInfoFactoryCache = FastMap.newInstance();
+ protected static UtilCache<String, ArtifactInfoFactory> artifactInfoFactoryCache = new UtilCache("ArtifactInfoFactory");
protected String delegatorName;
protected ModelReader entityModelReader;
Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java?rev=634119&r1=634118&r2=634119&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java Wed Mar 5 18:08:10 2008
@@ -19,6 +19,7 @@
package org.ofbiz.webtools.artifactinfo;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
@@ -29,16 +30,20 @@
import javolution.util.FastSet;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.FileUtil;
import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilJavaParse;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilPlist;
import org.ofbiz.minilang.MiniLangException;
import org.ofbiz.minilang.SimpleMethod;
-import org.ofbiz.minilang.method.callops.CallSimpleMethod;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.eca.ServiceEcaRule;
import org.ofbiz.service.eca.ServiceEcaUtil;
+import org.ofbiz.service.group.GroupModel;
+import org.ofbiz.service.group.GroupServiceModel;
+import org.ofbiz.service.group.ServiceGroupReader;
/**
*
@@ -87,23 +92,44 @@
}
Set<String> allEntityNameSet = simpleMethodToCall.getAllEntityNamesUsed();
- for (String entityName: allEntityNameSet) {
- if (entityName.contains("${")) {
- continue;
- }
- if (!aif.getEntityModelReader().getEntityNames().contains(entityName)) {
- Debug.logWarning("Entity [" + entityName + "] reference in service [" + this.modelService.name + "] does not exist!", module);
- continue;
+ populateEntitiesFromNameSet(allEntityNameSet);
+ } else if ("java".equals(this.modelService.engineName)) {
+ String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
+ if (fullClassPathAndFile != null) {
+ String javaFile = null;
+ try {
+ javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
+ } catch (FileNotFoundException e) {
+ Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
+ return;
+ } catch (IOException e) {
+ Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
+ return;
}
- // the forward reference
- this.entitiesUsedByThisService.add(aif.getEntityArtifactInfo(entityName));
- // the reverse reference
- UtilMisc.addToSetInMap(this, aif.allServiceInfosReferringToEntityName, entityName);
-
+ int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
+ int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
+ Set<String> allEntityNameSet = UtilJavaParse.findEntityUseInBlock(methodBlockStart, methodBlockEnd, javaFile);
+ populateEntitiesFromNameSet(allEntityNameSet);
+ }
+ } else if ("group".equals(this.modelService.engineName)) {
+ // nothing to do, there won't be entities referred to in these
+ }
+ }
+ protected void populateEntitiesFromNameSet(Set<String> allEntityNameSet) throws GeneralException {
+ for (String entityName: allEntityNameSet) {
+ if (entityName.contains("${")) {
+ continue;
+ }
+ if (!aif.getEntityModelReader().getEntityNames().contains(entityName)) {
+ Debug.logWarning("Entity [" + entityName + "] reference in service [" + this.modelService.name + "] does not exist!", module);
+ continue;
}
- } else if ("java".equals(this.modelService.engineName)) {
- // TODO: can't do anything about this :( ...YET! :)
+
+ // the forward reference
+ this.entitiesUsedByThisService.add(aif.getEntityArtifactInfo(entityName));
+ // the reverse reference
+ UtilMisc.addToSetInMap(this, aif.allServiceInfosReferringToEntityName, entityName);
}
}
@@ -124,22 +150,59 @@
}
Set<String> allServiceNameSet = simpleMethodToCall.getAllServiceNamesCalled();
- for (String serviceName: allServiceNameSet) {
- if (serviceName.contains("${")) {
- continue;
- }
- if (!aif.getDispatchContext().getAllServiceNames().contains(serviceName)) {
- Debug.logWarning("Service [" + serviceName + "] reference in service [" + this.modelService.name + "] does not exist!", module);
- continue;
+ populateServicesFromNameSet(allServiceNameSet);
+ } else if ("java".equals(this.modelService.engineName)) {
+ String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
+ if (fullClassPathAndFile != null) {
+ String javaFile = null;
+ try {
+ javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
+ } catch (FileNotFoundException e) {
+ Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
+ return;
+ } catch (IOException e) {
+ Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
+ return;
}
- // the forward reference
- this.servicesCalledByThisService.add(aif.getServiceArtifactInfo(serviceName));
- // the reverse reference
- UtilMisc.addToSetInMap(this, aif.allServiceInfosReferringToServiceName, serviceName);
+ int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
+ int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
+ Set<String> allServiceNameSet = UtilJavaParse.findServiceCallsInBlock(methodBlockStart, methodBlockEnd, javaFile);
+
+ populateServicesFromNameSet(allServiceNameSet);
}
- } else if ("java".equals(this.modelService.engineName)) {
- // TODO: can't do anything about this :( ...YET! :)
+ } else if ("group".equals(this.modelService.engineName)) {
+ Set<String> allServiceNameSet = FastSet.newInstance();
+ GroupModel groupModel = modelService.internalGroup;
+ if (groupModel == null) {
+ groupModel = ServiceGroupReader.getGroupModel(this.modelService.location);
+ }
+
+ if (groupModel != null) {
+ List<GroupServiceModel> groupServiceModels = groupModel.getServices();
+ for (GroupServiceModel groupServiceModel: groupServiceModels) {
+ allServiceNameSet.add(groupServiceModel.getName());
+ }
+ }
+
+ populateServicesFromNameSet(allServiceNameSet);
+ }
+ }
+
+ protected void populateServicesFromNameSet(Set<String> allServiceNameSet) throws GeneralException {
+ for (String serviceName: allServiceNameSet) {
+ if (serviceName.contains("${")) {
+ continue;
+ }
+ if (!aif.getDispatchContext().getAllServiceNames().contains(serviceName)) {
+ Debug.logWarning("Service [" + serviceName + "] reference in service [" + this.modelService.name + "] does not exist!", module);
+ continue;
+ }
+
+ // the forward reference
+ this.servicesCalledByThisService.add(aif.getServiceArtifactInfo(serviceName));
+ // the reverse reference
+ UtilMisc.addToSetInMap(this, aif.allServiceInfosReferringToServiceName, serviceName);
}
}
@@ -286,20 +349,20 @@
entitiesMap.put("className", "EOGenericRecord");
entitiesMap.put("name", entityName);
}
- UtilFormatOut.writePlistFile(indexEoModelMap, eomodeldFullPath, "index.eomodeld", true);
+ UtilPlist.writePlistFile(indexEoModelMap, eomodeldFullPath, "index.eomodeld", true);
// write this service description file
Map<String, Object> thisServiceEoModelMap = createEoModelMap(callingServiceSet, calledServiceSet, callingServiceEcaSet, calledServiceEcaSet, useMoreDetailedNames);
- UtilFormatOut.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, this.getDisplayPrefixedName() + ".plist", true);
+ UtilPlist.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, this.getDisplayPrefixedName() + ".plist", true);
// write service description files
for (ServiceArtifactInfo callingService: callingServiceSet) {
Map<String, Object> serviceEoModelMap = callingService.createEoModelMap(null, UtilMisc.toSet(this), null, null, useMoreDetailedNames);
- UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, callingService.getDisplayPrefixedName() + ".plist", true);
+ UtilPlist.writePlistFile(serviceEoModelMap, eomodeldFullPath, callingService.getDisplayPrefixedName() + ".plist", true);
}
for (ServiceArtifactInfo calledService: calledServiceSet) {
Map<String, Object> serviceEoModelMap = calledService.createEoModelMap(UtilMisc.toSet(this), null, null, null, useMoreDetailedNames);
- UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, calledService.getDisplayPrefixedName() + ".plist", true);
+ UtilPlist.writePlistFile(serviceEoModelMap, eomodeldFullPath, calledService.getDisplayPrefixedName() + ".plist", true);
}
// write SECA description files
@@ -313,7 +376,7 @@
ecaCallingServiceSet.add(this);
Map<String, Object> serviceEcaEoModelMap = callingServiceEca.createEoModelMap(ecaCallingServiceSet, useMoreDetailedNames);
- UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, callingServiceEca.getDisplayPrefixedName() + ".plist", true);
+ UtilPlist.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, callingServiceEca.getDisplayPrefixedName() + ".plist", true);
}
}
for (ServiceEcaArtifactInfo calledServiceEca: calledServiceEcaSet) {
@@ -325,7 +388,7 @@
ecaCalledServiceSet.add(this);
Map<String, Object> serviceEcaEoModelMap = calledServiceEca.createEoModelMap(ecaCalledServiceSet, useMoreDetailedNames);
- UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, calledServiceEca.getDisplayPrefixedName() + ".plist", true);
+ UtilPlist.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, calledServiceEca.getDisplayPrefixedName() + ".plist", true);
}
}