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.FieldReadInvocation; 28 import org.jboss.aop.joinpoint.FieldWriteInvocation; 29 import org.jboss.aop.joinpoint.MethodInvocation; 30 31 35 @Aspect(scope = Scope.PER_INSTANCE) 36 public class AspectPerInstance 37 { 38 public int methodCalled; 39 public int fieldRead; 40 public int fieldWrite; 41 42 @Bind(pointcut = "execution(void org.jboss.test.aop.jdk15.annotated.POJO*->someMethod())") 43 public Object methodAdvice(MethodInvocation invocation) throws Throwable 44 { 45 System.out.println("AspectPerInstance.methodAdvice accessing: " + invocation.getMethod().toString()); 46 methodCalled++; 47 return invocation.invokeNext(); 48 } 49 50 @Bind(pointcut = "set(* org.jboss.test.aop.jdk15.annotated.POJO*->field)") 51 public Object fieldAdvice(FieldWriteInvocation invocation) throws Throwable 52 { 53 System.out.println("AspectPerInstance.fieldAdvice writing to field: " + invocation.getField().getName()); 54 fieldWrite++; 55 return invocation.invokeNext(); 56 } 57 58 @Bind(pointcut = "get(* org.jboss.test.aop.jdk15.annotated.POJO*->field)") 59 public Object fieldAdvice(FieldReadInvocation invocation) throws Throwable 60 { 61 System.out.println("AspectPerInstance.fieldAdvice reading field: " + invocation.getField().getName()); 62 fieldRead++; 63 return invocation.invokeNext(); 64 } 65 } 66 | Popular Tags |