1 22 package org.jboss.test.aop.basic; 23 24 import org.jboss.aop.joinpoint.FieldReadInvocation; 25 import org.jboss.aop.joinpoint.FieldWriteInvocation; 26 import org.jboss.aop.joinpoint.MethodInvocation; 27 28 import java.lang.reflect.Field ; 29 import java.lang.reflect.Method ; 30 31 35 public class SimpleInterceptor implements org.jboss.aop.advice.Interceptor 36 { 37 38 public String getName() 39 { 40 return "SimpleInterceptor"; 41 } 42 43 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 44 { 45 System.out.println("interception: " + invocation.getClass().getName()); 46 if (invocation instanceof MethodInvocation) 47 { 48 org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation) invocation; 49 Method m = methodInvocation.getMethod(); 50 if (m.getName().equals("whazup")) return "nada"; 51 lastIntercepted = m.getName(); 52 String transattr = (String ) invocation.getMetaData("transaction", "trans-attribute"); 53 System.out.println("trans-attribute: " + transattr); 54 lastTransAttributeAccessed = transattr; 55 } 56 else if (invocation instanceof FieldReadInvocation || invocation instanceof FieldWriteInvocation) 57 { 58 org.jboss.aop.joinpoint.FieldInvocation fieldInvocation = (org.jboss.aop.joinpoint.FieldInvocation) invocation; 59 Field field = fieldInvocation.getField(); 60 System.out.println("**** simple: " + field.getName()); 61 lastFieldIntercepted = field.getName(); 62 Object obj = invocation.getMetaData("transaction", "trans-attribute"); 63 if (obj != null) 64 { 65 System.out.println(field.getName() + "type**" + obj.getClass().getName()); 66 } 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 |