| 1 87 package org.codehaus.loom.components.application; 88 89 import java.lang.reflect.InvocationHandler ; 90 import java.lang.reflect.InvocationTargetException ; 91 import java.lang.reflect.Method ; 92 import java.lang.reflect.Proxy ; 93 94 112 final class BlockInvocationHandler 113 implements InvocationHandler  114 { 115 private transient Object m_object; 116 private transient Object m_proxy; 117 118 125 BlockInvocationHandler( final Object object, final Class [] interfaces ) 126 { 127 final ClassLoader classLoader = object.getClass().getClassLoader(); 128 129 m_object = object; 130 m_proxy = Proxy.newProxyInstance( classLoader, interfaces, this ); 131 } 132 133 136 public void invalidate() 137 { 138 m_object = null; 139 m_proxy = null; 140 } 141 142 147 public Object getProxy() 148 { 149 return m_proxy; 150 } 151 152 162 public Object invoke( final Object proxy, 163 final Method method, 164 final Object [] args ) 165 throws Throwable  166 { 167 if( null != m_object ) 168 { 169 try 170 { 171 return method.invoke( m_object, args ); 172 } 173 catch( final InvocationTargetException ite ) 174 { 175 throw ite.getTargetException(); 176 } 177 } 178 else 179 { 180 throw new IllegalStateException ( "Using a stale object reference " 181 + "to call a disposed Block." ); 182 } 183 } 184 } 185 | Popular Tags |