1 22 package org.jboss.test.aop.bean; 23 24 import org.jboss.aop.joinpoint.FieldInvocation; 25 import org.jboss.aop.advice.Interceptor; 26 import org.jboss.aop.joinpoint.Invocation; 27 import org.jboss.aop.joinpoint.MethodInvocation; 28 import org.jboss.aop.joinpoint.FieldReadInvocation; 29 import org.jboss.aop.joinpoint.FieldWriteInvocation; 30 31 import java.lang.reflect.Field ; 32 import java.lang.reflect.Method ; 33 38 public class SimpleInterceptor implements org.jboss.aop.advice.Interceptor 39 { 40 41 public String getName() 42 { 43 return "SimpleInterceptor"; 44 } 45 46 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 47 { 48 System.out.println("interception: " + invocation.getClass().getName()); 49 if (invocation instanceof MethodInvocation) 50 { 51 org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation)invocation; 52 Method m = methodInvocation.getMethod(); 53 if (m.getName().equals("whazup")) return "nada"; 54 lastIntercepted = m.getName(); 55 String transattr = (String )invocation.getMetaData("transaction", "trans-attribute"); 56 System.out.println("trans-attribute: " + transattr); 57 lastTransAttributeAccessed = transattr; 58 } 59 else if (invocation instanceof FieldReadInvocation || invocation instanceof FieldWriteInvocation) 60 { 61 org.jboss.aop.joinpoint.FieldInvocation fieldInvocation = (org.jboss.aop.joinpoint.FieldInvocation)invocation; 62 Field field = fieldInvocation.getField(); 63 System.out.println("**** simple: " + field.getName()); 64 lastFieldIntercepted = field.getName(); 65 Object obj =invocation.getMetaData("transaction", "trans-attribute"); 66 System.out.println(field.getName() + "type**" + obj.getClass().getName()); 67 String transattr = (String )invocation.getMetaData("transaction", "trans-attribute"); 68 System.out.println("trans-attribute: " + transattr); 69 lastFieldTransAttributeAccessed = transattr; 70 } 71 return invocation.invokeNext(); 72 } 73 74 public static String lastIntercepted; 75 public static String lastTransAttributeAccessed; 76 public static String lastFieldIntercepted; 77 public static String lastFieldTransAttributeAccessed; 78 } 79 80 | Popular Tags |