1 7 8 package org.jboss.net.axis; 10 11 13 import org.jboss.axis.ConfigurationException; 14 import org.jboss.axis.MessageContext; 15 import org.jboss.axis.deployment.wsdd.WSDDConstants; 16 import org.jboss.axis.deployment.wsdd.WSDDDeployment; 17 import org.jboss.axis.deployment.wsdd.WSDDException; 18 import org.jboss.axis.deployment.wsdd.WSDDProvider; 19 import org.jboss.axis.deployment.wsdd.WSDDService; 20 import org.jboss.axis.deployment.wsdd.WSDDTypeMapping; 21 import org.jboss.axis.encoding.TypeMappingRegistry; 22 import org.jboss.axis.handlers.soap.SOAPService; 23 import org.jboss.logging.Logger; 24 import org.w3c.dom.Element ; 25 26 import javax.xml.namespace.QName ; 27 import javax.xml.rpc.encoding.DeserializerFactory ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 60 61 public class Deployment extends WSDDDeployment 62 { 63 64 private static Logger log = Logger.getLogger(Deployment.class); 65 66 70 74 protected ClassLoader deploymentLoader; 75 76 79 protected List typeMappings = new java.util.ArrayList (); 80 81 84 protected boolean tmrCreated; 85 86 90 static 91 { 92 WSDDProvider.registerProvider(WSDDConstants.QNAME_HANDLER_PROVIDER, 93 new ServiceClassLoaderAwareWSDDHandlerProvider()); 94 } 95 96 100 111 112 protected Deployment(Element e, ClassLoader loader) throws WSDDException 113 { 114 super(e); 115 this.deploymentLoader = loader; 116 Element [] elements = getChildElements(e, "typeMapping"); 118 for (int i = 0; i < elements.length; i++) 119 { 120 TypeMapping mapping = new TypeMapping(elements[i]); 121 deployTypeMapping(mapping); 122 } 123 } 124 125 128 public static Deployment makeSafeDeployment(Element e, ClassLoader loader) throws WSDDException 129 { 130 ClassLoader old = Thread.currentThread().getContextClassLoader(); 131 Thread.currentThread().setContextClassLoader(loader); 132 try 133 { 134 return new Deployment(e, loader); 135 } 136 finally 137 { 138 Thread.currentThread().setContextClassLoader(old); 139 } 140 } 141 142 146 149 protected ClassLoader getDeploymentLoader() 150 { 151 return deploymentLoader; 152 } 153 154 157 protected static Deployment getDeployment(WSDDService service) 158 { 159 return ( 160 (Deployment)service.getParametersTable().get(Constants.SERVICE_DEPLOYMENT_PARAMETER)); 161 } 162 163 167 176 177 public void deployService(WSDDService service) 178 { 179 service.getParametersTable().put(Constants.SERVICE_DEPLOYMENT_PARAMETER, 184 this); 185 186 if (service.getHandlerInfoChain() != null && "true".equals(service.getParameter(Constants.USE_PROVIDER_HANDLER_CHAIN))) 188 { 189 service.getParametersTable().put(Constants.PROVIDER_HANDLER_CHAIN, service.getHandlerInfoChain()); 190 service.setParameter(Constants.USE_PROVIDER_HANDLER_CHAIN, "false"); 191 service.setHandlerInfoChain(null); 192 } 193 super.deployService(service); 194 } 195 196 199 public void deployTypeMapping(WSDDTypeMapping typeMapping) 200 throws WSDDException 201 { 202 if (typeMapping instanceof TypeMapping) 204 { 205 if (tmrCreated) 206 { 207 try 208 { 209 installTypeMappingWithOptions((TypeMapping)typeMapping); 210 } 211 catch (ConfigurationException e) 212 { 213 throw new WSDDException("Could not install type mapping with options." + e); 214 } 215 } 216 else 217 { 218 typeMappings.add(typeMapping); 219 } 220 } 221 } 222 223 232 233 public Iterator getDeployedServices() throws ConfigurationException 234 { 235 List serviceDescs = new java.util.ArrayList (); 236 WSDDService[] services = getServices(); 237 for (int count = 0; count < services.length; count++) 238 { 239 try 240 { 241 serviceDescs.add(getService(services[count].getQName()). 242 getServiceDescription()); 243 } 244 catch (ConfigurationException ex) 245 { 246 log.debug("Ingoring non-fatal exception: ", ex); 248 } 249 } 250 return serviceDescs.iterator(); 251 } 252 253 261 262 private SOAPService getServiceInternal(QName serviceName) 263 throws ConfigurationException 264 { 265 ClassLoader deploymentLoader = getDeploymentLoader(); 269 Thread.currentThread().setContextClassLoader(deploymentLoader); 270 271 MessageContext currentContext = MessageContext.getCurrentContext(); 272 if (currentContext != null) 273 currentContext.setClassLoader(deploymentLoader); 274 275 return super.getService(serviceName); 276 } 277 278 284 285 public SOAPService getService(QName serviceName) throws ConfigurationException 286 { 287 WSDDService wsddService = getWSDDService(serviceName); 289 if (wsddService != null) 290 { 291 return getDeployment(wsddService).getServiceInternal(serviceName); 294 } 295 return null; 296 } 297 298 304 305 public SOAPService getServiceByNamespaceURI(String arg0) 306 throws ConfigurationException 307 { 308 return null; 309 } 310 311 316 public void deployToRegistry(WSDDDeployment arg0) 317 throws ConfigurationException 318 { 319 super.deployToRegistry(arg0); 322 configureEngine(arg0.getEngine()); 324 getTypeMappingRegistry().delegate(arg0.getTypeMappingRegistry()); 327 } 328 329 330 333 public TypeMappingRegistry getTypeMappingRegistry() 334 throws ConfigurationException 335 { 336 if (!tmrCreated) 338 { 339 tmrCreated = true; 340 for (Iterator allTms = typeMappings.iterator(); allTms.hasNext();) 343 { 344 TypeMapping nextMapping = (TypeMapping)allTms.next(); 345 installTypeMappingWithOptions(nextMapping); 346 } 347 tmrCreated = true; 348 } 349 return super.getTypeMappingRegistry(); 351 } 352 353 356 protected void installTypeMappingWithOptions(TypeMapping nextMapping) throws ConfigurationException 357 { 358 ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); 359 Thread.currentThread().setContextClassLoader(getDeploymentLoader()); 360 try 361 { 362 super.deployTypeMapping(nextMapping); 364 org.jboss.axis.encoding.TypeMapping axisMapping = 366 (org.jboss.axis.encoding.TypeMapping)getTypeMappingRegistry() 367 .getTypeMapping(nextMapping.getEncodingStyle()); 368 DeserializerFactory dser = 369 axisMapping.getDeserializer(nextMapping.getQName()); 370 if (dser instanceof ParameterizableDeserializerFactory) 371 { 372 ((ParameterizableDeserializerFactory)dser).setOptions(((TypeMapping)nextMapping).getParametersTable()); 374 } 375 } 376 finally 377 { 378 Thread.currentThread().setContextClassLoader(oldLoader); 379 } 380 } 381 382 } | Popular Tags |