triptracker.testing.compress
Class DebugProxy

java.lang.Object
  extended by triptracker.testing.compress.DebugProxy
All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
DBDebugProxy

public class DebugProxy
extends Object
implements InvocationHandler

Generic debug proxy class that logs every method call.

Author:
Jan Magne Tjensvold <janmagne at broadpark dot no>

Field Summary
protected static boolean debugEnabled
           
protected  List<Method> history
           
protected  List<Method> methods
           
protected  Object obj
           
 
Constructor Summary
protected DebugProxy(Object obj)
          Creation of new proxies can only be made by the proxyFor(Object) method since the constructor's visibility is private.
 
Method Summary
 void clearHistory()
          Clear the method call history.
 List<Method> getHistory()
          Returns the method call history as a list of strings.
 Object invoke(Object proxy, Method method, Object[] args)
          This method is called everytime a call is made to any method on the proxy instance.
static boolean isDebugEnabled()
          Get the enabled state of the debug proxy class.
static Object proxyFor(Object obj)
          Creates a logging proxy object from the specified object.
static void setDebugEnabled(boolean state)
          Set the enabled state of the debug proxy class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

obj

protected final Object obj

methods

protected final List<Method> methods

history

protected final List<Method> history

debugEnabled

protected static boolean debugEnabled
Constructor Detail

DebugProxy

protected DebugProxy(Object obj)
Creation of new proxies can only be made by the proxyFor(Object) method since the constructor's visibility is private.

Parameters:
obj - points to the object to create a proxy for.
Method Detail

proxyFor

public static Object proxyFor(Object obj)
Creates a logging proxy object from the specified object.

Parameters:
obj - points to the object to create a proxy for.
Returns:
proxy object of this class that logs method calls.

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
This method is called everytime a call is made to any method on the proxy instance.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - is a reference to the proxy object.
method - points to a method object describing the method being called.
args - is the arguments for the method call.
Returns:
the actual return value from the method call.
Throws:
Throwable
See Also:
InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])

getHistory

public List<Method> getHistory()
Returns the method call history as a list of strings.

Returns:
method call history.

clearHistory

public void clearHistory()
Clear the method call history.


isDebugEnabled

public static boolean isDebugEnabled()
Get the enabled state of the debug proxy class.

If a debug proxy class is disabled its debug specific states shall not be modified when method invocations pass through the invoke(Object, Method, Object[]) method and it should not generate any debug specific output.

Returns:
enabled state of the debug proxy.

setDebugEnabled

public static void setDebugEnabled(boolean state)
Set the enabled state of the debug proxy class.

If a debug proxy class is disabled its debug specific states shall not be modified when method invocations pass through the invoke(Object, Method, Object[]) method and it should not generate any debug specific output.

Parameters:
state - is the enabled state of the debug proxy.


Copyright © 2006 Team Trip Tracker. All Rights Reserved.