1 55 package org.jboss.axis.deployment.wsdd; 56 57 import org.jboss.axis.AxisEngine; 58 import org.jboss.axis.ConfigurationException; 59 import org.jboss.axis.Constants; 60 import org.jboss.axis.Handler; 61 import org.jboss.axis.WSDDEngineConfiguration; 62 import org.jboss.axis.encoding.DeserializerFactory; 63 import org.jboss.axis.encoding.SerializationContext; 64 import org.jboss.axis.encoding.SerializerFactory; 65 import org.jboss.axis.encoding.TypeMapping; 66 import org.jboss.axis.encoding.TypeMappingRegistry; 67 import org.jboss.axis.encoding.TypeMappingRegistryImpl; 68 import org.jboss.axis.encoding.ser.BaseDeserializerFactory; 69 import org.jboss.axis.encoding.ser.BaseSerializerFactory; 70 import org.jboss.axis.handlers.soap.SOAPService; 71 import org.jboss.axis.utils.Messages; 72 import org.jboss.logging.Logger; 73 import org.w3c.dom.Element ; 74 75 import javax.xml.namespace.QName ; 76 import java.io.IOException ; 77 import java.util.ArrayList ; 78 import java.util.HashMap ; 79 import java.util.Hashtable ; 80 import java.util.Iterator ; 81 import java.util.Vector ; 82 83 84 90 public class WSDDDeployment 91 extends WSDDElement 92 implements WSDDTypeMappingContainer, 93 WSDDEngineConfiguration 94 { 95 private static Logger log = Logger.getLogger(WSDDDeployment.class.getName()); 96 97 private HashMap handlers = new HashMap (); 98 private HashMap services = new HashMap (); 99 private HashMap transports = new HashMap (); 100 private Vector typeMappings = new Vector (); 101 private WSDDGlobalConfiguration globalConfig = null; 102 103 106 private HashMap namespaceToServices = new HashMap (); 107 private AxisEngine engine; 108 109 protected void addHandler(WSDDHandler handler) 110 { 111 handlers.put(handler.getQName(), handler); 112 } 113 114 protected void addService(WSDDService service) 115 { 116 WSDDService oldService = (WSDDService)services.get(service.getQName()); 117 if (oldService != null) 118 { 119 oldService.removeNamespaceMappings(this); 120 } 121 services.put(service.getQName(), service); 122 } 123 124 protected void addTransport(WSDDTransport transport) 125 { 126 transports.put(transport.getQName(), transport); 127 } 128 129 130 136 public void deployHandler(WSDDHandler handler) 137 { 138 handler.deployToRegistry(this); 139 } 140 141 147 public void deployTransport(WSDDTransport transport) 148 { 149 transport.deployToRegistry(this); 150 } 151 152 158 public void deployService(WSDDService service) 159 { 160 service.deployToRegistry(this); 161 } 162 163 168 public void undeployHandler(QName qname) 169 { 170 handlers.remove(qname); 171 } 172 173 178 public void undeployService(QName qname) 179 { 180 WSDDService service = (WSDDService)services.get(qname); 181 if (service != null) 182 { 183 service.removeNamespaceMappings(this); 184 services.remove(qname); 185 } 186 } 187 188 193 public void undeployTransport(QName qname) 194 { 195 transports.remove(qname); 196 } 197 198 public void deployTypeMapping(WSDDTypeMapping typeMapping) 199 throws WSDDException 200 { 201 if (!typeMappings.contains(typeMapping)) 202 { 203 typeMappings.add(typeMapping); 204 } 205 if (tmrDeployed) 206 deployMapping(typeMapping); 207 } 208 209 212 public WSDDDeployment() 213 { 214 } 215 216 222 public WSDDDeployment(Element e) 223 throws WSDDException 224 { 225 super(e); 226 227 Element [] elements = getChildElements(e, ELEM_WSDD_HANDLER); 228 int i; 229 230 for (i = 0; i < elements.length; i++) 231 { 232 WSDDHandler handler = new WSDDHandler(elements[i]); 233 deployHandler(handler); 234 } 235 236 elements = getChildElements(e, ELEM_WSDD_CHAIN); 237 for (i = 0; i < elements.length; i++) 238 { 239 WSDDChain chain = new WSDDChain(elements[i]); 240 deployHandler(chain); 241 } 242 243 elements = getChildElements(e, ELEM_WSDD_TRANSPORT); 244 for (i = 0; i < elements.length; i++) 245 { 246 WSDDTransport transport = new WSDDTransport(elements[i]); 247 deployTransport(transport); 248 } 249 250 elements = getChildElements(e, ELEM_WSDD_SERVICE); 251 for (i = 0; i < elements.length; i++) 252 { 253 try 254 { 255 WSDDService service = new WSDDService(elements[i]); 256 deployService(service); 257 } 258 catch (WSDDNonFatalException ex) 259 { 260 } 262 catch (WSDDException ex) 263 { 264 throw ex; 266 } 267 } 268 269 elements = getChildElements(e, ELEM_WSDD_TYPEMAPPING); 270 for (i = 0; i < elements.length; i++) 271 { 272 try 273 { 274 WSDDTypeMapping mapping = new WSDDTypeMapping(elements[i]); 275 deployTypeMapping(mapping); 276 } 277 catch (WSDDNonFatalException ex) 278 { 279 } 281 catch (WSDDException ex) 282 { 283 throw ex; 285 } 286 } 287 288 elements = getChildElements(e, ELEM_WSDD_BEANMAPPING); 289 for (i = 0; i < elements.length; i++) 290 { 291 WSDDBeanMapping mapping = new WSDDBeanMapping(elements[i]); 292 deployTypeMapping(mapping); 293 } 294 295 Element el = getChildElement(e, ELEM_WSDD_GLOBAL); 296 if (el != null) 297 globalConfig = new WSDDGlobalConfiguration(el); 298 } 299 300 protected QName getElementName() 301 { 302 return QNAME_DEPLOY; 303 } 304 305 public void deployToRegistry(WSDDDeployment target) 306 throws ConfigurationException 307 { 308 309 WSDDGlobalConfiguration global = getGlobalConfiguration(); 310 311 if (global != null) 312 { 313 target.setGlobalConfiguration(global); 314 } 315 316 Iterator i = handlers.values().iterator(); 317 while (i.hasNext()) 318 { 319 WSDDHandler handler = (WSDDHandler)i.next(); 320 target.deployHandler(handler); 321 } 322 323 i = transports.values().iterator(); 324 while (i.hasNext()) 325 { 326 WSDDTransport transport = (WSDDTransport)i.next(); 327 target.deployTransport(transport); 328 } 329 330 i = services.values().iterator(); 331 while (i.hasNext()) 332 { 333 WSDDService service = (WSDDService)i.next(); 334 service.deployToRegistry(target); 335 } 336 337 i = typeMappings.iterator(); 338 while (i.hasNext()) 339 { 340 WSDDTypeMapping mapping = (WSDDTypeMapping)i.next(); 341 target.deployTypeMapping(mapping); 342 } 343 } 344 345 private void deployMapping(WSDDTypeMapping mapping) 346 throws WSDDException 347 { 348 try 349 { 350 String encodingStyle = mapping.getEncodingStyle(); 351 if (encodingStyle == null) 352 { 353 encodingStyle = Constants.URI_DEFAULT_SOAP_ENC; 354 } 355 TypeMapping tm = tmr.getOrMakeTypeMapping(encodingStyle); 356 357 SerializerFactory ser = null; 358 DeserializerFactory deser = null; 359 360 if (mapping.getSerializerName() != null && 370 !mapping.getSerializerName().equals("")) 371 { 372 ser = BaseSerializerFactory.createFactory(mapping.getSerializer(), 373 mapping.getLanguageSpecificType(), 374 mapping.getQName()); 375 } 376 378 if (mapping.getDeserializerName() != null && 379 !mapping.getDeserializerName().equals("")) 380 { 381 deser = BaseDeserializerFactory.createFactory(mapping.getDeserializer(), 382 mapping.getLanguageSpecificType(), 383 mapping.getQName()); 384 } 385 tm.register(mapping.getLanguageSpecificType(), mapping.getQName(), ser, deser); 387 } 389 catch (ClassNotFoundException e) 390 { 391 log.error(Messages.getMessage("unabletoDeployTypemapping00", mapping.getQName().toString()), e); 392 throw new WSDDNonFatalException(e); 393 } 394 catch (Exception e) 395 { 396 throw new WSDDException(e); 397 } 398 } 399 400 public void writeToContext(SerializationContext context) 401 throws IOException 402 { 403 context.registerPrefixForURI(NS_PREFIX_WSDD, URI_WSDD); 404 405 context.registerPrefixForURI(NS_PREFIX_WSDD_JAVA, URI_WSDD_JAVA); 406 407 context.startElement(QNAME_DEPLOY, null); 408 409 if (globalConfig != null) 410 { 411 globalConfig.writeToContext(context); 412 } 413 414 Iterator i = handlers.values().iterator(); 415 while (i.hasNext()) 416 { 417 WSDDHandler handler = (WSDDHandler)i.next(); 418 handler.writeToContext(context); 419 } 420 421 i = services.values().iterator(); 422 while (i.hasNext()) 423 { 424 WSDDService service = (WSDDService)i.next(); 425 service.writeToContext(context); 426 } 427 428 i = transports.values().iterator(); 429 while (i.hasNext()) 430 { 431 WSDDTransport transport = (WSDDTransport)i.next(); 432 transport.writeToContext(context); 433 } 434 435 i = typeMappings.iterator(); 436 while (i.hasNext()) 437 { 438 WSDDTypeMapping mapping = (WSDDTypeMapping)i.next(); 439 mapping.writeToContext(context); 440 } 441 context.endElement(); 442 } 443 444 449 public WSDDGlobalConfiguration getGlobalConfiguration() 450 { 451 return globalConfig; 452 } 453 454 public void setGlobalConfiguration(WSDDGlobalConfiguration globalConfig) 455 { 456 this.globalConfig = globalConfig; 457 } 458 459 462 public WSDDTypeMapping[] getTypeMappings() 463 { 464 WSDDTypeMapping[] t = new WSDDTypeMapping[typeMappings.size()]; 465 typeMappings.toArray(t); 466 return t; 467 } 468 469 472 public WSDDService[] getServices() 473 { 474 WSDDService[] serviceArray = new WSDDService[services.size()]; 475 services.values().toArray(serviceArray); 476 return serviceArray; 477 } 478 479 482 public WSDDService getWSDDService(QName qname) 483 { 484 return (WSDDService)services.get(qname); 485 } 486 487 491 public Handler getHandler(QName name) throws ConfigurationException 492 { 493 WSDDHandler h = (WSDDHandler)handlers.get(name); 494 if (h != null) 495 { 496 return h.getInstance(this); 497 } 498 499 return null; 500 } 501 502 506 public Handler getTransport(QName name) throws ConfigurationException 507 { 508 WSDDTransport t = (WSDDTransport)transports.get(name); 509 if (t != null) 510 { 511 return t.getInstance(this); 512 } 513 514 return null; 515 } 516 517 521 public SOAPService getService(QName name) throws ConfigurationException 522 { 523 WSDDService s = (WSDDService)services.get(name); 524 if (s != null) 525 { 526 return (SOAPService)s.getInstance(this); 527 } 528 529 return null; 530 } 531 532 public SOAPService getServiceByNamespaceURI(String namespace) 533 throws ConfigurationException 534 { 535 WSDDService s = (WSDDService)namespaceToServices.get(namespace); 536 if (s != null) 537 { 538 return (SOAPService)s.getInstance(this); 539 } 540 541 return null; 542 } 543 544 public void configureEngine(AxisEngine engine) 545 throws ConfigurationException 546 { 547 this.engine = engine; 548 } 549 550 public void writeEngineConfig(AxisEngine engine) throws ConfigurationException 551 { 552 } 553 554 TypeMappingRegistry tmr = new TypeMappingRegistryImpl(); 555 556 public TypeMapping getTypeMapping(String encodingStyle) throws ConfigurationException 557 { 558 return (TypeMapping)getTypeMappingRegistry().getTypeMapping(encodingStyle); 559 } 560 561 private boolean tmrDeployed = false; 562 563 public TypeMappingRegistry getTypeMappingRegistry() throws ConfigurationException 564 { 565 if (false == tmrDeployed) 566 { 567 for (int i = 0; i < typeMappings.size(); i++) 568 { 569 WSDDTypeMapping mapping = (WSDDTypeMapping)typeMappings.get(i); 570 deployMapping(mapping); 571 } 572 tmrDeployed = true; 573 } 574 return tmr; 575 } 576 577 public Handler getGlobalRequest() throws ConfigurationException 578 { 579 if (globalConfig != null) 580 { 581 WSDDRequestFlow reqFlow = globalConfig.getRequestFlow(); 582 if (reqFlow != null) 583 return reqFlow.getInstance(this); 584 } 585 586 return null; 587 } 588 589 public Handler getGlobalResponse() throws ConfigurationException 590 { 591 if (globalConfig != null) 592 { 593 WSDDResponseFlow respFlow = globalConfig.getResponseFlow(); 594 if (respFlow != null) 595 return respFlow.getInstance(this); 596 } 597 598 return null; 599 } 600 601 public Hashtable getGlobalOptions() throws ConfigurationException 602 { 603 return globalConfig.getParametersTable(); 604 } 605 606 609 public Iterator getDeployedServices() throws ConfigurationException 610 { 611 ArrayList serviceDescs = new ArrayList (); 612 for (Iterator i = services.values().iterator(); i.hasNext();) 613 { 614 WSDDService service = (WSDDService)i.next(); 615 try 616 { 617 service.makeNewInstance(this); 618 serviceDescs.add(service.getServiceDesc()); 619 } 620 catch (WSDDNonFatalException ex) 621 { 622 log.debug("Ingoring non-fatal exception: ", ex); 624 } 625 } 626 return serviceDescs.iterator(); 627 } 628 629 636 public void registerNamespaceForService(String namespace, 637 WSDDService service) 638 { 639 namespaceToServices.put(namespace, service); 640 } 641 642 647 public void removeNamespaceMapping(String namespace) 648 { 649 namespaceToServices.remove(namespace); 650 } 651 652 public AxisEngine getEngine() 653 { 654 return engine; 655 } 656 657 public WSDDDeployment getDeployment() 658 { 659 return this; 660 } 661 } 662 | Popular Tags |