org.jcoderz.commons.tracing
Class TracingProxy

java.lang.Object
  extended by org.jcoderz.commons.tracing.TracingProxy
All Implemented Interfaces:
InvocationHandler

public final class TracingProxy
extends Object
implements InvocationHandler

This class can be used to proxy any object, providing tracing for all interfaces of the object.

Note: Java Dynamic Proxies only work on interfaces. The object returned by the #getProxy(Object) can be cast to any interface implemented by the argument or one of its ancestors. It can't, however, be cast to an implementation class.

Author:
Andreas Mandel

Method Summary
static Object getProxy(Object obj, Class tracerClass)
          Static factory that wraps an object into a proxy depending on the log level for that object.
 Object invoke(Object proxy, Method method, Object[] args)
          Log the entering, exiting and throwing events of the proxied object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getProxy

public static Object getProxy(Object obj,
                              Class tracerClass)
Static factory that wraps an object into a proxy depending on the log level for that object.

Parameters:
obj - an object for which a proxy should be created
Returns:
a logging proxy for the obj, if the log level for that object is FINER or finest, the object itself otherwise

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Log the entering, exiting and throwing events of the proxied object.

Specified by:
invoke in interface InvocationHandler
Throws:
Throwable
See Also:
InvocationHandler.invoke( java.lang.Object, java.lang.reflect.Method, java.lang.Object[])


Copyright 2007 The jCoderZ Project.