commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1209995 - in /commons/proper/digester/trunk/src: main/java/org/apache/commons/digester3/binder/ main/java/org/apache/commons/digester3/xmlrules/ main/resources/org/apache/commons/digester3/xmlrules/ site/resources/dtds/ test/java/org/apach...
Date Sat, 03 Dec 2011 20:23:26 GMT
Author: simonetripodi
Date: Sat Dec  3 20:23:25 2011
New Revision: 1209995

URL: http://svn.apache.org/viewvc?rev=1209995&view=rev
Log:
restored ObjectCreateRule constructor via meta XML declaration

Removed:
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectParamRule.java
Modified:
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectCreateRule.java
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/XmlRulesModule.java
    commons/proper/digester/trunk/src/main/resources/org/apache/commons/digester3/xmlrules/digester-rules.dtd
    commons/proper/digester/trunk/src/site/resources/dtds/digester-rules-3.0.dtd
    commons/proper/digester/trunk/src/test/java/org/apache/commons/digester3/Digester153TestCase.java
    commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml

Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
(original)
+++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
Sat Dec  3 20:23:25 2011
@@ -19,6 +19,10 @@ package org.apache.commons.digester3.bin
  * under the License.
  */
 
+import static java.lang.String.format;
+
+import java.util.Arrays;
+
 import org.apache.commons.digester3.ObjectCreateRule;
 
 /**
@@ -112,6 +116,40 @@ public final class ObjectCreateBuilder
      * @return
      * @since 3.2
      */
+    public ObjectCreateBuilder usingConstructor( String...paramTypeNames )
+    {
+        if ( paramTypeNames == null )
+        {
+            reportError( "createObject().usingConstructor( String[] )", "NULL parametersTypes
not allowed" );
+        }
+
+        Class<?>[] paramTypes = null;
+        if ( paramTypeNames != null )
+        {
+            paramTypes = new Class<?>[paramTypeNames.length];
+            for ( int i = 0; i < paramTypeNames.length; i++ )
+            {
+                try
+                {
+                    paramTypes[i] = classLoader.loadClass( paramTypeNames[i] );
+                }
+                catch ( ClassNotFoundException e )
+                {
+                    this.reportError( format( "createObject().usingConstructor( %s )",
+                                              Arrays.toString( paramTypeNames ) ),
+                                      format( "class '%s' cannot be load", paramTypeNames[i]
) );
+                }
+            }
+        }
+
+        return usingConstructor( paramTypes );
+    }
+
+    /**
+     *
+     * @return
+     * @since 3.2
+     */
     public ObjectCreateBuilder usingConstructor( Class<?>...constructorArgumentsType
)
     {
         if ( constructorArgumentsType == null )

Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectCreateRule.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectCreateRule.java?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectCreateRule.java
(original)
+++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/ObjectCreateRule.java
Sat Dec  3 20:23:25 2011
@@ -19,6 +19,8 @@ package org.apache.commons.digester3.xml
  * under the License.
  */
 
+import java.util.StringTokenizer;
+
 import org.apache.commons.digester3.binder.LinkedRuleBuilder;
 import org.apache.commons.digester3.binder.ObjectCreateBuilder;
 import org.apache.commons.digester3.binder.RulesBinder;
@@ -46,14 +48,19 @@ final class ObjectCreateRule
         ObjectCreateBuilder builder = linkedRuleBuilder.createObject()
             .ofType( attributes.getValue( "classname" ) )
             .ofTypeSpecifiedByAttribute( attributes.getValue( "attrname" ) );
-        getDigester().push( builder );
-    }
 
-    @Override
-    public void end( String namespace, String name )
-        throws Exception
-    {
-        getDigester().pop();
+        String paramTypesStr = attributes.getValue( "paramtypes" );
+        if ( paramTypesStr != null && paramTypesStr.length() > 0 )
+        {
+            StringTokenizer tokens = new StringTokenizer( paramTypesStr, " \t\n\r," );
+            String[] paramTypeNames = new String[tokens.countTokens()];
+            int counter = 0;
+            while ( tokens.hasMoreTokens() )
+            {
+                paramTypeNames[counter++] = tokens.nextToken();
+            }
+            builder.usingConstructor( paramTypeNames );
+        }
     }
 
 }

Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/XmlRulesModule.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/XmlRulesModule.java?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/XmlRulesModule.java
(original)
+++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/xmlrules/XmlRulesModule.java
Sat Dec  3 20:23:25 2011
@@ -85,7 +85,6 @@ final class XmlRulesModule
 
             forPattern( "*/call-method-rule" ).addRule( new CallMethodRule( targetRulesBinder,
patternStack ) );
             forPattern( "*/call-param-rule" ).addRule( new CallParamRule( targetRulesBinder,
patternStack ) );
-            forPattern( "*/object-param-rule" ).addRule( new ObjectParamRule( targetRulesBinder,
patternStack ) );
 
             forPattern( "*/factory-create-rule" ).addRule( new FactoryCreateRule( targetRulesBinder,
patternStack ) );
             forPattern( "*/node-create-rule" ).addRule( new NodeCreateRule( targetRulesBinder,
patternStack ) );

Modified: commons/proper/digester/trunk/src/main/resources/org/apache/commons/digester3/xmlrules/digester-rules.dtd
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/resources/org/apache/commons/digester3/xmlrules/digester-rules.dtd?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/resources/org/apache/commons/digester3/xmlrules/digester-rules.dtd
(original)
+++ commons/proper/digester/trunk/src/main/resources/org/apache/commons/digester3/xmlrules/digester-rules.dtd
Sat Dec  3 20:23:25 2011
@@ -185,15 +185,12 @@
     ignore-exceptions  CDATA #IMPLIED>
 
 <!-- ObjectCreateRule -->
-<!ELEMENT object-create-rule (constructor-argument)*>
+<!ELEMENT object-create-rule EMPTY>
 <!ATTLIST object-create-rule
-    pattern   CDATA #IMPLIED
-    classname CDATA #REQUIRED
-    attrname  CDATA #IMPLIED>
-<!ELEMENT constructor-argument EMPTY>
-<!ATTLIST constructor-argument
-    attrname  CDATA #IMPLIED
-    type      CDATA #REQUIRED>
+    pattern    CDATA #IMPLIED
+    classname  CDATA #REQUIRED
+    attrname   CDATA #IMPLIED
+    paramtypes CDATA #IMPLIED>
 
 <!-- SetPropertiesRule -->
 <!ELEMENT set-properties-rule (alias)*>

Modified: commons/proper/digester/trunk/src/site/resources/dtds/digester-rules-3.0.dtd
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/site/resources/dtds/digester-rules-3.0.dtd?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/site/resources/dtds/digester-rules-3.0.dtd (original)
+++ commons/proper/digester/trunk/src/site/resources/dtds/digester-rules-3.0.dtd Sat Dec 
3 20:23:25 2011
@@ -185,15 +185,12 @@
     ignore-exceptions  CDATA #IMPLIED>
 
 <!-- ObjectCreateRule -->
-<!ELEMENT object-create-rule (constructor-argument)*>
+<!ELEMENT object-create-rule EMPTY>
 <!ATTLIST object-create-rule
-    pattern   CDATA #IMPLIED
-    classname CDATA #REQUIRED
-    attrname  CDATA #IMPLIED>
-<!ELEMENT constructor-argument EMPTY>
-<!ATTLIST constructor-argument
-    attrname  CDATA #IMPLIED
-    type      CDATA #REQUIRED>
+    pattern    CDATA #IMPLIED
+    classname  CDATA #REQUIRED
+    attrname   CDATA #IMPLIED
+    paramtypes CDATA #IMPLIED>
 
 <!-- SetPropertiesRule -->
 <!ELEMENT set-properties-rule (alias)*>

Modified: commons/proper/digester/trunk/src/test/java/org/apache/commons/digester3/Digester153TestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/java/org/apache/commons/digester3/Digester153TestCase.java?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/test/java/org/apache/commons/digester3/Digester153TestCase.java
(original)
+++ commons/proper/digester/trunk/src/test/java/org/apache/commons/digester3/Digester153TestCase.java
Sat Dec  3 20:23:25 2011
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTru
 import org.apache.commons.digester3.annotations.FromAnnotationsRuleModule;
 import org.apache.commons.digester3.binder.AbstractRulesModule;
 import org.apache.commons.digester3.binder.RulesModule;
+import org.apache.commons.digester3.xmlrules.FromXmlRulesModule;
 import org.junit.Test;
 
 /**
@@ -122,7 +123,7 @@ public final class Digester153TestCase
         } );
     }
 
-    /* @Test
+    @Test
     public void basicConstructorViaXML()
         throws Exception
     {
@@ -136,7 +137,7 @@ public final class Digester153TestCase
             }
 
         } );
-    } */
+    }
 
     private void succesfullConstructor( RulesModule rulesModule )
         throws Exception

Modified: commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml?rev=1209995&r1=1209994&r2=1209995&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
(original)
+++ commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
Sat Dec  3 20:23:25 2011
@@ -18,9 +18,9 @@
 -->
 <digester-rules>
   <pattern value="toplevel/bean">
-    <object-create-rule classname="org.apache.commons.digester3.TestBean">
-      <constructor-argument attrname="boolean" type="java.lang.Boolean" />
-      <constructor-argument attrname="double" type="java.lang.Double" />
-    </object-create-rule>
+    <object-create-rule classname="org.apache.commons.digester3.TestBean"
+      paramtypes="java.lang.Boolean,java.lang.Double" />
+    <call-param-rule paramnumber="0" attrname="boolean" />
+    <call-param-rule paramnumber="1" attrname="double" />
   </pattern>
 </digester-rules>



Mime
View raw message