commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r903570 - in /commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations: FromAnnotationsRuleSet.java handlers/DefaultLoaderHandler.java handlers/MethodHandler.java utils/AnnotationRuleProviderUtils.java
Date Wed, 27 Jan 2010 08:58:45 GMT
Author: simonetripodi
Date: Wed Jan 27 08:58:44 2010
New Revision: 903570

URL: http://svn.apache.org/viewvc?rev=903570&view=rev
Log:
moved the AnnotationRuleProviderUtils code to the FromAnnotationsRuleSet
removed the useless class AnnotationRuleProviderUtils

Removed:
    commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/AnnotationRuleProviderUtils.java
Modified:
    commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/FromAnnotationsRuleSet.java
    commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/DefaultLoaderHandler.java
    commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java

Modified: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/FromAnnotationsRuleSet.java
URL: http://svn.apache.org/viewvc/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/FromAnnotationsRuleSet.java?rev=903570&r1=903569&r2=903570&view=diff
==============================================================================
--- commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/FromAnnotationsRuleSet.java
(original)
+++ commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/FromAnnotationsRuleSet.java
Wed Jan 27 08:58:44 2010
@@ -26,6 +26,7 @@
 import java.util.Set;
 import java.util.Map.Entry;
 
+import org.apache.commons.beanutils.ConstructorUtils;
 import org.apache.commons.digester.Digester;
 import org.apache.commons.digester.Rule;
 import org.apache.commons.digester.RuleSet;
@@ -75,6 +76,35 @@
     }
 
     /**
+     * Builds and register an {@link AnnotationRuleProvider} for a specific
+     * pattern.
+     *
+     * @param <T> the {@link AnnotationRuleProvider} type.
+     * @param pattern the pattern has to be associated to the rule provider.
+     * @param klass the {@link AnnotationRuleProvider} type has to be instantiated.
+     * @param annotation the current visited annotation.
+     * @param element the current visited element.
+     */
+    public <T extends AnnotationRuleProvider<? extends Annotation, ? extends AnnotatedElement,
? extends Rule>> void addRuleProvider(String pattern,
+            Class<T> klass,
+            Annotation annotation,
+            AnnotatedElement element) {
+        Object[] args = new Object[] { annotation, element };
+        Class<?>[] parameterTypes = new Class<?>[] { annotation.annotationType(),
element.getClass() };
+
+        try {
+            Object o = ConstructorUtils.invokeExactConstructor(klass,
+                    args,
+                    parameterTypes);
+            this.addRuleProvider(pattern, klass.cast(o));
+        } catch (Throwable t) {
+            throw new DigesterLoadingException("Impossible to instantiate provider of type
'"
+                    + klass.getName()
+                    + "', see nested exceptions", t);
+        }
+    }
+
+    /**
      * Register an {@link AnnotationRuleProvider} for a specific pattern.
      *
      * @param pattern the pattern has to be associated to the rule provider.

Modified: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/DefaultLoaderHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/DefaultLoaderHandler.java?rev=903570&r1=903569&r2=903570&view=diff
==============================================================================
--- commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/DefaultLoaderHandler.java
(original)
+++ commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/DefaultLoaderHandler.java
Wed Jan 27 08:58:44 2010
@@ -23,7 +23,6 @@
 import org.apache.commons.digester.annotations.DigesterLoaderHandler;
 import org.apache.commons.digester.annotations.DigesterRule;
 import org.apache.commons.digester.annotations.FromAnnotationsRuleSet;
-import org.apache.commons.digester.annotations.utils.AnnotationRuleProviderUtils;
 import org.apache.commons.digester.annotations.utils.AnnotationUtils;
 
 /**
@@ -41,7 +40,9 @@
     public void handle(Annotation annotation, AnnotatedElement element, FromAnnotationsRuleSet
ruleSet) {
         DigesterRule digesterRule = annotation.annotationType().getAnnotation(DigesterRule.class);
         ruleSet.addRuleProvider(AnnotationUtils.getAnnotationPattern(annotation),
-                AnnotationRuleProviderUtils.newProvider(digesterRule.providedBy(), annotation,
element));
+                digesterRule.providedBy(),
+                annotation,
+                element);
     }
 
 }

Modified: commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java?rev=903570&r1=903569&r2=903570&view=diff
==============================================================================
--- commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java
(original)
+++ commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java
Wed Jan 27 08:58:44 2010
@@ -27,7 +27,6 @@
 import org.apache.commons.digester.annotations.DigesterRule;
 import org.apache.commons.digester.annotations.DigesterRuleList;
 import org.apache.commons.digester.annotations.FromAnnotationsRuleSet;
-import org.apache.commons.digester.annotations.utils.AnnotationRuleProviderUtils;
 import org.apache.commons.digester.annotations.utils.AnnotationUtils;
 
 /**
@@ -113,7 +112,9 @@
             DigesterRule digesterRule = methodAnnotation.annotationType().getAnnotation(DigesterRule.class);
 
             ruleSet.addRuleProvider(AnnotationUtils.getAnnotationPattern(annotation),
-                    AnnotationRuleProviderUtils.newProvider(digesterRule.providedBy(), methodAnnotation,
method));
+                    digesterRule.providedBy(),
+                    methodAnnotation,
+                    method);
         } else if (annotation.annotationType().isAnnotationPresent(DigesterRuleList.class))
{
             // check if it is one of the *.List annotation
             Annotation[] annotations = AnnotationUtils.getAnnotationsArrayValue(annotation);



Mime
View raw message