1 17 18 package org.apache.geronimo.connector; 19 20 import java.io.Serializable ; 21 import java.lang.reflect.Method ; 22 23 import net.sf.cglib.proxy.MethodInterceptor; 24 import net.sf.cglib.proxy.MethodProxy; 25 import org.apache.geronimo.kernel.KernelRegistry; 26 import org.apache.geronimo.kernel.Kernel; 27 import org.apache.geronimo.kernel.proxy.DeadProxyException; 28 import org.apache.geronimo.gbean.AbstractName; 29 30 37 public class ConnectorMethodInterceptor implements MethodInterceptor, Serializable { 38 private static final long serialVersionUID = -3062915319296676033L; 39 private final String kernelName; 40 private final AbstractName targetName; 41 42 private transient Object internalProxy; 43 44 public ConnectorMethodInterceptor(String kernelName, AbstractName targetName) { 45 this.kernelName = kernelName; 46 this.targetName = targetName; 47 } 48 49 public Object intercept(final Object o, final Method method, Object [] objects, final MethodProxy methodProxy) throws Throwable { 50 if (internalProxy == null) { 51 connectInternalProxy(); 52 } 53 try { 54 return methodProxy.invoke(internalProxy, objects); 55 } catch (DeadProxyException e) { 56 connectInternalProxy(); 57 return methodProxy.invoke(internalProxy, objects); 58 } 59 } 60 61 public void setInternalProxy(final Object internalProxy) { 62 this.internalProxy = internalProxy; 63 } 64 65 private void connectInternalProxy() throws Throwable { 66 Kernel kernel = KernelRegistry.getKernel(kernelName); 67 try { 68 internalProxy = kernel.invoke(targetName, "$getConnectionFactory"); 69 } catch (Exception e) { 70 throw new IllegalStateException ("Could not connect proxy to ManagedConnectionFactoryWrapper").initCause(e); 71 } 72 } 73 } 74 | Popular Tags |