1 22 package org.jboss.test.aop.reflection; 23 24 import org.jboss.aop.joinpoint.ConstructorInvocation; 25 import org.jboss.aop.joinpoint.FieldReadInvocation; 26 import org.jboss.aop.joinpoint.FieldWriteInvocation; 27 import org.jboss.aop.joinpoint.MethodInvocation; 28 29 33 public class SimplePerVmInterceptor implements org.jboss.aop.advice.Interceptor 34 { 35 public static int constructorIntercepted; 36 public static int fieldReadIntercepted; 37 public static int fieldWriteIntercepted; 38 public static int methodIntercepted; 39 40 public String getName() 41 { 42 return "SimplePerVmInterceptor"; 43 } 44 45 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 46 { 47 System.out.println("SimplePerVmInterceptor interception: " + invocation.getClass().getName()); 48 if (invocation instanceof MethodInvocation) 49 { 50 methodIntercepted++; 51 System.out.println("methodIntercepted: " + methodIntercepted); 52 } 53 else if (invocation instanceof FieldReadInvocation) 54 { 55 fieldReadIntercepted++; 56 System.out.println("fieldReadIntercepted: " + fieldReadIntercepted); 57 } 58 else if (invocation instanceof FieldWriteInvocation) 59 { 60 fieldWriteIntercepted++; 61 System.out.println("fieldWriteIntercepted: " + fieldWriteIntercepted); 62 } 63 else if (invocation instanceof ConstructorInvocation) 64 { 65 constructorIntercepted++; 66 System.out.println("constructorIntercepted:" + constructorIntercepted); 67 } 68 return invocation.invokeNext(); 69 } 70 71 public static boolean hasIntercepted() 72 { 73 return (constructorIntercepted > 0 || fieldReadIntercepted > 0 || fieldWriteIntercepted > 0 ||methodIntercepted> 0); 74 } 75 76 public static void reset() 77 { 78 constructorIntercepted = 0; 79 fieldReadIntercepted = 0; 80 fieldWriteIntercepted = 0; 81 methodIntercepted = 0; 82 } 83 } 84 85 | Popular Tags |