1 8 package org.apache.avalon.phoenix.components.application; 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 32 final class BlockInvocationHandler 33 implements InvocationHandler 34 { 35 private transient Object m_object; 36 37 private transient Object m_proxy; 38 39 45 protected BlockInvocationHandler( final Object object, final Class [] interfaces ) 46 { 47 final ClassLoader classLoader = object.getClass().getClassLoader(); 48 49 m_object = object; 50 m_proxy = Proxy.newProxyInstance( classLoader, interfaces, this ); 51 } 52 53 57 public void invalidate() 58 { 59 m_object = null; 60 m_proxy = null; 61 } 62 63 68 public Object getProxy() 69 { 70 return m_proxy; 71 } 72 73 83 public Object invoke( final Object proxy, 84 final Method method, 85 final Object [] args ) 86 throws Throwable 87 { 88 if( null != m_object ) 89 { 90 try 91 { 92 return method.invoke( m_object, args ); 93 } 94 catch( final InvocationTargetException ite ) 95 { 96 throw ite.getTargetException(); 97 } 98 } 99 else 100 { 101 throw new IllegalStateException ( "Using a stale object reference " 102 + "to call a disposed Block." ); 103 } 104 } 105 } 106
| Popular Tags
|