package org.nthx.util.jbossaop;
import org.apache.log4j.Logger;
import org.jboss.aop.joinpoint.ConstructorInvocation;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
public class InterceptorLogger
extends DefaultInterceptorImpl
{
private transient static Logger log = Logger.getLogger("pat");
public Object invoke(Invocation invocation) throws Throwable
{
log.debug("------>>>: " + getInvocationName(invocation) + " for :" + getInfo(invocation));
Object result = invocation.invokeNext();
log.debug(" **<<--|: " + getInvocationName(invocation));
return result;
}
private Invocation getBaseInvocation(Invocation invocation)
{
return (Invocation) ((MethodInvocation)invocation).getArguments()[0];
}
private String getInvocationName(Invocation invocation)
{
return getBaseInvocation(invocation).toString().substring(
getBaseInvocation(invocation).toString().lastIndexOf(".") + 1);
}
private String getInfo(Invocation invocation)
{
String info;
Invocation baseInvocation = getBaseInvocation(invocation);
if (baseInvocation instanceof MethodInvocation)
{
info = ((MethodInvocation) baseInvocation).getMethod().toString();
}
else if (baseInvocation instanceof ConstructorInvocation)
info = ((ConstructorInvocation)baseInvocation).getConstructor().getName();
else
info = "unknown, TODO";
return info;
}
}