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 2010/01/13 23:50:13 UTC
svn commit: r898988 -
/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/handlers/MethodHandler.java
Author: simonetripodi
Date: Wed Jan 13 22:50:13 2010
New Revision: 898988
URL: http://svn.apache.org/viewvc?rev=898988&view=rev
Log:
fixed pattern retrieving for SetNext/SetRoot rule
Modified:
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/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=898988&r1=898987&r2=898988&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 13 22:50:13 2010
@@ -17,9 +17,12 @@
package org.apache.commons.digester.annotations.handlers;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import org.apache.commons.digester.Rule;
+import org.apache.commons.digester.annotations.AnnotationRuleProvider;
import org.apache.commons.digester.annotations.CreationRule;
import org.apache.commons.digester.annotations.DigesterLoader;
import org.apache.commons.digester.annotations.DigesterLoaderHandler;
@@ -43,11 +46,6 @@
private static final int SUPPORTED_ARGS = 1;
/**
- *
- */
- private DefaultLoaderHandler defaultLoaderHandler = new DefaultLoaderHandler();
-
- /**
* {@inheritDoc}
*/
public void handle(Annotation annotation, Method element, FromAnnotationsRuleSet ruleSet) {
@@ -84,10 +82,10 @@
+ paramType.getName());
}
- this.doHandle(element, explicitType, ruleSet);
+ this.doHandle(annotation, element, explicitType, ruleSet);
}
} else {
- this.doHandle(element, paramType, ruleSet);
+ this.doHandle(annotation, element, paramType, ruleSet);
}
}
@@ -98,14 +96,14 @@
* @param type
* @param ruleSet
*/
- private void doHandle(Method method, Class<?> type, FromAnnotationsRuleSet ruleSet) {
+ private void doHandle(Annotation methodAnnotation, Method method, Class<?> type, FromAnnotationsRuleSet ruleSet) {
if (type.isInterface()
&& Modifier.isAbstract(type.getModifiers())) {
throw new IllegalArgumentException("");
}
for (Annotation annotation : type.getAnnotations()) {
- this.doHandle(annotation, method, type, ruleSet);
+ this.doHandle(methodAnnotation, annotation, method, type, ruleSet);
}
}
@@ -117,11 +115,23 @@
* @param type
* @param ruleSet
*/
- private void doHandle(Annotation annotation, Method method, Class<?> type, FromAnnotationsRuleSet ruleSet) {
+ @SuppressWarnings("unchecked")
+ private void doHandle(Annotation methodAnnotation, Annotation annotation, Method method, Class<?> type, FromAnnotationsRuleSet ruleSet) {
if (annotation.annotationType().isAnnotationPresent(DigesterRule.class)
&& annotation.annotationType().isAnnotationPresent(CreationRule.class)) {
DigesterLoader.addRules(type, ruleSet);
- this.defaultLoaderHandler.handle(annotation, method, ruleSet);
+
+ DigesterRule digesterRule = methodAnnotation.annotationType().getAnnotation(DigesterRule.class);
+ try {
+ AnnotationRuleProvider<Annotation, AnnotatedElement, Rule> ruleProvider =
+ (AnnotationRuleProvider<Annotation, AnnotatedElement, Rule>) digesterRule.providedBy().newInstance();
+ ruleProvider.init(annotation, method);
+ ruleSet.addRuleProvider(AnnotationUtils.getAnnotationPattern(annotation), ruleProvider);
+ } catch (Throwable t) {
+ throw new RuntimeException("Impossible to instantiate provider of type '"
+ + digesterRule.providedBy().getName()
+ + "', see nested exceptions", t);
+ }
} else if (annotation.annotationType().isAnnotationPresent(DigesterRuleList.class)) {
// check if it is one of the *.List annotation
Annotation[] annotations = AnnotationUtils.getAnnotationsArrayValue(annotation);