001    /*
002    @license.text@
003     */
004    
005    package biz.hammurapi.util;
006    
007    import java.lang.reflect.InvocationHandler;
008    import java.lang.reflect.Method;
009    import java.lang.reflect.Proxy;
010    
011    /**
012     * @author Pavel Vlasov 
013     * @version $Revision: 1.3 $
014     */
015    public class ProxyInvocationPump extends InvocationPump implements InvocationHandler {
016            private Object proxy;
017            private final Object obj;
018            
019            public ProxyInvocationPump(Object obj) {
020                    this.obj=obj;
021                    proxy=Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
022            }
023            
024            public Object getProxy() {
025                    return proxy;
026            }
027            
028            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
029                    Command command=new Command() {
030                            protected Object execute() throws Throwable {
031                                    return method.invoke(obj, args);
032                            }                       
033                    };
034                    
035                    return command.post();
036            }
037    }