commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1069107 - in /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3: CallMethodRule.java RulesBinderImpl.java rulesbinder/CallMethodBuilder.java
Date Wed, 09 Feb 2011 21:10:20 GMT
Author: simonetripodi
Date: Wed Feb  9 21:10:19 2011
New Revision: 1069107

URL: http://svn.apache.org/viewvc?rev=1069107&view=rev
Log:
added a method to define callMethod() argument types by a string array
changed the rules binder initialization to a synchronized lazy loading, so it can use the
classloader to resolve the types

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/CallMethodRule.java
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/CallMethodBuilder.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/CallMethodRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/CallMethodRule.java?rev=1069107&r1=1069106&r2=1069107&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/CallMethodRule.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/CallMethodRule.java
Wed Feb  9 21:10:19 2011
@@ -175,7 +175,7 @@ public class CallMethodRule extends Rule
      */
     @Override
     public void body(String namespace, String name, String text) throws Exception {
-        if (this.paramTypes.length == 0) {
+        if (this.paramTypes.length == 1) {
             this.bodyText = text.trim();
         }
     }

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java?rev=1069107&r1=1069106&r2=1069107&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java
Wed Feb  9 21:10:19 2011
@@ -18,6 +18,7 @@
 package org.apache.commons.digester3;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -57,6 +58,12 @@ final class RulesBinderImpl implements R
      */
     private final Collection<RegisteredProvider> providers = new ArrayList<RegisteredProvider>();
 
+    private final ClassLoader classLoader;
+
+    public RulesBinderImpl(final ClassLoader classLoader) {
+        this.classLoader = classLoader;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -661,8 +668,31 @@ final class RulesBinderImpl implements R
                         return this;
                     }
 
+                    public CallMethodBuilder withParamTypes(String... paramTypeNames) {
+                        if (paramTypeNames != null) {
+                            this.paramTypes = new Class[paramTypeNames.length];
+                            for (int i = 0; i < paramTypeNames.length; i++) {
+                                try {
+                                    this.paramTypes[i] = classLoader.loadClass(paramTypeNames[i]);
+                                } catch (ClassNotFoundException e) {
+                                    // use the digester log
+                                    addError("{forPattern(\"%s\").callMethod().withParamTypes(%s)}
class %s cannot be load",
+                                            keyPattern,
+                                            Arrays.toString(paramTypeNames),
+                                            paramTypeNames[i]);
+                                }
+                            }
+                        }
+                        return this;
+                    }
+
                     public CallMethodBuilder withParamTypes(/* @Nullable */Class<?>...
paramTypes) {
                         this.paramTypes = paramTypes;
+
+                        if (paramTypes != null) {
+                            this.paramCount = paramTypes.length;
+                        }
+
                         return this;
                     }
 

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/CallMethodBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/CallMethodBuilder.java?rev=1069107&r1=1069106&r2=1069107&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/CallMethodBuilder.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/rulesbinder/CallMethodBuilder.java
Wed Feb  9 21:10:19 2011
@@ -36,6 +36,17 @@ public interface CallMethodBuilder exten
     CallMethodBuilder withTargetOffset(int targetOffset);
 
     /**
+     * Sets the Java classe names that represent the parameter types of the method arguments.
+     *
+     * If you wish to use a primitive type, specify the corresonding Java wrapper class instead,
+     * such as {@code java.lang.Boolean.TYPE} for a {@code boolean} parameter.
+     *
+     * @param The Java classe names that represent the parameter types of the method arguments
+     * @return this builder instance
+     */
+    CallMethodBuilder withParamTypes(String...paramTypeNames);
+
+    /**
      * Sets the Java classes that represent the parameter types of the method arguments.
      *
      * If you wish to use a primitive type, specify the corresonding Java wrapper class instead,



Mime
View raw message