You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/01/31 22:29:49 UTC

svn commit: r1065803 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/RulesBinderImpl.java

Author: simonetripodi
Date: Mon Jan 31 21:29:49 2011
New Revision: 1065803

URL: http://svn.apache.org/viewvc?rev=1065803&view=rev
Log:
added a method to apply the namespaceURI to generated rules

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

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=1065803&r1=1065802&r2=1065803&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 Mon Jan 31 21:29:49 2011
@@ -165,7 +165,8 @@ final class RulesBinderImpl implements R
                     }
 
                     public SetTopRule get() {
-                        return new SetTopRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch());
+                        return setNamespaceAndReturn(
+                                new SetTopRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch()));
                     }
 
                 });
@@ -187,7 +188,8 @@ final class RulesBinderImpl implements R
                     }
 
                     public SetRootRule get() {
-                        return new SetRootRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch());
+                        return setNamespaceAndReturn(
+                                new SetRootRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch()));
                     }
 
                 });
@@ -208,7 +210,7 @@ final class RulesBinderImpl implements R
                     private boolean ignoreMissingProperty = true;
 
                     public SetPropertiesRule get() {
-                        return new SetPropertiesRule(this.aliases, this.ignoreMissingProperty);
+                        return setNamespaceAndReturn(new SetPropertiesRule(this.aliases, this.ignoreMissingProperty));
                     }
 
                     public LinkedRuleBuilder then() {
@@ -249,7 +251,8 @@ final class RulesBinderImpl implements R
                     }
 
                     public SetNextRule get() {
-                        return new SetNextRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch());
+                        return setNamespaceAndReturn(
+                                new SetNextRule(this.getMethodName(), this.getParamType(), this.isUseExactMatch()));
                     }
 
                 });
@@ -268,7 +271,8 @@ final class RulesBinderImpl implements R
                     private boolean allowUnknownChildElements = false;
 
                     public SetNestedPropertiesRule get() {
-                        return new SetNestedPropertiesRule(elementNames, trimData, allowUnknownChildElements);
+                        return setNamespaceAndReturn(
+                                new SetNestedPropertiesRule(elementNames, trimData, allowUnknownChildElements));
                     }
 
                     public LinkedRuleBuilder then() {
@@ -302,7 +306,7 @@ final class RulesBinderImpl implements R
                     private String propertyName;
 
                     public BeanPropertySetterRule get() {
-                        return new BeanPropertySetterRule(this.propertyName);
+                        return setNamespaceAndReturn(new BeanPropertySetterRule(this.propertyName));
                     }
 
                     public LinkedRuleBuilder then() {
@@ -342,9 +346,7 @@ final class RulesBinderImpl implements R
                             return null;
                         }
 
-                        ObjectCreateRule rule = new ObjectCreateRule(this.className, this.attributeName);
-                        rule.setNamespaceURI(namespaceURI);
-                        return rule;
+                        return setNamespaceAndReturn(new ObjectCreateRule(this.className, this.attributeName));
                     }
 
                     public LinkedRuleBuilder then() {
@@ -418,9 +420,7 @@ final class RulesBinderImpl implements R
                     }
 
                     public R get() {
-                        R rule = provider.get();
-                        rule.setNamespaceURI(namespaceURI);
-                        return rule;
+                        return setNamespaceAndReturn(provider.get());
                     }
 
                 });
@@ -448,6 +448,18 @@ final class RulesBinderImpl implements R
                 return provider;
             }
 
+            /**
+             * Set the namespaceURI to the given rule and return it.
+             *
+             * @param <R> The rule type to apply the namespaceURI
+             * @param rule The rule to apply the namespaceURI
+             * @return  The rule type to apply the namespaceURI
+             */
+            private <R extends Rule> R setNamespaceAndReturn(R rule) {
+                rule.setNamespaceURI(namespaceURI);
+                return rule;
+            }
+
         };
     }