1 16 package org.apache.axis.deployment.wsdd; 17 18 import org.apache.axis.AxisEngine; 19 import org.apache.axis.ConfigurationException; 20 import org.apache.axis.Constants; 21 import org.apache.axis.Handler; 22 import org.apache.axis.WSDDEngineConfiguration; 23 import org.apache.axis.components.logger.LogFactory; 24 import org.apache.axis.encoding.DeserializerFactory; 25 import org.apache.axis.encoding.SerializationContext; 26 import org.apache.axis.encoding.SerializerFactory; 27 import org.apache.axis.encoding.TypeMapping; 28 import org.apache.axis.encoding.TypeMappingRegistry; 29 import org.apache.axis.encoding.TypeMappingRegistryImpl; 30 import org.apache.axis.encoding.ser.ArraySerializerFactory; 31 import org.apache.axis.encoding.ser.BaseDeserializerFactory; 32 import org.apache.axis.encoding.ser.BaseSerializerFactory; 33 import org.apache.axis.handlers.soap.SOAPService; 34 import org.apache.axis.utils.Messages; 35 import org.apache.commons.logging.Log; 36 import org.w3c.dom.Element ; 37 38 import javax.xml.namespace.QName ; 39 import java.io.IOException ; 40 import java.util.ArrayList ; 41 import java.util.HashMap ; 42 import java.util.Hashtable ; 43 import java.util.Iterator ; 44 import java.util.List ; 45 46 52 public class WSDDDeployment 53 extends WSDDElement 54 implements WSDDTypeMappingContainer, 55 WSDDEngineConfiguration 56 { 57 protected static Log log = 58 LogFactory.getLog(WSDDDeployment.class.getName()); 59 private HashMap handlers = new HashMap (); 60 private HashMap services = new HashMap (); 61 private HashMap transports = new HashMap (); 62 private HashMap typeMappings = new HashMap (); 63 private WSDDGlobalConfiguration globalConfig = null; 64 67 private HashMap namespaceToServices = new HashMap (); 68 private AxisEngine engine; 69 70 protected void addHandler(WSDDHandler handler) { 71 handlers.put(handler.getQName(), handler); 72 } 73 74 protected void addService(WSDDService service) { 75 WSDDService oldService = (WSDDService) services.get(service.getQName()); 76 if (oldService != null) { 77 oldService.removeNamespaceMappings(this); 78 } 79 services.put(service.getQName(), service); 80 } 81 82 protected void addTransport(WSDDTransport transport) { 83 transports.put(transport.getQName(), transport); 84 } 85 86 92 public void deployHandler(WSDDHandler handler) { 93 handler.deployToRegistry(this); 94 } 95 96 102 public void deployTransport(WSDDTransport transport) { 103 transport.deployToRegistry(this); 104 } 105 106 112 public void deployService(WSDDService service) { 113 service.deployToRegistry(this); 114 } 115 116 121 public void undeployHandler(QName qname) { 122 handlers.remove(qname); 123 } 124 125 130 public void undeployService(QName qname) { 131 WSDDService service = (WSDDService) services.get(qname); 132 if (service != null) { 133 service.removeNamespaceMappings(this); 134 services.remove(qname); 135 } 136 } 137 138 143 public void undeployTransport(QName qname) { 144 transports.remove(qname); 145 } 146 147 public void deployTypeMapping(WSDDTypeMapping typeMapping) 148 throws WSDDException { 149 QName qname = typeMapping.getQName(); 150 String encoding = typeMapping.getEncodingStyle(); 151 typeMappings.put(qname + encoding, typeMapping); 154 if (tmrDeployed) 155 deployMapping(typeMapping); 156 } 157 158 161 public WSDDDeployment() { 162 } 163 164 170 public WSDDDeployment(Element e) 171 throws WSDDException { 172 super(e); 173 Element [] elements = getChildElements(e, ELEM_WSDD_HANDLER); 174 int i; 175 for (i = 0; i < elements.length; i++) { 176 WSDDHandler handler = new WSDDHandler(elements[i]); 177 deployHandler(handler); 178 } 179 elements = getChildElements(e, ELEM_WSDD_CHAIN); 180 for (i = 0; i < elements.length; i++) { 181 WSDDChain chain = new WSDDChain(elements[i]); 182 deployHandler(chain); 183 } 184 elements = getChildElements(e, ELEM_WSDD_TRANSPORT); 185 for (i = 0; i < elements.length; i++) { 186 WSDDTransport transport = new WSDDTransport(elements[i]); 187 deployTransport(transport); 188 } 189 elements = getChildElements(e, ELEM_WSDD_SERVICE); 190 for (i = 0; i < elements.length; i++) { 191 try { 192 WSDDService service = new WSDDService(elements[i]); 193 deployService(service); 194 } catch (WSDDNonFatalException ex) { 195 log.info(Messages.getMessage("ignoringNonFatalException00"), ex); 197 } catch (WSDDException ex) { 198 throw ex; 200 } 201 } 202 elements = getChildElements(e, ELEM_WSDD_TYPEMAPPING); 203 for (i = 0; i < elements.length; i++) { 204 try { 205 WSDDTypeMapping mapping = new WSDDTypeMapping(elements[i]); 206 deployTypeMapping(mapping); 207 } catch (WSDDNonFatalException ex) { 208 log.info(Messages.getMessage("ignoringNonFatalException00"), ex); 210 } catch (WSDDException ex) { 211 throw ex; 213 } 214 } 215 elements = getChildElements(e, ELEM_WSDD_BEANMAPPING); 216 for (i = 0; i < elements.length; i++) { 217 WSDDBeanMapping mapping = new WSDDBeanMapping(elements[i]); 218 deployTypeMapping(mapping); 219 } 220 221 elements = getChildElements(e, ELEM_WSDD_ARRAYMAPPING); 222 for (i = 0; i < elements.length; i++) { 223 WSDDArrayMapping mapping = 224 new WSDDArrayMapping(elements[i]); 225 deployTypeMapping(mapping); 226 } 227 228 Element el = getChildElement(e, ELEM_WSDD_GLOBAL); 229 if (el != null) 230 globalConfig = new WSDDGlobalConfiguration(el); 231 } 232 233 protected QName getElementName() { 234 return QNAME_DEPLOY; 235 } 236 237 public void deployToRegistry(WSDDDeployment target) 238 throws ConfigurationException { 239 WSDDGlobalConfiguration global = getGlobalConfiguration(); 240 if (global != null) { 241 target.setGlobalConfiguration(global); 242 } 243 Iterator i = handlers.values().iterator(); 244 while (i.hasNext()) { 245 WSDDHandler handler = (WSDDHandler) i.next(); 246 target.deployHandler(handler); 247 } 248 i = transports.values().iterator(); 249 while (i.hasNext()) { 250 WSDDTransport transport = (WSDDTransport) i.next(); 251 target.deployTransport(transport); 252 } 253 i = services.values().iterator(); 254 while (i.hasNext()) { 255 WSDDService service = (WSDDService) i.next(); 256 service.deployToRegistry(target); 257 } 258 i = typeMappings.values().iterator(); 259 while (i.hasNext()) { 260 WSDDTypeMapping mapping = (WSDDTypeMapping) i.next(); 261 target.deployTypeMapping(mapping); 262 } 263 } 264 265 private void deployMapping(WSDDTypeMapping mapping) 266 throws WSDDException { 267 try { 268 String encodingStyle = mapping.getEncodingStyle(); 269 if (encodingStyle == null) { 270 encodingStyle = Constants.URI_DEFAULT_SOAP_ENC; 271 } 272 TypeMapping tm = tmr.getOrMakeTypeMapping(encodingStyle); 273 SerializerFactory ser = null; 274 DeserializerFactory deser = null; 275 if (mapping.getSerializerName() != null && 285 !mapping.getSerializerName().equals("")) { 286 ser = BaseSerializerFactory.createFactory(mapping.getSerializer(), 287 mapping.getLanguageSpecificType(), 288 mapping.getQName()); 289 } 290 291 if ((mapping instanceof WSDDArrayMapping) && (ser instanceof ArraySerializerFactory)) { 292 WSDDArrayMapping am = (WSDDArrayMapping) mapping; 293 ArraySerializerFactory factory = (ArraySerializerFactory) ser; 294 factory.setComponentType(am.getInnerType()); 295 } 296 297 299 if (mapping.getDeserializerName() != null && 300 !mapping.getDeserializerName().equals("")) { 301 deser = BaseDeserializerFactory.createFactory(mapping.getDeserializer(), 302 mapping.getLanguageSpecificType(), 303 mapping.getQName()); 304 } 305 tm.register(mapping.getLanguageSpecificType(), mapping.getQName(), ser, deser); 307 } catch (ClassNotFoundException e) { 309 log.error(Messages.getMessage("unabletoDeployTypemapping00", mapping.getQName().toString()), e); 310 throw new WSDDNonFatalException(e); 311 } catch (Exception e) { 312 throw new WSDDException(e); 313 } 314 } 315 316 public void writeToContext(SerializationContext context) 317 throws IOException { 318 context.registerPrefixForURI(NS_PREFIX_WSDD, URI_WSDD); 319 context.registerPrefixForURI(NS_PREFIX_WSDD_JAVA, URI_WSDD_JAVA); 320 context.startElement(QNAME_DEPLOY, null); 321 if (globalConfig != null) { 322 globalConfig.writeToContext(context); 323 } 324 Iterator i = handlers.values().iterator(); 325 while (i.hasNext()) { 326 WSDDHandler handler = (WSDDHandler) i.next(); 327 handler.writeToContext(context); 328 } 329 i = services.values().iterator(); 330 while (i.hasNext()) { 331 WSDDService service = (WSDDService) i.next(); 332 service.writeToContext(context); 333 } 334 i = transports.values().iterator(); 335 while (i.hasNext()) { 336 WSDDTransport transport = (WSDDTransport) i.next(); 337 transport.writeToContext(context); 338 } 339 i = typeMappings.values().iterator(); 340 while (i.hasNext()) { 341 WSDDTypeMapping mapping = (WSDDTypeMapping) i.next(); 342 mapping.writeToContext(context); 343 } 344 context.endElement(); 345 } 346 347 352 public WSDDGlobalConfiguration getGlobalConfiguration() { 353 return globalConfig; 354 } 355 356 public void setGlobalConfiguration(WSDDGlobalConfiguration globalConfig) { 357 this.globalConfig = globalConfig; 358 } 359 360 363 public WSDDTypeMapping[] getTypeMappings() { 364 WSDDTypeMapping[] t = new WSDDTypeMapping[typeMappings.size()]; 365 typeMappings.values().toArray(t); 366 return t; 367 } 368 369 372 public WSDDService[] getServices() { 373 WSDDService [] serviceArray = new WSDDService[services.size()]; 374 services.values().toArray(serviceArray); 375 return serviceArray; 376 } 377 378 381 public WSDDService getWSDDService(QName qname) { 382 return (WSDDService) services.get(qname); 383 } 384 385 391 public Handler getHandler(QName name) throws ConfigurationException { 392 WSDDHandler h = (WSDDHandler) handlers.get(name); 393 if (h != null) { 394 return h.getInstance(this); 395 } 396 return null; 397 } 398 399 407 public Handler getTransport(QName name) throws ConfigurationException { 408 WSDDTransport t = (WSDDTransport) transports.get(name); 409 if (t != null) { 410 return t.getInstance(this); 411 } 412 return null; 413 } 414 415 424 public SOAPService getService(QName name) throws ConfigurationException { 425 WSDDService s = (WSDDService) services.get(name); 426 if (s != null) { 427 return (SOAPService) s.getInstance(this); 428 } 429 return null; 430 } 431 432 public SOAPService getServiceByNamespaceURI(String namespace) 433 throws ConfigurationException { 434 WSDDService s = (WSDDService) namespaceToServices.get(namespace); 435 if (s != null) { 436 return (SOAPService) s.getInstance(this); 437 } 438 return null; 439 } 440 441 public void configureEngine(AxisEngine engine) 442 throws ConfigurationException { 443 this.engine = engine; 444 } 445 446 public void writeEngineConfig(AxisEngine engine) throws ConfigurationException { 447 } 448 449 TypeMappingRegistry tmr = new TypeMappingRegistryImpl(); 450 451 public TypeMapping getTypeMapping(String encodingStyle) throws ConfigurationException { 452 return (TypeMapping) getTypeMappingRegistry().getTypeMapping(encodingStyle); 453 } 454 455 private boolean tmrDeployed = false; 456 457 public TypeMappingRegistry getTypeMappingRegistry() throws ConfigurationException { 458 if (false == tmrDeployed) { 459 Iterator i = typeMappings.values().iterator(); 460 while (i.hasNext()) { 461 WSDDTypeMapping mapping = (WSDDTypeMapping) i.next(); 462 deployMapping(mapping); 463 } 464 tmrDeployed = true; 465 } 466 return tmr; 467 } 468 469 public Handler getGlobalRequest() throws ConfigurationException { 470 if (globalConfig != null) { 471 WSDDRequestFlow reqFlow = globalConfig.getRequestFlow(); 472 if (reqFlow != null) 473 return reqFlow.getInstance(this); 474 } 475 return null; 476 } 477 478 public Handler getGlobalResponse() throws ConfigurationException { 479 if (globalConfig != null) { 480 WSDDResponseFlow respFlow = globalConfig.getResponseFlow(); 481 if (respFlow != null) 482 return respFlow.getInstance(this); 483 } 484 return null; 485 } 486 487 public Hashtable getGlobalOptions() throws ConfigurationException { 488 return globalConfig.getParametersTable(); 489 } 490 491 public List getRoles() { 492 return globalConfig == null ? new ArrayList () : globalConfig.getRoles(); 493 } 494 495 498 public Iterator getDeployedServices() throws ConfigurationException { 499 ArrayList serviceDescs = new ArrayList (); 500 for (Iterator i = services.values().iterator(); i.hasNext();) { 501 WSDDService service = (WSDDService) i.next(); 502 try { 503 service.makeNewInstance(this); 504 serviceDescs.add(service.getServiceDesc()); 505 } catch (WSDDNonFatalException ex) { 506 log.info(Messages.getMessage("ignoringNonFatalException00"), ex); 508 } 509 } 510 return serviceDescs.iterator(); 511 } 512 513 520 public void registerNamespaceForService(String namespace, 521 WSDDService service) { 522 namespaceToServices.put(namespace, service); 523 } 524 525 530 public void removeNamespaceMapping(String namespace) { 531 namespaceToServices.remove(namespace); 532 } 533 534 public AxisEngine getEngine() { 535 return engine; 536 } 537 538 public WSDDDeployment getDeployment() { 539 return this; 540 } 541 542 public WSDDHandler[] getHandlers() { 543 WSDDHandler [] handlerArray = new WSDDHandler[handlers.size()]; 544 handlers.values().toArray(handlerArray); 545 return handlerArray; 546 } 547 548 public WSDDHandler getWSDDHandler(QName qname) { 549 return (WSDDHandler) handlers.get(qname); 550 } 551 552 public WSDDTransport[] getTransports() { 553 WSDDTransport [] transportArray = new WSDDTransport[transports.size()]; 554 transports.values().toArray(transportArray); 555 return transportArray; 556 } 557 558 public WSDDTransport getWSDDTransport(QName qname) { 559 return (WSDDTransport) transports.get(qname); 560 } 561 } 562 | Popular Tags |