1 22 package org.jboss.test.aop.jdk15.annotated; 23 24 import org.jboss.aop.Aspect; 25 import org.jboss.aop.Bind; 26 import org.jboss.aop.advice.Scope; 27 import org.jboss.aop.joinpoint.ConstructorInvocation; 28 import org.jboss.aop.joinpoint.FieldReadInvocation; 29 import org.jboss.aop.joinpoint.FieldWriteInvocation; 30 import org.jboss.aop.joinpoint.MethodInvocation; 31 32 36 @Aspect(scope = Scope.PER_CLASS) 37 public class AspectPerClass 38 { 39 public int constructorCalled; 40 public int methodCalled; 41 public int fieldRead; 42 public int fieldWrite; 43 44 @Bind(pointcut = "execution(org.jboss.test.aop.jdk15.annotated.POJO*->new())") 45 public Object constructorAdvice(ConstructorInvocation invocation) throws Throwable 46 { 47 System.out.println("AspectPerClass.constructorAdvice accessing: " + invocation.getConstructor().toString()); 48 constructorCalled++; 49 return invocation.invokeNext(); 50 } 51 52 @Bind(pointcut = "execution(void org.jboss.test.aop.jdk15.annotated.POJO*->someMethod())") 53 public Object methodAdvice(MethodInvocation invocation) throws Throwable 54 { 55 System.out.println("AspectPerClass.methodAdvice accessing: " + invocation.getMethod().toString()); 56 methodCalled++; 57 return invocation.invokeNext(); 58 } 59 60 @Bind(pointcut = "set(* org.jboss.test.aop.jdk15.annotated.POJO*->field)") 61 public Object fieldAdvice(FieldWriteInvocation invocation) throws Throwable 62 { 63 System.out.println("AspectPerClass.fieldAdvice writing to field: " + invocation.getField().getName()); 64 fieldWrite++; 65 return invocation.invokeNext(); 66 } 67 68 @Bind(pointcut = "get(* org.jboss.test.aop.jdk15.annotated.POJO*->field)") 69 public Object fieldAdvice(FieldReadInvocation invocation) throws Throwable 70 { 71 System.out.println("AspectPerClass.fieldAdvice reading field: " + invocation.getField().getName()); 72 fieldRead++; 73 return invocation.invokeNext(); 74 } 75 76 public void reset() 77 { 78 constructorCalled = 0; 79 methodCalled = 0; 80 fieldRead = 0; 81 fieldWrite = 0; 82 } 83 } 84 | Popular Tags |