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/02/09 22:47:09 UTC

svn commit: r1069128 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java

Author: simonetripodi
Date: Wed Feb  9 21:47:09 2011
New Revision: 1069128

URL: http://svn.apache.org/viewvc?rev=1069128&view=rev
Log:
missed from previous commit:
moved the String type resolution of ObjectCreationRule to binding time rather then execution time

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

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java?rev=1069128&r1=1069127&r2=1069128&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java (original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java Wed Feb  9 21:47:09 2011
@@ -29,7 +29,7 @@ public class ObjectCreateRule extends Ru
     /**
      * The Java class name of the object to be created.
      */
-    private final String className;
+    private final Class<?> type;
 
     /**
      * The attribute containing an override class name if it is present.
@@ -42,8 +42,8 @@ public class ObjectCreateRule extends Ru
      * @param className The Java class name of the object to be created
      * @param attributeName The attribute containing an override class name if it is present
      */
-    public ObjectCreateRule(String className, String attributeName) {
-        this.className = className;
+    public ObjectCreateRule(Class<?> type, String attributeName) {
+        this.type = type;
         this.attributeName = attributeName;
     }
 
@@ -53,21 +53,25 @@ public class ObjectCreateRule extends Ru
     @Override
     public void begin(String namespace, String name, Attributes attributes) throws Exception {
         // Identify the name of the class to instantiate
-        String realClassName = this.className;
+        Class<?> clazz = this.type;
         if (this.attributeName != null) {
             String value = attributes.getValue(this.attributeName);
             if (value != null) {
-                realClassName = value;
+                clazz = this.getDigester().getClassLoader().loadClass(value);
             }
         }
         if (this.getDigester().getLog().isDebugEnabled()) {
             this.getDigester().getLog().debug(String.format("[ObjectCreateRule]{%s} New %s",
                     this.getDigester().getMatch(),
-                    realClassName));
+                    clazz.getName()));
+        }
+
+        if (clazz == null) {
+            throw this.getDigester().createSAXException(String.format("[ObjectCreateRule]{%s} No type defined",
+                    this.getDigester().getMatch()));
         }
 
         // Instantiate the new object and push it on the context stack
-        Class<?> clazz = this.getDigester().getClassLoader().loadClass(realClassName);
         Object instance = clazz.newInstance();
         this.getDigester().push(instance);
     }
@@ -91,7 +95,7 @@ public class ObjectCreateRule extends Ru
      */
     @Override
     public String toString() {
-        return String.format("ObjectCreateRule[className=%s, attributeName=%s]", this.className, this.attributeName);
+        return String.format("ObjectCreateRule[className=%s, attributeName=%s]", this.type.getClasses(), this.attributeName);
     }
 
 }