1 9 package org.jboss.portal.test.portal; 10 11 import java.lang.reflect.InvocationHandler ; 12 import java.lang.reflect.InvocationTargetException ; 13 import java.lang.reflect.Method ; 14 import java.lang.reflect.Proxy ; 15 16 20 public class ProxyDelegate 21 { 22 public Object createProxy(Class itf) 23 { 24 InvocationHandler ih = new InvocationHandler () 25 { 26 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 27 { 28 try 29 { 30 Class implementorClass = ProxyDelegate.this.getClass(); 31 Method implementedMethod = implementorClass.getMethod(method.getName(), method.getParameterTypes()); 32 return implementedMethod.invoke(ProxyDelegate.this, args); 33 } 34 catch (NoSuchMethodException e) 35 { 36 throw new UnsupportedOperationException (); 37 } 38 catch (InvocationTargetException e) 39 { 40 throw e.getTargetException(); 41 } 42 catch (Exception e) 43 { 44 throw new RuntimeException (); 45 } 46 } 47 }; 48 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class []{itf}, ih); 49 } 50 } 51 | Popular Tags |