[jboss-cvs] JBossAS SVN: r62527 - in projects/aop/trunk/aop/src: main/org/jboss/aop/advice/annotation and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 24 19:23:23 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-04-24 19:23:23 -0400 (Tue, 24 Apr 2007)
New Revision: 62527
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/trunk/aop/src/resources/test/beforeafter/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/POJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/SimpleAspect.java
Log:
[JBAOP-381] Fixed implementation + first test
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -219,31 +219,21 @@
factories.add(factory);
}
- public InterceptorFactory deployAdvice(Element element) throws Exception
+ public InterceptorFactory deployAdvice(Element element, AdviceType type) throws Exception
{
String name = element.getAttribute("name");
String aspect = element.getAttribute("aspect");
AspectDefinition def = manager.getAspectDefinition(aspect);
if (def == null) throw new RuntimeException("advice " + name + " cannot find aspect " + aspect);
- String tagName = element.getTagName();
AdviceFactory factory = null;
- if (tagName.equals("advice"))
+ if (type == null)
{
- // default advice type
+ // use default advice type
factory = new AdviceFactory(def, name);
}
else
{
- AdviceType type = null;
- try
- {
- type = Enum.valueOf(AdviceType.class, tagName.toUpperCase());
- }
- catch (IllegalArgumentException e)
- {
- throw new RuntimeException(" cannot find advice tag " + tagName);
- }
factory = new AdviceFactory(def, name, type);
}
@@ -383,9 +373,31 @@
if (stack == null) throw new Exception("there is no <stack> defined for name: " + name);
interceptors.addAll(stack.getInterceptorFactories());
}
- else if (tag2.equals("advice") || tag2.equals("before") || tag2.equals("after") || tag2.equals("throwing"))
+ else
{
- InterceptorFactory factory = deployAdvice(interceptorElement);
+ AdviceType type = null;
+ if (!tag2.equals("advice"))
+ {
+ try
+ {
+ type = Enum.valueOf(AdviceType.class, tag2.toUpperCase());
+ }
+ catch (IllegalArgumentException e)
+ {
+ StringBuffer message = new StringBuffer();
+ message.append("unexpected tag inside binding:");
+ message.append(tag2);
+ message.append("\n should be one of: \'interceptor\', \'interceptor-ref\', \'advice\', \'");
+ for(AdviceType adviceType: AdviceType.values())
+ {
+ message.append(adviceType.getDescription());
+ message.append("\', \'");
+ }
+ message.append("stack-ref\'");
+ throw new RuntimeException(message.toString());
+ }
+ }
+ InterceptorFactory factory = deployAdvice(interceptorElement, type);
interceptors.add(factory);
}
}
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-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -68,13 +68,13 @@
*/
public static final AdviceMethodFactory THROWING = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
- ParameterAnnotationRule.THROWN}, ReturnType.VOID, null);
+ ParameterAnnotationRule.MANDATORY_THROWN}, ReturnType.VOID, null);
/**
* Factory that selects advice methods for <i>finally</i> interception.
*/
public static final AdviceMethodFactory FINALLY = new AdviceMethodFactory (null,
new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
- ParameterAnnotationRule.THROWN, ParameterAnnotationRule.RETURN},
+ ParameterAnnotationRule.OPTIONAL_THROWN, ParameterAnnotationRule.RETURN},
ReturnType.VOID, new int[][]{{2, 1}});
/**
* Factory that selects advice methods for <i>aroung</i> interception.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -76,11 +76,18 @@
/**
* Rule for parameter annotation {@link Thrown}.
*/
- THROWN (
- Thrown.class, Throwable.class, AdviceMethodProperties.THROWABLE_ARG, 50, true,
- true),
+ OPTIONAL_THROWN (
+ Thrown.class, Throwable.class, AdviceMethodProperties.THROWABLE_ARG, 50,
+ false, true),
/**
+ * Rule for parameter annotation {@link Thrown}.
+ */
+ MANDATORY_THROWN (
+ Thrown.class, Throwable.class, AdviceMethodProperties.THROWABLE_ARG, 50,
+ true, true),
+
+ /**
* Rule for parameter annotation {@link Return}.
*/
RETURN (
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -80,7 +80,6 @@
public static final String JOINPOINT_CLASS_PREFIX = "JoinPoint_";
private static final String RETURN_VALUE = "ret";
private static final String THROWABLE = "t";
- private static final String THROWABLE_FOR_FINALLY = "throwableForFinally";
protected static final String ARGUMENTS= "arguments";
private static final String GET_ARGUMENTS= OptimizedBehaviourInvocations.GET_ARGUMENTS + "()";
protected static final CtClass[] EMPTY_CTCLASS_ARRAY = new CtClass[0];
@@ -1352,6 +1351,13 @@
allSetups[i].setAdviceMethodProperties(properties);
aspects[index].add(allSetups[i]);
}
+ else if (AspectManager.verbose)
+ {
+ System.out.print("[warn] No matching advice called '" + allSetups[i].getAdviceName() +
+ "' could be found in " + allSetups[i].getAspectClass().getName() +
+ " for joinpoint " + info + ":");
+ System.out.println(AdviceMethodFactory.getAdviceMatchingMessage());
+ }
}
this.setups = new AdviceSetup[length][];
Modified: projects/aop/trunk/aop/src/resources/test/beforeafter/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafter/jboss-aop.xml 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/resources/test/beforeafter/jboss-aop.xml 2007-04-24 23:23:23 UTC (rev 62527)
@@ -4,12 +4,21 @@
<aspect class="org.jboss.test.aop.beforeafter.ArgsAspect" scope="PER_VM"/>
<aspect class="org.jboss.test.aop.beforeafter.GeneralAspect" scope="PER_VM"/>
- <bind pointcut="execution(* org.jboss.test.aop.beforeafter.POJO->method(boolean))">
+ <stack name="simpleStack">
<before name="before" aspect="org.jboss.test.aop.beforeafter.SimpleAspect"/>
<advice name="around" aspect="org.jboss.test.aop.beforeafter.SimpleAspect"/>
<after name="after" aspect="org.jboss.test.aop.beforeafter.SimpleAspect"/>
<throwing name="throwing" aspect="org.jboss.test.aop.beforeafter.SimpleAspect"/>
+ </stack>
+
+ <bind pointcut="execution(* org.jboss.test.aop.beforeafter.POJO->method1(boolean))">
+ <stack-ref name="simpleStack"/>
</bind>
+
+ <bind pointcut="execution(* org.jboss.test.aop.beforeafter.POJO->method2(boolean))">
+ <stack-ref name="simpleStack"/>
+ <finally name="finallyAdvice" aspect="org.jboss.test.aop.beforeafter.SimpleAspect"/>
+ </bind>
<stack name="argsStack">
<before name="before" aspect="org.jboss.test.aop.beforeafter.ArgsAspect"/>
@@ -18,7 +27,7 @@
<throwing name="throwingzzz" aspect="org.jboss.test.aop.beforeafter.ArgsAspect"/>
</stack>
- <bind pointcut="execution(org.jboss.test.aop.beforeafter.POJO->new(..)) OR execution(* org.jboss.test.aop.beforeafter.POJO->method(..)) OR field(!static * org.jboss.test.aop.beforeafter.POJO->*)">
+ <bind pointcut="execution(org.jboss.test.aop.beforeafter.POJO->new(..)) OR execution(* org.jboss.test.aop.beforeafter.POJO->method*(..)) OR field(!static * org.jboss.test.aop.beforeafter.POJO->*)">
<stack-ref name="argsStack"/>
</bind>
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/BeforeAfterThrowingTestCase.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -41,20 +41,20 @@
System.out.println("=== TESING SIMPLE");
POJO pojo = new POJO();
- System.out.println("* Calling method with error=false");
+ System.out.println("* Calling method1 with error=false");
SimpleAspect.clear();
- assertEquals(1, pojo.method(false));
+ assertEquals(1, pojo.method1(false));
assertTrue(SimpleAspect.before);
assertTrue(SimpleAspect.around);
assertTrue(SimpleAspect.after);
assertFalse(SimpleAspect.throwing);
- System.out.println("* Calling method with error=true");
+ System.out.println("* Calling method1 with error=true");
SimpleAspect.clear();
try
{
- pojo.method(true);
+ pojo.method1(true);
assertFalse("Should not get here", true);
}
catch(TestException e)
@@ -67,6 +67,40 @@
assertFalse(SimpleAspect.after);
assertTrue(SimpleAspect.throwing);
}
+
+ public void testSimpleWithFinally() throws Exception
+ {
+ System.out.println("=== TESING SIMPLE WITH FINALLY");
+ POJO pojo = new POJO();
+
+ System.out.println("* Calling method2 with error=false");
+ SimpleAspect.clear();
+ assertEquals(1, pojo.method2(false));
+ assertTrue(SimpleAspect.before);
+ assertTrue(SimpleAspect.around);
+ assertTrue(SimpleAspect.after);
+ assertFalse(SimpleAspect.throwing);
+ assertTrue(SimpleAspect.finallyAdvice);
+
+
+ System.out.println("* Calling method2 with error=true");
+ SimpleAspect.clear();
+ try
+ {
+ pojo.method2(true);
+ assertFalse("Should not get here", true);
+ }
+ catch(TestException e)
+ {
+ assertSame(e, SimpleAspect.exception);
+ }
+
+ assertTrue(SimpleAspect.before);
+ assertTrue(SimpleAspect.around);
+ assertFalse(SimpleAspect.after);
+ assertTrue(SimpleAspect.throwing);
+ assertTrue(SimpleAspect.finallyAdvice);
+ }
public void testArgs() throws Exception
{
@@ -110,12 +144,12 @@
assertFalse(SimpleAspect.throwing);
- System.out.println("* Testing method(boolean) with exception");
+ System.out.println("* Testing method1(boolean) with exception");
ArgsAspect.clear();
SimpleAspect.clear();
try
{
- pojo.method(true);
+ pojo.method1(true);
throw new RuntimeException("TestException not thrown");
}
catch (TestException e)
@@ -131,10 +165,10 @@
assertFalse(SimpleAspect.after);
assertTrue(SimpleAspect.throwing);
- System.out.println("* Testing method(boolean)");
+ System.out.println("* Testing method1(boolean)");
ArgsAspect.clear();
SimpleAspect.clear();
- pojo.method(false);
+ pojo.method1(false);
assertNull(ArgsAspect.before);
assertNull(ArgsAspect.after);
assertNull(ArgsAspect.throwing);
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/POJO.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/POJO.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -50,7 +50,7 @@
joinPointRun = true;
}
- public int method(boolean error)throws TestException
+ public int method1(boolean error)throws TestException
{
joinPointRun = true;
if (error) throw new TestException();
@@ -58,6 +58,14 @@
return 1;
}
+ public int method2(boolean error)throws TestException
+ {
+ joinPointRun = true;
+ if (error) throw new TestException();
+
+ return 1;
+ }
+
public int method(boolean error, int i, long l, String s) throws TestException
{
joinPointRun = true;
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/SimpleAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/SimpleAspect.java 2007-04-24 22:06:01 UTC (rev 62526)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafter/SimpleAspect.java 2007-04-24 23:23:23 UTC (rev 62527)
@@ -38,6 +38,7 @@
public static boolean around;
public static boolean after;
public static boolean throwing;
+ public static boolean finallyAdvice;
public static Throwable exception;
public static void clear()
@@ -46,6 +47,7 @@
around = false;
after = false;
throwing = false;
+ finallyAdvice = false;
POJO.joinPointRun = false;
}
@@ -81,4 +83,11 @@
exception = t;
throwing = true;
}
+
+ public void finallyAdvice()
+ {
+ System.out.println("SimpleAspect.finallyAdvice");
+ finallyAdvice = true;
+ Assert.assertTrue(POJO.joinPointRun);
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list