1 22 package org.jboss.test.aop.callerargs; 23 24 import org.jboss.aop.advice.Interceptor; 25 import org.jboss.aop.joinpoint.ConstructorInvocation; 26 import org.jboss.aop.joinpoint.Invocation; 27 import org.jboss.aop.joinpoint.MethodInvocation; 28 29 34 public class ExecutionInterceptor implements Interceptor 35 { 36 public static boolean intercepted; 37 public static int argsLength; 38 public static Object [] args; 39 40 public String getName() 41 { 42 return "ExecutionInterceptor"; 43 } 44 45 public Object invoke(Invocation invocation) throws Throwable 46 { 47 System.out.println("execution intercepted"); 48 intercepted = true; 49 Object [] invArgs = getArguments(invocation); 50 if (invArgs == null) 51 { 52 argsLength = 0; 53 } 54 else 55 { 56 argsLength = invArgs.length; 57 } 58 args = invArgs; 59 60 return invocation.invokeNext(); 61 } 62 63 private Object [] getArguments(Invocation invocation) 64 { 65 if (invocation instanceof MethodInvocation) 66 { 67 return ((MethodInvocation)invocation).getArguments(); 68 } 69 else if (invocation instanceof ConstructorInvocation) 70 { 71 return ((ConstructorInvocation)invocation).getArguments(); 72 } 73 return new Object [0]; 74 } 75 76 } 77 | Popular Tags |