Package mondrian.util
Class DelegatingInvocationHandler
- java.lang.Object
-
- mondrian.util.DelegatingInvocationHandler
-
- All Implemented Interfaces:
InvocationHandler
- Direct Known Subclasses:
SqlStatement.MyDelegatingInvocationHandler
public abstract class DelegatingInvocationHandler extends Object implements InvocationHandler
A class derived fromDelegatingInvocationHandler
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(); } });
- Author:
- jhyde
-
-
Constructor Summary
Constructors Constructor Description DelegatingInvocationHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
getTarget()
Returns the object to forward method calls to, should the derived class not implement the method.Object
invoke(Object proxy, Method method, Object[] args)
-
-
-
Method Detail
-
invoke
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- Specified by:
invoke
in interfaceInvocationHandler
- Throws:
Throwable
-
getTarget
protected Object getTarget() throws InvocationTargetException
Returns the object to forward method calls to, should the derived class not implement the method. Generally, this object will be a member of the derived class, supplied as a parameter to its constructor.The default implementation returns null, which will cause the
invoke(Object, java.lang.reflect.Method, Object[])
method to throw anUnsupportedOperationException
if the derived class does not have the required method.- Returns:
- object to forward method calls to
- Throws:
InvocationTargetException
- if there is an error acquiring the target
-
-