FileDocCategorySizeDatePackage
CallLoggingInterceptor.javaAPI DocJBoss 4.2.15115Fri Jul 13 21:02:26 BST 2007org.jboss.aspects.logging

CallLoggingInterceptor

public final class CallLoggingInterceptor extends Object implements org.jboss.aop.advice.Interceptor, LoggingConstants
Logs invocations.
author
Adrian Brock.
version
$Revision: 57186 $

Fields Summary
protected Logger
log
Constructors Summary
Methods Summary
public java.lang.StringdumpInvocation(org.jboss.aop.joinpoint.Invocation invocation)
Display useful information about the invocation

todo
improve this, probably controlled by meta data
param
invocation the invocation

      StringBuffer buffer = new StringBuffer();
      if (invocation instanceof MethodInvocation)
      {
         org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation)invocation;
         buffer.append("Method@").append(System.identityHashCode(invocation)).append("{");
         buffer.append("method=").append(methodInvocation.getMethod());
         // TODO fix this, null arguments screws this up 
         // buffer.append(" args=").append(Arrays.asList(methodInvocation.arguments));
      }
      else if (invocation instanceof FieldReadInvocation)
      {
         org.jboss.aop.joinpoint.FieldReadInvocation fieldInvocation = (org.jboss.aop.joinpoint.FieldReadInvocation)invocation;
         buffer.append("FieldRead@").append(System.identityHashCode(invocation)).append("{");
         buffer.append("field=").append(fieldInvocation.getField());
      }
      else if (invocation instanceof FieldWriteInvocation)
      {
         org.jboss.aop.joinpoint.FieldWriteInvocation fieldInvocation = (org.jboss.aop.joinpoint.FieldWriteInvocation)invocation;
         buffer.append("FieldWrite@").append(System.identityHashCode(invocation)).append("{");
         buffer.append("field=").append(fieldInvocation.getField());
         buffer.append(" value=").append(fieldInvocation.getValue());
      }
      else if (invocation instanceof ConstructorInvocation)
      {
         org.jboss.aop.joinpoint.ConstructorInvocation cInvocation = (org.jboss.aop.joinpoint.ConstructorInvocation)invocation;
         buffer.append("Construct@").append(System.identityHashCode(invocation)).append("{");
         buffer.append("constructor=").append(cInvocation.getConstructor());
         buffer.append(" args=").append(Arrays.asList(cInvocation.getArguments()));
      }
      else
      {
         return "Unknown " + invocation;
      }
      buffer.append("}");
      return buffer.toString();
   
public java.lang.StringdumpInvocationResponse(java.lang.Object response)
Display useful information about the invocation response

todo
improve this, probably controlled by meta data
param
invocation the invocation

      if (response == null)
         return "null";
      StringBuffer buffer = new StringBuffer();
      buffer.append(response);
      return buffer.toString();
   
public java.lang.StringgetName()


       return "CallLoggingInterceptor"; 
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      boolean callLogging = log.isDebugEnabled();
      if (callLogging)
         callLogging = Boolean.valueOf((String)invocation.getMetaData(LOGGING, CALL_LOGGING)).booleanValue();

      if (callLogging)
         log.debug("Invoking: " + dumpInvocation(invocation));

      Object response = null;
      try
      {
         response = invocation.invokeNext();
         return response;
      }
      catch (Throwable t)
      {
         if (callLogging)
            log.debug("Throwing: " + dumpInvocation(invocation), t);
         throw t;
      }
      finally
      {
         if (callLogging)
            log.debug("Response: " + dumpInvocationResponse(response) + " for " + dumpInvocation(invocation));
      }