getProxyClass with a class
loader and an array of interfaces for which you need to proxy, to get a Class
instance for the proxy. Proxy objects have one constructor, to which you pass an
InvocationHandler object associated with that proxy. When you invoke a method
on the proxy instance, the method invocation is encoded and dispatched to the
invoke method of its invocation handler. Let us also look at the InvocationHandler
API reproduced as follows:
package java.lang.reflect;
public interface InvocationHandler
{
Object invoke(Object proxy, Method method, Object[] args)
throws Throwable;
}
JBI Proxy
[ 240 ]
We need to implement this interface and provide code for the invoke method. Once
you get a Class instance for the proxy by invoking the Proxy.getProxyClass with a
class loader and an array of interfaces for which you need to proxy to. Now, you can
get a Constructor object for this proxy from the Class instance. On the constructor
you can use newInstance (passing in an invocation handler instance) to create the
proxy instance. The created instance should be implementing all the interfaces that
were passed to getProxyClass.
Pages:
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333