public abstract class DelegatingInvocationHandler extends Object implements InvocationHandler
DelegatingInvocationHandler handles a
method call by looking for a method in itself with identical parameters. If
no such method is found, it forwards the call to a fallback object, which
must implement all of the interfaces which this proxy implements.
It is useful in creating a wrapper class around an interface which may change over time.
Example:
import java.sql.Connection;
Connection connection = ...;
Connection tracingConnection = (Connection) Proxy.newProxyInstance(
null,
new Class[] {Connection.class},
new DelegatingInvocationHandler() {
protected Object getTarget() {
return connection;
}
Statement createStatement() {
System.out.println("statement created");
return connection.createStatement();
}
});
| Constructor and Description |
|---|
DelegatingInvocationHandler() |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke in interface InvocationHandlerThrowableprotected abstract Object getTarget()
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.