1 22 import org.jboss.aop.joinpoint.Invocation; 23 import org.jboss.aop.joinpoint.MethodInvocation; 24 import org.jboss.aop.joinpoint.ConstructorInvocation; 25 import org.jboss.aop.joinpoint.FieldInvocation; 26 import org.jboss.aop.joinpoint.FieldReadInvocation; 27 import org.jboss.aop.joinpoint.FieldWriteInvocation; 28 import org.jboss.aop.advice.Interceptor; 29 import org.jboss.aop.advice.Scope; 30 import org.jboss.aop.Bind; 31 import org.jboss.aop.Aspect; 32 import org.jboss.aop.PointcutDef; 33 import org.jboss.aop.pointcut.Pointcut; 34 35 40 @Aspect (scope=Scope.PER_VM) 41 public class MyAspect 42 { 43 @PointcutDef("execution(POJO->new(..))") 44 public static Pointcut pojoConstructors; 45 46 @PointcutDef("get(* POJO->*)") 47 public static Pointcut pojoFieldReads; 48 49 @PointcutDef("set(* POJO->*)") 50 public static Pointcut pojoFieldWrites; 51 52 @PointcutDef("execution(* POJO->*(..))") 53 public static Pointcut pojoMethods; 54 55 @PointcutDef("MyAspect.pojoFieldReads OR MyAspect.pojoFieldWrites") 56 public static Pointcut pojoFields; 57 58 @Bind(pointcut = "MyAspect.pojoFields OR MyAspect.pojoMethods OR MyAspect.pojoConstructors") 59 public Object anotherPOJOAdvice(Invocation invocation) throws Throwable 60 { 61 try 62 { 63 if (invocation instanceof ConstructorInvocation) 64 { 65 System.out.println("<<< MyAspect.anotherPOJOAdvice - calling constructor"); 66 } 67 else if (invocation instanceof MethodInvocation) 68 { 69 System.out.println("<<< MyAspect.anotherPOJOAdvice - calling method"); 70 } 71 else if (invocation instanceof FieldReadInvocation) 72 { 73 System.out.println("<<< MyAspect.anotherPOJOAdvice - reading field"); 74 } 75 else if (invocation instanceof FieldWriteInvocation) 76 { 77 System.out.println("<<< MyAspect.anotherPOJOAdvice - writing field"); 78 } 79 return invocation.invokeNext(); 80 } 81 finally 82 { 83 System.out.println(">>> Leaving MyAspect.anotherPOJOAdvice"); 84 } 85 } 86 87 } 88 | Popular Tags |