1 22 package org.jboss.test.aop.jdk15.dynamic.common; 23 24 import org.jboss.aop.joinpoint.FieldInvocation; 25 import org.jboss.aop.joinpoint.FieldReadInvocation; 26 import org.jboss.aop.joinpoint.FieldWriteInvocation; 27 import org.jboss.aop.joinpoint.Invocation; 28 import org.jboss.aop.joinpoint.ConstructorInvocation; 29 import org.jboss.aop.joinpoint.MethodInvocation; 30 import org.jboss.aop.advice.Interceptor; 31 32 39 public class InstanceInterceptor implements Interceptor 40 { 41 private static InterceptionsCount interceptionsCount = new InterceptionsCount(); 42 43 48 public static InterceptionsCount getInterceptionsCount() 49 { 50 return interceptionsCount; 51 } 52 53 56 public static void resetCounts() 57 { 58 interceptionsCount = new InterceptionsCount(); 59 } 60 61 64 public String getName() { return "InstanceInterceptor"; } 65 66 69 public Object invoke(Invocation invocation) throws Throwable 70 { 71 interceptionsCount.total++; 72 if (invocation instanceof ConstructorInvocation) 73 { 74 interceptionsCount.constructor++; 75 } 76 else if (invocation instanceof FieldInvocation) 77 { 78 if (invocation instanceof FieldReadInvocation) 79 { 80 if (!((FieldReadInvocation) invocation).getField().getName().equals("runner")) 83 { 84 interceptionsCount.fieldRead++; 85 } 86 else 87 { 88 interceptionsCount.total--; 89 } 90 91 } 92 else if (invocation instanceof FieldWriteInvocation) 93 { 94 if (!((FieldWriteInvocation) invocation).getField().getName().equals("runner")) 96 { 97 interceptionsCount.fieldWrite++; 98 } 99 else 100 { 101 interceptionsCount.total--; 102 } 103 } 104 else 105 { 106 throw new RuntimeException ("Unexpected invocation type invalidates test correction."); 107 } 108 } 109 else if (invocation instanceof MethodInvocation) 110 { 111 if (!((MethodInvocation) invocation).getMethod().getName().equals("finalize")) 113 { 114 interceptionsCount.method++; 115 } 116 else 117 { 118 interceptionsCount.total--; 119 } 120 } 121 return invocation.invokeNext(); 122 } 123 } | Popular Tags |