InvocationHandler - Who get a handle on the Object?
Ladies and Gentlemen,
Once again, here am I, confused. I need explanation on the code outline below.
/****************************************************************************/
package typeinfo.proxy;
import java.lang.reflect.*;
import java.util.*;
public class DynamicProxy implements InvocationHandler
{
private Object server;
public DynamicProxy(Object server)
{
this.server = server;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
/* print the proxy instance class name, print the interface
method signature and print the method's arguments. */
System.out.print("\n Proxy: " + proxy.getClass() + "\n Method: " +
method + "\n");
if(args != null)
{
System.out.println(" Method arguments:");
for(Object arg : args)
{
System.out.println(" " + arg);
}
}
return method.invoke(server, args);
}
}
/****************************************************************************/
Notes:
1. This is only the proxy class. The interface, implemetation (server) and client programmes are not included here.
2. My interpretation of the programme is that the cleint programme makes an instance of the proxy, upcast this instance to the interface and calls a method on it. This automatically leads to invocation of the proxy instance's invoke( ) method which ultimately calls the appropriate method on the implementation object (server).
The invoke( ) method above is required to return an Object. My question is where is the object returned to?
method.invoke(server, args); I want this method invocation on the server to return an integer value that I would like to use in the client code. How do I get the proxy to fetch and subsequently release this value to the client?
Thank you.
ue_Joe.

