Java Reference
In-Depth Information
this.obj = obj;
methods = new ArrayList<Method>();
history = Collections.unmodifiableList(methods);
}
public static synchronized Object proxyFor(Object obj) {
Class<?> objClass = obj.getClass();
return Proxy.newProxyInstance(
objClass.getClassLoader(),
objClass.getInterfaces(),
new DebugProxy(obj));
}
public Object
invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
methods.add(method); // log the call
try {
// invoke the real method
return method.invoke(obj, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
public List<Method> getHistory() { return history; }
}
If you want a debug proxy for a given object, you invoke proxyFor , as in
Object proxyObj = DebugProxy.proxyFor(realObj);
The object proxyObj would implement all the interfaces that realObj im-
plements, plus the methods of Object . The object proxyObj is also associ-
ated with the instance of DebugProxy that was createdthis instance is the
invocation handler for the proxy. When a method is invoked on proxyObj ,
 
Search WWH ::




Custom Search