1 22 package org.jboss.test.aop.dynamicgenadvisor; 23 24 import java.lang.reflect.AccessibleObject ; 25 import java.lang.reflect.Constructor ; 26 import java.lang.reflect.Field ; 27 import java.lang.reflect.Method ; 28 29 import org.jboss.aop.advice.Interceptor; 30 import org.jboss.aop.joinpoint.ConstructionInvocation; 31 import org.jboss.aop.joinpoint.ConstructorInvocation; 32 import org.jboss.aop.joinpoint.FieldInvocation; 33 import org.jboss.aop.joinpoint.FieldReadInvocation; 34 import org.jboss.aop.joinpoint.FieldWriteInvocation; 35 import org.jboss.aop.joinpoint.Invocation; 36 import org.jboss.aop.joinpoint.MethodInvocation; 37 38 public class MyInterceptor implements Interceptor 39 { 40 41 public String getName() 42 { 43 return "MyInterceptor"; 44 } 45 46 public Object invoke(Invocation invocation) throws Throwable 47 { 48 System.out.println("MyInterceptor.invoke()"); 49 if (invocation instanceof ConstructorInvocation) 50 { 51 ConstructorInvocation ci = (ConstructorInvocation)invocation; 52 Interceptions.addConstructorInterception(this.getClass(), ci.getConstructor()); 53 } 54 if (invocation instanceof ConstructionInvocation) 55 { 56 ConstructionInvocation ci = (ConstructionInvocation)invocation; 57 Interceptions.addConstructionInterception(this.getClass(), ci.getConstructor()); 58 } 59 else if (invocation instanceof MethodInvocation) 60 { 61 MethodInvocation mi = (MethodInvocation)invocation; 62 Interceptions.addMethodInterception(this.getClass(), mi.getMethod()); 63 } 64 else if (invocation instanceof FieldReadInvocation) 65 { 66 FieldInvocation fi = (FieldReadInvocation)invocation; 67 Interceptions.addFieldReadInterception(this.getClass(), fi.getField()); 68 } 69 else if (invocation instanceof FieldWriteInvocation) 70 { 71 FieldWriteInvocation fi = (FieldWriteInvocation)invocation; 72 Interceptions.addFieldWriteInterception(this.getClass(), fi.getField()); 73 } 74 75 return invocation.invokeNext(); 76 } 77 78 private String getClassName(Constructor c) 79 { 80 return getClassName(c.getDeclaringClass().getName()); 81 } 82 83 private String getClassName(Method m) 84 { 85 return getClassName(m.getDeclaringClass().getName()); 86 } 87 88 private String getClassName(Field f) 89 { 90 return getClassName(f.getDeclaringClass().getName()); 91 } 92 93 private String getClassName(String s) 94 { 95 return s.substring(s.lastIndexOf('.') + 1); 96 } 97 98 } 99 | Popular Tags |