1 8 package org.apache.avalon.excalibur.proxy; 9 10 import java.lang.reflect.InvocationHandler ; 11 import java.lang.reflect.InvocationTargetException ; 12 import java.lang.reflect.Method ; 13 import java.lang.reflect.Proxy ; 14 15 31 public final class DynamicProxy 32 implements InvocationHandler 33 { 34 private transient Object m_object; 35 36 41 private DynamicProxy( final Object object ) 42 { 43 m_object = object; 44 } 45 46 53 public static Object newInstance( final Object object ) 54 { 55 return newInstance( object, object.getClass().getInterfaces() ); 56 } 57 58 64 public static Object newInstance( final Object object, final Class [] interfaces ) 65 { 66 final ClassLoader classLoader = object.getClass().getClassLoader(); 67 final DynamicProxy proxy = new DynamicProxy( object ); 68 69 return Proxy.newProxyInstance( classLoader, interfaces, proxy ); 70 } 71 72 82 public Object invoke( final Object proxy, 83 final Method method, 84 final Object [] args ) 85 throws Throwable 86 { 87 try 88 { 89 return method.invoke( m_object, args ); 90 } 91 catch( final InvocationTargetException ite ) 92 { 93 throw ite.getTargetException(); 94 } 95 } 96 } 97 | Popular Tags |