You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2010/10/14 01:11:11 UTC

svn commit: r1022319 - in /openjpa/tools/trunk/openjpa-tools/src: main/java/org/apache/openjpa/tools/ main/java/org/apache/openjpa/tools/action/ main/resources/org/apache/openjpa/tools/ test/java/org/apache/openjpa/tools/ test/resources/

Author: ppoddar
Date: Wed Oct 13 23:11:10 2010
New Revision: 1022319

URL: http://svn.apache.org/viewvc?rev=1022319&view=rev
Log:
Clean up Actions. Remove -error option

Modified:
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/localizer.properties
    openjpa/tools/trunk/openjpa-tools/src/test/java/org/apache/openjpa/tools/TestMigratedOutput.java
    openjpa/tools/trunk/openjpa-tools/src/test/resources/sample.hbm.xml

Modified: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java?rev=1022319&r1=1022318&r2=1022319&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java (original)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java Wed Oct 13 23:11:10 2010
@@ -33,9 +33,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.FileHandler;
-import java.util.logging.Handler;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -61,7 +58,6 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.w3c.dom.UserDataHandler;
 
 
 /**
@@ -72,8 +68,7 @@ import org.w3c.dom.UserDataHandler;
  * Configuration files to JPA standard mapping/configuration files.
  * <p>
  * Usage:<br>
- * <code>$ java org.apache.openjpa.tools.MigrationTool -i input [-o output] [-err error output] 
- * [-rule rule xml] [-verbose]</code>
+ * <code>$ java org.apache.openjpa.tools.MigrationTool -i input [-o output] [-rule rule xml] [-verbose]</code>
  * <br>
  * Simply typing<br>
  * <code>$ java org.apache.openjpa.tools.MigrationTool</code>
@@ -94,10 +89,10 @@ import org.w3c.dom.UserDataHandler;
  * (e.g. <code>&lt;attributes&gt;</code> below <code>&lt;entity&gt;</code>)
  * <LI>some element can be fully replaced by its own child element (e.g. <code>&lt;bag&gt;</code>)
  * <br>
- * These actions, wherever possible, are parameterized and defined via an 
- * <A HREF="../../../../resources/META-INF/migration-actions.xsd">XML Schema definition</A>.
- * The recipe to transform individual Hibernate elements are described in a 
- *  <A HREF="../../../../resources/META-INF/migration-actions.xml">XML specification</A>
+ * These actions, wherever possible, are parameterized and defined via an XML Schema definition 
+ * <A HREF="../../../../resources/META-INF/migration-actions.xsd">migration-actions.xsd</A>.
+ * The recipe to transform individual Hibernate elements are described in a XML specification 
+ *  <A HREF="../../../../resources/META-INF/migration-actions.xml">migration-actions.xml</A>
  *  complaint to this schema.
  * 
  *  
@@ -138,7 +133,6 @@ public class MigrationTool  {
     public void run(String[] args) throws Exception {
     	Properties defaults = new Properties();
     	defaults.setProperty("output", "stdout");
-    	defaults.setProperty("error",  "stderr");
     	defaults.setProperty("actions", DEFAULT_ACTIONS);
     	defaults.setProperty("verbose", "false");
     	
@@ -193,16 +187,6 @@ public class MigrationTool  {
     	}
     }
     
-    public void setError(String errorOutput) throws IOException {
-        Handler handler = null;
-        if ("stderr".equals(errorOutput)) {
-        	handler = new ConsoleHandler();
-        } else if (errorOutput.endsWith("+")) {
-            handler = new FileHandler(errorOutput.substring(errorOutput.length()-1), true);
-        } else {
-            handler = new FileHandler(errorOutput, false);
-        }
-    }
     
     public void setActions(String actions) throws Exception {
     	_rulebase = getInputStream(actions);

Modified: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java?rev=1022319&r1=1022318&r2=1022319&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java (original)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java Wed Oct 13 23:11:10 2010
@@ -144,11 +144,16 @@ public interface Actions {
         protected final Element original;
         protected final Code order;
         protected boolean silent;
+        protected String sourceName;
+        protected String targetName;
 
         protected Abstract(Code o, Element s) {
             order = o;
             original = s;
-            silent = "false".equalsIgnoreCase(s.getAttribute(WARN));
+            sourceName = getAttribute(FROM, false);
+            targetName = getAttribute(TO, false);
+            silent = "false".equalsIgnoreCase(getAttribute(WARN, false));
+            
         }
 
         /**
@@ -158,12 +163,16 @@ public interface Actions {
             return order;
         }
 
+        protected String getAttribute(String attrName) {
+            return getAttribute(attrName, true);
+        }
+        
         /**
          * Gets the attribute value as the parameter of the action. This accessor validates that the attribute indeed
          * exists.
          */
-        protected String getAttribute(String attrName) {
-            if (!original.hasAttribute(attrName)) {
+        protected String getAttribute(String attrName, boolean mustExist) {
+            if (mustExist && !original.hasAttribute(attrName)) {
                 throw new IllegalArgumentException(_loc.get("attr-missing", this, attrName).toString());
             }
             return original.getAttribute(attrName);
@@ -232,8 +241,6 @@ public interface Actions {
      * 
      */
     public static class RenameNode extends Abstract {
-        private String sourceName;
-        private final String targetName;
 
         public RenameNode(Element node) {
             super(Code.RENAME_NODE, node);
@@ -254,13 +261,10 @@ public interface Actions {
     }
 
     public static class RenameChildNode extends Abstract {
-        private final String sourceName;
-        private final String targetName;
         private List<String> _ignores = new ArrayList<String>();
 
         public RenameChildNode(Element s) {
             super(Code.RENAME_CHILD_NODE, s);
-            sourceName = getAttribute(FROM);
             targetName = getAttribute(TO, sourceName);
 
             NodeList values = s.getElementsByTagName("ignore-attr");
@@ -294,14 +298,10 @@ public interface Actions {
     }
 
     public static class RenameAttr extends Abstract {
-        String sourceName;
-        String targetName;
         private Map<String, String> _valueMap = new HashMap<String, String>();
 
         public RenameAttr(Element e) {
             super(Code.RENAME_ATTR, e);
-            sourceName = e.getAttribute(FROM);
-            targetName = e.getAttribute(TO);
 
             NodeList values = e.getElementsByTagName("map-value");
             int M = values.getLength();
@@ -345,12 +345,9 @@ public interface Actions {
     /**
      * An attribute in the source element becomes a sub-element in the target document.
      * 
-     * @author Pinaki Poddar
      * 
      */
     public static class PromoteAttr extends Abstract {
-        String sourceName;
-        String targetName;
         String targetAttrName;
         String valueCondition;
         Map<String, String> borrow = new HashMap<String, String>();
@@ -358,8 +355,6 @@ public interface Actions {
 
         public PromoteAttr(Element e) {
             super(Code.PROMOTE_ATTR, e);
-            sourceName = e.getAttribute(FROM);
-            targetName = e.getAttribute(TO);
             targetAttrName = e.getAttribute("as");
             valueCondition = e.getAttribute("if");
 
@@ -394,7 +389,6 @@ public interface Actions {
                     for (Map.Entry<String, String> entry : borrow.entrySet()) {
                         String borrowedAttrName = entry.getKey();
                         if (source.hasAttribute(borrowedAttrName)) {
-                            logger.trace(_loc.get("attr-consume", this, borrowedAttrName));
                             consumedAttrs.add(borrowedAttrName);
                             String borrowedAttrValue = source.getAttribute(borrowedAttrName);
                             Map<String,String> mappedValues = _valueMap.get(sourceName);
@@ -402,6 +396,8 @@ public interface Actions {
                             String targetAttrValue = hasMappedValue ? mappedValues.get(borrowedAttrValue) 
                                 : borrowedAttrValue;
                             newElement.setAttribute(entry.getValue(), targetAttrValue);
+                            logger.trace(_loc.get("attr-consumed", this, borrowedAttrName+"="+borrowedAttrValue,
+                                entry.getValue()+"="+targetAttrValue));
                         }
                     }
                 }
@@ -476,15 +472,11 @@ public interface Actions {
      * 
      */
     public static class SplitNode extends Abstract {
-        String sourceName;
-        String targetName;
         String sourceAttrName;
         String targetAttrName;
 
         public SplitNode(Element e) {
             super(Code.SPLIT_NODE, e);
-            sourceName = e.getAttribute(FROM);
-            targetName = e.getAttribute(TO);
             sourceAttrName = e.getAttribute("on");
             targetAttrName = getAttribute("as", sourceAttrName);
         }

Modified: openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/localizer.properties?rev=1022319&r1=1022318&r2=1022319&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/localizer.properties (original)
+++ openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/localizer.properties Wed Oct 13 23:11:10 2010
@@ -33,9 +33,9 @@ element-ignored: Ignored child element "
 rename-node: renaming element "{1}" to element "{2}" [Action <{0}>]
 rename-child-node: renaming child element "{1}" to element "{2}" [Action <{0}>]
 
-attr-ignored: ignored attribute "{1}" in element "{2}"
 attr-skipped: Attribute "{0}" is skipped by all actions
 attr-missing: Action <{0}> requires that a value must be specified for attribute "{1}".
 attr-missing-def: Action <{0}> requires that attribute "{1}" must have a value or a non-null default value.
-
+attr-ignored: ignored attribute "{1}" in element "{2}" [Action <{0}>]
+attr-consumed: consumed attribute "{1}" as "{2}"  [Action <{0}>]
  
\ No newline at end of file

Modified: openjpa/tools/trunk/openjpa-tools/src/test/java/org/apache/openjpa/tools/TestMigratedOutput.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/test/java/org/apache/openjpa/tools/TestMigratedOutput.java?rev=1022319&r1=1022318&r2=1022319&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/test/java/org/apache/openjpa/tools/TestMigratedOutput.java (original)
+++ openjpa/tools/trunk/openjpa-tools/src/test/java/org/apache/openjpa/tools/TestMigratedOutput.java Wed Oct 13 23:11:10 2010
@@ -74,7 +74,7 @@ public class TestMigratedOutput extends 
     void migrateAndValidate(String dir, String type) {
         String input  = type + ".hbm.xml";
         String output = type + ".orm.xml";
-        String[] args = {"-input", input, "-output", dir + output};
+        String[] args = {"-input", input, "-output", dir + output, "-verbose", ""+Boolean.getBoolean("verbose")};
         System.err.println("Input  Descriptor [" + input + "]");
         System.err.println("Output Descriptor [" + output + "]");
         SchemaErrorDetector parserError = new SchemaErrorDetector(output, false);

Modified: openjpa/tools/trunk/openjpa-tools/src/test/resources/sample.hbm.xml
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/test/resources/sample.hbm.xml?rev=1022319&r1=1022318&r2=1022319&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/test/resources/sample.hbm.xml (original)
+++ openjpa/tools/trunk/openjpa-tools/src/test/resources/sample.hbm.xml Wed Oct 13 23:11:10 2010
@@ -32,6 +32,7 @@
 		<id name="id" type="java.lang.Long" column="ID">
 			<generator class="native" />
 		</id>
+        <property name="value" column="VALUE" type="text"/>
 		<property name="envId" type="com.approuter.common.hibernate.GuidUserType"
 			length="64" unique-key="env_name_version">
 			<column name="ENV_ID" index="IDX_PROJECT_ENV" />