org.apache.commons.proxy.invoker
Class DuckTypingInvoker
java.lang.Object
org.apache.commons.proxy.invoker.DuckTypingInvoker
- All Implemented Interfaces:
- Invoker
public class DuckTypingInvoker
- extends Object
- implements Invoker
An invoker which supports "duck typing", meaning
that it finds a matching method on the object returned from the target provider and invokes it. This class is
useful for adapting an existing class to an interface it does not implement.
Example:
public class LegacyDuck // Does not implement interface!
{
public void quack()
{
// Quacking logic...
}
}
public interface Duck
{
public void quack();
}
ObjectProvider targetProvider = new ConstantProvider(new LegacyDuck()); // Always returns a "legacy" duck
DuckTypingInvoker invoker = new DuckTypingInvoker(targetProvider);
Duck duck = ( Duck )proxyFactory.createInvokerProxy( invoker, new Class[] { Duck.class } );
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DuckTypingInvoker
public DuckTypingInvoker(ObjectProvider targetProvider)
invoke
public Object invoke(Object proxy,
Method method,
Object[] arguments)
throws Throwable
- Description copied from interface:
Invoker
- "Invokes" the method. Implementation should throw a
InvokerException
if problems arise while trying to invoke the method.
- Specified by:
invoke
in interface Invoker
- Parameters:
proxy
- the proxy objectmethod
- the method being invokedarguments
- the arguments
- Returns:
- the return value
- Throws:
Throwable
- thrown by the implementation
Copyright © 2005-2008 The Apache Software Foundation. All Rights Reserved.