1 22 package org.jboss.test.aop.annotated; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.Method ; 26 27 import org.jboss.aop.advice.Interceptor; 28 import org.jboss.aop.annotation.AnnotationElement; 29 import org.jboss.aop.introduction.AnnotationIntroduction; 30 import org.jboss.aop.joinpoint.ConstructorInvocation; 31 import org.jboss.aop.joinpoint.Invocation; 32 import org.jboss.aop.joinpoint.MethodInvocation; 33 34 41 public class IntroducedAnnotationInterceptor implements Interceptor 42 { 43 46 public static AnnotationIntroduction annotationIntroduction; 47 48 public static MyAnnotation lastMyAnnotation; 49 50 public String getName() 51 { 52 return "TestAnnotationInterceptor"; 53 } 54 55 public Object invoke(Invocation invocation) throws Throwable 56 { 57 System.out.println("IntroducedInterceptor"); 58 if (invocation instanceof MethodInvocation) 59 { 60 Method method = ((MethodInvocation)invocation).getMethod(); 61 System.out.println("executing method " + method.toString()); 62 MyAnnotation myAnn = (MyAnnotation)AnnotationElement.getAnyAnnotation(method, MyAnnotation.class); 63 lastMyAnnotation = myAnn; 64 } 65 else if (invocation instanceof ConstructorInvocation) 66 { 67 Constructor constructor = ((ConstructorInvocation)invocation).getConstructor(); 68 System.out.println("executing constructor " + constructor); 69 MyAnnotation myAnn = (MyAnnotation)AnnotationElement.getAnyAnnotation(constructor, MyAnnotation.class); 70 lastMyAnnotation = myAnn; 71 } 72 73 return invocation.invokeNext(); 74 } 75 } 76 | Popular Tags |