import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; /** * CallInterceptionExampleProxyFactory - the dumbest proxy factory ever invented. Instantiate it with an * invocation handler and ask it. We'll get a simple proxy for that invocation handler. Remember our * invocation handler instances are associated with a concrete class. */ public class CallInterceptionExampleProxyFactory { private InvocationHandler invocationHandler = null; public CallInterceptionExampleProxyFactory(InvocationHandler ih) { this.invocationHandler = ih; } public Object createProxy( Class intrface ) { Class[] interfaces = new Class[] { intrface }; InvocationHandler ih = this.invocationHandler; //we'll also discuss classloaders some other time Object proxy = Proxy.newProxyInstance( this.getClass().getClassLoader(), interfaces, ih); return proxy; } }