commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1074228 - in /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations: handlers/FactoryCreateHandler.java rules/FactoryCreate.java
Date Thu, 24 Feb 2011 17:28:46 GMT
Author: simonetripodi
Date: Thu Feb 24 17:28:46 2011
New Revision: 1074228

URL: http://svn.apache.org/viewvc?rev=1074228&view=rev
Log:
added a default ObjectCreationFactory type in the FactoryCreate annotation as default value

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/handlers/FactoryCreateHandler.java
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/rules/FactoryCreate.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/handlers/FactoryCreateHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/handlers/FactoryCreateHandler.java?rev=1074228&r1=1074227&r2=1074228&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/handlers/FactoryCreateHandler.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/handlers/FactoryCreateHandler.java
Thu Feb 24 17:28:46 2011
@@ -20,6 +20,7 @@ package org.apache.commons.digester3.ann
 import org.apache.commons.digester3.RulesBinder;
 import org.apache.commons.digester3.annotations.AnnotationHandler;
 import org.apache.commons.digester3.annotations.rules.FactoryCreate;
+import org.apache.commons.digester3.rulesbinder.FactoryCreateBuilder;
 
 /**
  * {@link FactoryCreate} handler.
@@ -30,12 +31,15 @@ public final class FactoryCreateHandler 
      * {@inheritDoc}
      */
     public void handle(FactoryCreate annotation, Class<?> element, RulesBinder rulesBinder)
{
-        rulesBinder.forPattern(annotation.pattern())
+        FactoryCreateBuilder builder = rulesBinder.forPattern(annotation.pattern())
             .withNamespaceURI(annotation.namespaceURI())
             .factoryCreate()
                 .overriddenByAttribute(annotation.attributeName().length() > 0 ? annotation.attributeName()
: null)
-                .ignoreCreateExceptions(annotation.ignoreCreateExceptions())
-                .ofType(annotation.factoryClass());
+                .ignoreCreateExceptions(annotation.ignoreCreateExceptions());
+
+        if (FactoryCreate.DefaultObjectCreationFactory.class != annotation.factoryClass())
{
+            builder.ofType(annotation.factoryClass());
+        }
     }
 
 }

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/rules/FactoryCreate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/rules/FactoryCreate.java?rev=1074228&r1=1074227&r2=1074228&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/rules/FactoryCreate.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/annotations/rules/FactoryCreate.java
Thu Feb 24 17:28:46 2011
@@ -26,8 +26,10 @@ import java.lang.annotation.Target;
 import org.apache.commons.digester3.annotations.DigesterRule;
 import org.apache.commons.digester3.annotations.DigesterRuleList;
 import org.apache.commons.digester3.annotations.handlers.FactoryCreateHandler;
+import org.apache.commons.digester3.rule.AbstractObjectCreationFactory;
 import org.apache.commons.digester3.rule.FactoryCreateRule;
 import org.apache.commons.digester3.spi.ObjectCreationFactory;
+import org.xml.sax.Attributes;
 
 /**
  * Classes annotated with {@code FactoryCreate} will be bound with
@@ -48,7 +50,7 @@ public @interface FactoryCreate {
      *
      * @return the Java class of the object creation factory class
      */
-    Class<? extends ObjectCreationFactory<?>> factoryClass();
+    Class<? extends ObjectCreationFactory<?>> factoryClass() default DefaultObjectCreationFactory.class;
 
     /**
      * Allows specify the attribute containing an override class name if it is present.
@@ -92,4 +94,20 @@ public @interface FactoryCreate {
         FactoryCreate[] value();
     }
 
+    /**
+     * Dummy ObjectCreationFactory type only for annotation value type purposes.
+     */
+    public static final class DefaultObjectCreationFactory extends AbstractObjectCreationFactory<Object>
{
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Object createObject(Attributes attributes) throws Exception {
+            // do nothing
+            return null;
+        }
+
+    }
+
 }



Mime
View raw message