[jboss-cvs] JBossAS SVN: r62447 - projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 20 15:15:05 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-04-20 15:15:05 -0400 (Fri, 20 Apr 2007)
New Revision: 62447
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Arg.java
Log:
[JBAOP-381] Refactoring to allow the implementation of rule Thrown -> Return
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java 2007-04-20 18:39:10 UTC (rev 62446)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java 2007-04-20 19:15:05 UTC (rev 62447)
@@ -56,19 +56,19 @@
*/
public static final AdviceMethodFactory BEFORE = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT},
- ReturnType.VOID);
+ ReturnType.VOID, null);
/**
* Factory that selects advice methods for <i>after</i> interception.
*/
public static final AdviceMethodFactory AFTER = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
- ParameterAnnotationRule.RETURN}, ReturnType.ANY);
+ ParameterAnnotationRule.RETURN}, ReturnType.ANY, null);
/**
* Factory that selects advice methods for <i>throwing</i> interception.
*/
public static final AdviceMethodFactory THROWING = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
- ParameterAnnotationRule.THROWABLE}, ReturnType.VOID);
+ ParameterAnnotationRule.THROWABLE}, ReturnType.VOID, null);
/**
* Factory that selects advice methods for <i>aroung</i> interception.
*/
@@ -163,7 +163,7 @@
}
},
new ParameterAnnotationRule[]{ParameterAnnotationRule.INVOCATION},
- ReturnType.NOT_VOID);
+ ReturnType.NOT_VOID, null);
static final short NOT_ASSIGNABLE_DEGREE = Short.MAX_VALUE;
@@ -210,6 +210,7 @@
private ReturnType returnType;
private AdviceSignatureRule adviceSignatureRule;
private ParameterAnnotationRule[] rules;
+ private int[][] implication;
/**
@@ -223,13 +224,14 @@
* a value to overwrite the join point execution result.
*/
private AdviceMethodFactory(AdviceSignatureRule adviceSignatureRule,
- ParameterAnnotationRule[] rules, ReturnType returnType)
+ ParameterAnnotationRule[] rules, ReturnType returnType, int[][] implication)
{
this.adviceSignatureRule = adviceSignatureRule;
this.rules = rules;
this.returnType = returnType;
this.adviceInfoCache = new HashMap
<String, WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>>>();
+ this.implication = implication;
}
/**
@@ -376,7 +378,8 @@
{
// advice applies to annotated parameter rules
rankedAdvices.add(new AnnotatedParameterAdviceInfo(properties,
- methods[i], rules, contextRules, mutuallyExclusive));
+ methods[i], rules, contextRules, mutuallyExclusive,
+ implication));
}catch (ParameterAnnotationRuleException pare)
{
// no need to print messages ->
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2007-04-20 18:39:10 UTC (rev 62446)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2007-04-20 19:15:05 UTC (rev 62447)
@@ -22,6 +22,8 @@
// muttually exclusive context parameter rules
private int[][] mutuallyExclusive;
+ private int[][] implication;
+
/**
* Creates an annotated parameter advice info.
*
@@ -38,13 +40,15 @@
*/
public AnnotatedParameterAdviceInfo(AdviceMethodProperties properties,
Method method, ParameterAnnotationRule[] rules,
- ParameterAnnotationRule[] contextRules, int[][] mutuallyExclusive)
+ ParameterAnnotationRule[] contextRules, int[][] mutuallyExclusive,
+ int[][] implication)
throws ParameterAnnotationRuleException
{
super(method, 0);
this.paramTypes = createParameterAnnotationTypes(rules);
this.contextParamTypes = createParameterAnnotationTypes(contextRules);
this.mutuallyExclusive = mutuallyExclusive;
+ this.implication = implication;
this.applyRules(properties);
}
@@ -114,6 +118,31 @@
}
}
}
+
+ if (implication != null)
+ {
+ for (int i = 0; i < implication.length; i++)
+ {
+ ParameterAnnotationType implicator = paramTypes[implication[i][0]];
+ if (implicator.isSet())
+ {
+ for (int j = 1; j < implication[i].length; j++)
+ {
+ if (!paramTypes[implication[i][j]].isSet())
+ {
+ if (AspectManager.verbose)
+ {
+ AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - the use of parameter annotation ");
+ AdviceMethodFactory.adviceMatchingMessage.append(paramTypes[implication[i][0]].rule.getAnnotation());
+ AdviceMethodFactory.adviceMatchingMessage.append(" implies in the mandatory use of parameter annotation ");
+ AdviceMethodFactory.adviceMatchingMessage.append(paramTypes[implication[i][j]].rule.getAnnotation());
+ }
+ return false;
+ }
+ }
+ }
+ }
+ }
return true;
}
@@ -311,17 +340,6 @@
}
/**
- * Indicates whether <code>parameterAnnotation</code> is of this type.
- *
- * @param parameterAnnotation the parameter annotation
- * @return <code>true</code> if parameter annotation is of this type
- */
- public final boolean applies(Annotation parameterAnnotation)
- {
- return parameterAnnotation.annotationType() == rule.getAnnotation();
- }
-
- /**
* Verifies if <code>parameterAnnotation</code> is of this type, and, if it is,
* sets the parameter index information.
*
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Arg.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Arg.java 2007-04-20 18:39:10 UTC (rev 62446)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Arg.java 2007-04-20 19:15:05 UTC (rev 62447)
@@ -30,6 +30,25 @@
* Use this annotation on advice parameters that should contain values of
* advised joinpoint arguments.
*
+ * What are the arguments of a joinpoint depends on the type of the joinpoint itself.
+ * For instance, if the intercepted joinpoint is a method execution, its arguments
+ * are the method arguments.
+ *
+ * If the optional <code>index</code> attribute is not defined, JBoss AOP will match
+ * the <code>@Arg</code> annotated parameter with the joinpoint argument closest with
+ * the closest type.
+ *
+ * Look at the following example:
+ *
+ * <code>
+ * </code>
+ *
+ * In this scenario, JBoss AOP will match
+ *
+ * To learn how JBoss AOP will match Arg annotated parameters with joinpoint
+ * arguments in more complex scenarios, please, refer to the Reference Manual
+ * documentation.
+ *
* @author Flavia Rainone
*/
@Target (ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME)
More information about the jboss-cvs-commits
mailing list