/* * 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.MethodInvocation; import org.jboss.aop.joinpoint.ConstructorInvocation; import org.jboss.aop.joinpoint.FieldInvocation; import org.jboss.aop.joinpoint.FieldReadInvocation; import org.jboss.aop.joinpoint.FieldWriteInvocation; import org.jboss.aop.advice.Interceptor; import org.jboss.aop.advice.Scope; import org.jboss.aop.InterceptorDef; import org.jboss.aop.Bind; import org.jboss.aop.Aspect; /** * * @author Kabir Khan * @version $Revision: 1.1 $ */ @Aspect public class MyAspect { @Bind (pointcut="execution(POJO->new())") public Object constructorAdvice(ConstructorInvocation invocation) throws Throwable { try { System.out.println("<<< MyAdvice.constructorAdvice accessing: " + invocation.getConstructor().toString()); return invocation.invokeNext(); } finally { System.out.println(">>> Leaving MyAdvice.constructorAdvice"); } } @Bind (pointcut="execution(void POJO->method())") public Object methodAdvice(MethodInvocation invocation) throws Throwable { try { System.out.println("<<< MyAdvice.methodAdvice accessing: " + invocation.getMethod().toString()); return invocation.invokeNext(); } finally { System.out.println(">>> Leaving MyAdvice.methodAdvice"); } } @Bind (pointcut="set(int POJO->field)") public Object fieldAdvice(FieldReadInvocation invocation) throws Throwable { try { System.out.println("<<< MyAspect.fieldAdvice writing to field: " + invocation.getField().getName()); return invocation.invokeNext(); } finally { System.out.println(">>> Leaving MyAspect.fieldAdvice"); } } @Bind (pointcut="get(int POJO->field)") public Object fieldAdvice(FieldWriteInvocation invocation) throws Throwable { try { System.out.println("<<< MyAspect.fieldAdvice reading field: " + invocation.getField().getName()); return invocation.invokeNext(); } finally { System.out.println(">>> Leaving MyAspect.fieldAdvice"); } } }