The code download for this chapter also includes a
README.txt file, which gives detailed steps to build and run the samples.
We will now look at the source code that can be found in the folder
ch13\JdkProxy\src.
Chapter 13
[ 241 ]
The files are explained here:
ch13\JdkProxy\src\SimpleIntf.java
public interface SimpleIntf
{
public void print();
}
SimpleIntf is a simple interface with a single method print. print does not accept
any parameters and also does not return any value. Our aim is that when we invoke
methods on the proxy object for SimpleIntf, the method invocation should be
turned into calls to an invocation handler's invoke method. Let us now define an
invocation handler in the following code:
ch13\JdkProxy\src\SimpleInvocationHandler.java
import java.lang.reflect.InvocationHandler;
import java.io.Serializable;
import java.lang.reflect.Method;
public class SimpleInvocationHandler implements InvocationHandler,
Serializable
{
public SimpleInvocationHandler(){}
public Object invoke(final Object obj, Method method,
Object[] args) throws Throwable
{
if (method.
Pages:
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335