/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.ConstructorInvocation; import org.jboss.aop.joinpoint.MethodInvocation; import org.jboss.aop.joinpoint.FieldReadInvocation; import org.jboss.aop.joinpoint.FieldWriteInvocation; import org.jboss.aop.advice.Interceptor; import org.jboss.aop.Aspect; import org.jboss.aop.Bind; import org.jboss.aop.advice.Scope; /** * * @author Bill Burke * @version $Revision: 1.1 $ */ @Aspect(scope=Scope.PER_VM) public class AspectPerVM { public int constructorCalled; public int methodCalled; public int fieldRead; public int fieldWrite; @Bind(pointcut="execution(POJO*->new())") public Object constructorAdvice(ConstructorInvocation invocation) throws Throwable { System.out.println("AspectPerVM.constructorAdvice accessing: " + invocation.getConstructor().toString()); constructorCalled++; return invocation.invokeNext(); } @Bind(pointcut="execution(void POJO*->someMethod())") public Object methodAdvice(MethodInvocation invocation) throws Throwable { System.out.println("AspectPerVM.methodAdvice accessing: " + invocation.getMethod().toString()); methodCalled++; return invocation.invokeNext(); } @Bind(pointcut="set(* POJO*->field)") public Object fieldAdvice(FieldWriteInvocation invocation) throws Throwable { System.out.println("AspectPerVM.fieldAdvice writing to field: " + invocation.getField().getName()); fieldWrite++; return invocation.invokeNext(); } @Bind(pointcut="get(* POJO*->field)") public Object fieldAdvice(FieldReadInvocation invocation) throws Throwable { System.out.println("AspectPerVM.fieldAdvice reading field: " + invocation.getField().getName()); fieldRead++; return invocation.invokeNext(); } }