/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.MethodInvocation; import org.jboss.aop.joinpoint.ConstructorInvocation; import org.jboss.aop.joinpoint.FieldReadInvocation; import org.jboss.aop.joinpoint.FieldWriteInvocation; import org.jboss.aop.advice.Interceptor; /** * * @author Bill Burke * @version $Revision: 1.3 $ */ public class TraceInterceptor implements Interceptor { public String getName() { return "TraceInterceptor"; } public Object invoke(Invocation invocation) throws Throwable { String msg = ""; if (invocation instanceof MethodInvocation) { msg = "executing method " + ((MethodInvocation)invocation).getMethod().toString(); } else if (invocation instanceof ConstructorInvocation) { msg = "executing constructor " + ((ConstructorInvocation)invocation).getConstructor(); } else if (invocation instanceof FieldReadInvocation) { msg = "read field name: " + ((FieldReadInvocation)invocation).getField(); } else if (invocation instanceof FieldWriteInvocation) { msg = "write field name: " + ((FieldWriteInvocation)invocation).getField(); } else { msg = "unknown invocation type: " + invocation.getClass().getName(); } try { System.out.println("<<< Trace : " + msg); return invocation.invokeNext(); } finally { System.out.println(">>> Leaving Trace"); } } }