1 23 package com.sun.enterprise.webservice; 24 25 import java.util.Hashtable ; 26 import java.util.Iterator ; 27 28 import java.lang.reflect.Proxy ; 29 import java.lang.reflect.InvocationHandler ; 30 31 import java.rmi.Remote ; 32 33 import javax.servlet.ServletConfig ; 34 import javax.servlet.ServletContext ; 35 36 import javax.xml.rpc.server.ServiceLifecycle ; 37 38 import com.sun.enterprise.Switch; 39 import com.sun.enterprise.ComponentInvocation; 40 import com.sun.enterprise.InvocationManager; 41 42 import com.sun.xml.rpc.spi.JaxRpcObjectFactory; 44 import com.sun.xml.rpc.spi.runtime.Implementor; 45 import com.sun.xml.rpc.spi.runtime.ImplementorCache; 46 import com.sun.xml.rpc.spi.runtime.ImplementorCacheDelegate; 47 import com.sun.xml.rpc.spi.runtime.RuntimeEndpointInfo; 48 import com.sun.xml.rpc.spi.runtime.Tie; 49 50 57 public class ImplementorCacheDelegateImpl extends ImplementorCacheDelegate { 58 59 private Hashtable implementorCache_; 60 private ServletContext servletContext_; 61 private JaxRpcObjectFactory rpcFactory_; 62 63 public ImplementorCacheDelegateImpl(ServletConfig servletConfig) { 64 servletContext_ = servletConfig.getServletContext(); 65 implementorCache_ = new Hashtable (); 66 rpcFactory_ = JaxRpcObjectFactory.newInstance(); 67 } 68 69 public Implementor getImplementorFor(RuntimeEndpointInfo targetEndpoint) { 70 71 Implementor implementor = null; 72 try { 73 synchronized(targetEndpoint) { 74 implementor = (Implementor) 75 implementorCache_.get(targetEndpoint); 76 if( implementor == null ) { 77 implementor = createImplementor(targetEndpoint); 78 implementorCache_.put(targetEndpoint, implementor); 79 } 80 } 81 82 InvocationManager invManager = 83 Switch.getSwitch().getInvocationManager(); 84 ComponentInvocation inv = invManager.getCurrentInvocation(); 85 inv.setWebServiceTie(implementor.getTie()); 86 87 } catch(Throwable t) { 88 95 RuntimeException re = new RuntimeException (); 96 re.initCause(t); 97 throw re; 98 } 99 100 return implementor; 101 } 102 103 public void releaseImplementor(RuntimeEndpointInfo targetEndpoint, 104 Implementor implementor) { 105 } 107 108 public void destroy() { 109 for (Iterator iter = implementorCache_.values().iterator(); 110 iter.hasNext();) { 111 Implementor implementor = (Implementor) iter.next(); 112 try { 113 implementor.destroy(); 114 } catch(Throwable t) { 115 } 117 } 118 implementorCache_.clear(); 119 } 120 121 private Implementor createImplementor(RuntimeEndpointInfo targetEndpoint) 122 throws Exception { 123 124 Tie tie = (Tie) targetEndpoint.getTieClass().newInstance(); 125 126 Class seiClass = targetEndpoint.getRemoteInterface(); 127 Class implClass = targetEndpoint.getImplementationClass(); 128 129 Remote servant = null; 130 if( seiClass.isAssignableFrom(implClass) ) { 131 servant = (Remote ) implClass.newInstance(); 134 } else { 135 Object implInstance = implClass.newInstance(); 139 140 InvocationHandler handler = 141 new ServletImplInvocationHandler(implInstance); 142 boolean implementsLifecycle = 143 ServiceLifecycle .class.isAssignableFrom(implClass); 144 Class [] proxyInterfaces = implementsLifecycle ? 145 new Class [] { seiClass, ServiceLifecycle .class } : 146 new Class [] { seiClass }; 147 148 servant = (Remote ) Proxy.newProxyInstance 149 (implClass.getClassLoader(), proxyInterfaces, handler); 150 } 151 tie.setTarget(servant); 152 153 Implementor implementor = rpcFactory_.createImplementor(servletContext_, tie); 154 implementor.init(); 155 156 return implementor; 157 } 158 } 159 | Popular Tags |