Dynamic method invocation on Proxy object?
- From: Sebastian <sebastian@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 08 Feb 2012 09:19:51 +0100
How can I dynamically invoke a method on a Proxy, where the method belongs to one of the proxied interfaces?
Normally (i. e. in the non-proxy case), one would do something like this:
protected Object invokeDelegated( Method m, Object[] args,
Object delegate ) throws Exception
{
// m is a method from an interface that is not implemented by delegate
// find the corresponding method in delegate interface and invoke
Class<?>[] parameterTypes = new Class[args.length];
for( int i = 0; i < args.length; i++ ) {
parameterTypes[i] = args[i].getClass();
}
Method meth = delegate.getClass().getMethod( m.getName(),
parameterTypes );
return meth.invoke( delegate, args );
}
However, when delegate is itself a proxy, then delegate.getClass() will give me Proxy, which is not what I'm looking for. How can I dynamically invoke the methods in the proxied interfaces?
-- Sebastian
.
- Follow-Ups:
- Re: Dynamic method invocation on Proxy object?
- From: Steven Simpson
- Re: Dynamic method invocation on Proxy object?
- Prev by Date: Re: Interplatform (interprocess, interlanguage) communication
- Next by Date: Re: Interplatform (interprocess, interlanguage) communication
- Previous by thread: packaging selenium code as jar
- Next by thread: Re: Dynamic method invocation on Proxy object?
- Index(es):