1 16 package org.apache.axis2.description; 17 18 import com.ibm.wsdl.extensions.soap.SOAPAddressImpl; 19 import com.ibm.wsdl.extensions.soap.SOAPConstants; 20 import org.apache.axis2.context.MessageContext; 21 import org.apache.axis2.context.ServiceContext; 22 import org.apache.axis2.engine.AxisFault; 23 import org.apache.axis2.phaseresolver.PhaseResolver; 24 import org.apache.wsdl.WSDLBindingOperation; 25 import org.apache.wsdl.WSDLEndpoint; 26 import org.apache.wsdl.WSDLExtensibilityElement; 27 import org.apache.wsdl.WSDLService; 28 import org.apache.wsdl.extensions.ExtensionConstants; 29 import org.apache.wsdl.extensions.SOAPOperation; 30 import org.apache.wsdl.impl.WSDLInterfaceImpl; 31 import org.apache.wsdl.impl.WSDLServiceImpl; 32 33 import javax.wsdl.*; 34 import javax.wsdl.extensions.ExtensibilityElement; 35 import javax.wsdl.extensions.soap.SOAPAddress; 36 import javax.wsdl.factory.WSDLFactory; 37 import javax.xml.namespace.QName ; 38 import java.io.IOException ; 39 import java.io.Writer ; 40 import java.util.*; 41 42 45 public class ServiceDescription 46 extends WSDLServiceImpl 47 implements WSDLService, ParameterInclude, FlowInclude, DescriptionConstants { 48 49 private Definition difDefinition = null; 51 52 57 59 private String serviceDescription = "Not Specified"; 60 61 64 public ServiceDescription() { 65 this.setComponentProperty(MODULEREF_KEY, new ArrayList()); 66 this.setComponentProperty(PARAMETER_KEY, new ParameterIncludeImpl()); 67 this.setServiceInterface( new WSDLInterfaceImpl()); 68 } 69 70 75 public ServiceDescription(QName qName) { 76 this(); 77 this.setName(qName); 78 } 79 80 85 86 91 public void engageModule(ModuleDescription moduleref) throws AxisFault { 92 if (moduleref == null) { 93 return; 94 } 95 if (moduleref != null) { 96 Collection collectionModule = (Collection) this.getComponentProperty(MODULEREF_KEY); 97 for (Iterator iterator = collectionModule.iterator(); iterator.hasNext();) { 98 ModuleDescription modu = (ModuleDescription) iterator.next(); 99 if(modu.getName().equals(moduleref.getName())){ 100 throw new AxisFault(moduleref.getName().getLocalPart()+ " module has alredy engaged to the seevice" + 101 " operation terminated !!!"); 102 } 103 104 } 105 } 106 new PhaseResolver().engageModuleToService(this,moduleref); 107 Collection collectionModule = (Collection) this.getComponentProperty(MODULEREF_KEY); 108 collectionModule.add(moduleref); 109 } 110 111 115 public void addModuleOperations(ModuleDescription module){ 116 HashMap map = module.getOperations(); 117 Collection col = map.values(); 118 for (Iterator iterator = col.iterator(); iterator.hasNext();) { 119 OperationDescription operation = (OperationDescription) iterator.next(); 120 this.addOperation(operation); 121 } 122 } 123 124 public void addToEngagModuleList(ModuleDescription moduleName){ 125 Collection collectionModule = (Collection) this.getComponentProperty(MODULEREF_KEY); 126 for (Iterator iterator = collectionModule.iterator(); iterator.hasNext();) { 127 ModuleDescription moduleDescription = (ModuleDescription) iterator.next(); 128 if(moduleName.getName().equals(moduleDescription.getName())){ 129 return; 130 } 131 } 132 collectionModule.add(moduleName); 133 } 134 135 140 141 146 public Collection getEngagedModules() { 147 return (Collection) this.getComponentProperty(MODULEREF_KEY); 148 } 149 150 156 public OperationDescription getOperation(QName operationName) { 157 String opStr = operationName.getLocalPart(); 158 159 HashMap allOperations = this.getServiceInterface().getAllOperations(); 160 return (OperationDescription) allOperations.get(opStr); 161 } 162 163 168 169 174 public void addOperation(OperationDescription operation) { 175 176 this.getServiceInterface().setOperation(operation); 177 } 178 179 184 185 190 public void setClassLoader(ClassLoader classLoader) { 191 if (classLoader != null) { 192 this.setComponentProperty(CLASSLOADER_KEY, classLoader); 193 } 194 } 195 196 201 202 207 public ClassLoader getClassLoader() { 208 return (ClassLoader ) this.getComponentProperty(CLASSLOADER_KEY); 209 } 210 211 216 217 222 public void setContextPath(String contextPath) { 223 if (contextPath != null) { 224 this.setComponentProperty(CONTEXTPATH_KEY, contextPath); 225 } 226 } 227 228 233 234 239 public String getContextPath() { 240 return (String ) this.getComponentProperty(CONTEXTPATH_KEY); 241 } 242 243 248 249 254 public void setStyle(String style) { 255 if (style != null) { 256 this.setComponentProperty(STYLE_KEY, style); 257 } 258 } 259 260 265 266 271 public String getStyle() { 272 return (String ) this.getComponentProperty(STYLE_KEY); 273 } 274 275 281 282 287 288 293 public void addParameter(Parameter param) { 294 if (param == null) { 295 return; 296 } 297 ParameterIncludeImpl paramInclude = 298 (ParameterIncludeImpl) this.getComponentProperty(PARAMETER_KEY); 299 paramInclude.addParameter(param); 300 } 301 302 307 308 314 public Parameter getParameter(String name) { 315 ParameterIncludeImpl paramInclude = 316 (ParameterIncludeImpl) this.getComponentProperty(PARAMETER_KEY); 317 return (Parameter) paramInclude.getParameter(name); 318 } 319 320 325 326 331 public Flow getInFlow() { 332 return (Flow) this.getComponentProperty(INFLOW_KEY); 333 } 334 335 340 341 346 public void setInFlow(Flow inFlow) { 347 if (inFlow != null) { 348 this.setComponentProperty(INFLOW_KEY, inFlow); 349 } 350 } 351 352 357 358 363 public Flow getOutFlow() { 364 return (Flow) this.getComponentProperty(OUTFLOW_KEY); 365 } 366 367 372 373 378 public void setOutFlow(Flow outFlow) { 379 if (outFlow != null) { 380 this.setComponentProperty(OUTFLOW_KEY, outFlow); 381 } 382 } 383 384 389 390 395 public Flow getFaultInFlow() { 396 return (Flow) this.getComponentProperty(IN_FAULTFLOW_KEY); 397 } 398 399 404 405 410 public void setFaultInFlow(Flow faultFlow) { 411 if (faultFlow != null) { 412 this.setComponentProperty(IN_FAULTFLOW_KEY, faultFlow); 413 } 414 } 415 416 public Flow getFaultOutFlow() { 417 return (Flow) this.getComponentProperty(OUT_FAULTFLOW_KEY); 418 } 419 420 public void setFaultOutFlow(Flow faultFlow) { 421 if (faultFlow != null) { 422 this.setComponentProperty(OUT_FAULTFLOW_KEY, faultFlow); 423 } 424 } 425 426 431 public HashMap getOperations() { 432 return this.getServiceInterface().getOperations(); 433 } 434 435 public OperationDescription getOperation(String ncName){ 436 return (OperationDescription)this.getServiceInterface().getOperations().get(ncName); 437 } 438 439 450 public OperationDescription getOperationBySOAPAction(String soapAction){ 451 Iterator iterator = this.getEndpoints().keySet().iterator(); 452 if(iterator.hasNext()){ 453 WSDLEndpoint endpoint = (WSDLEndpoint)this.getEndpoints().get(iterator.next()); 454 return this.getOperationBySOAPAction(soapAction, endpoint.getName()); 455 } 456 457 return null; 458 459 460 } 461 462 463 474 public OperationDescription getOperationBySOAPAction(String soapAction, QName endpoint){ 475 HashMap bindingOperations = this.getEndpoint(endpoint).getBinding().getBindingOperations(); 476 Iterator operationKeySetIterator = bindingOperations.keySet().iterator(); 477 OperationDescription operation = null; 478 int count = 0; 479 while(operationKeySetIterator.hasNext()){ 480 WSDLBindingOperation bindingOperation = (WSDLBindingOperation)bindingOperations.get(operationKeySetIterator.next()); 481 Iterator extIterator = bindingOperation.getExtensibilityElements().iterator(); 482 while(extIterator.hasNext()){ 483 WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next(); 484 if(element.getType().equals(ExtensionConstants.SOAP_OPERATION)){ 485 if(((SOAPOperation)element).getSoapAction().equals(soapAction)){ 486 operation = (OperationDescription)bindingOperation.getOperation(); 487 count++; 488 } 489 } 490 } 491 } 492 if(1 == count){ 493 return operation; 494 } 495 return null; 496 } 497 498 499 507 public ServiceContext findServiceContext(MessageContext msgContext) { 508 ServiceContext serviceContext = null; 509 if (null == msgContext.getServiceInstanceID()) { 510 serviceContext = new ServiceContext(this, msgContext.getSystemContext()); 511 } else { 515 serviceContext = 516 (ServiceContext) msgContext.getSystemContext().getServiceContext( 517 msgContext.getServiceInstanceID()); 518 } 519 520 return serviceContext; 521 522 } 523 524 528 public String getServiceDescription() { 529 return serviceDescription; 530 } 531 532 536 public void setServiceDescription(String serviceDescription) { 537 this.serviceDescription = serviceDescription; 538 } 539 540 public Definition getWSDLDefinition() { 541 return difDefinition; 542 } 543 544 public void setWSDLDefinition(Definition difDefinition) { 545 this.difDefinition = difDefinition; 546 } 547 548 public void printWSDL(Writer out, String PortURL)throws AxisFault{ 549 try { 550 Definition wsdlDefinition = this.getWSDLDefinition(); 551 if(wsdlDefinition !=null){ 552 Iterator sreviceitr = wsdlDefinition.getServices().keySet().iterator(); 553 while (sreviceitr.hasNext()) { 554 wsdlDefinition.removeService((QName )sreviceitr.next()); 555 } 556 557 559 Service service = wsdlDefinition.createService(); 560 service.setQName(this.getName()); 561 562 Port port = wsdlDefinition.createPort(); 563 SOAPAddress soapAddress = new SOAPAddressImpl(); 564 soapAddress.setElementType(SOAPConstants.Q_ELEM_SOAP_ADDRESS); 565 soapAddress.setLocationURI(PortURL); 566 port.addExtensibilityElement(soapAddress); 567 port.setName(this.getName().getLocalPart() + "Port"); 568 569 Map bindingsMap = wsdlDefinition.getBindings(); 570 Collection bind_col = bindingsMap.values(); 571 for (Iterator iterator = bind_col.iterator(); iterator.hasNext();) { 572 Binding binding = (Binding) iterator.next(); 573 port.setBinding(binding); 574 break; 575 } 576 service.addPort(port); 577 578 wsdlDefinition.addService(service); 579 WSDLFactory.newInstance().newWSDLWriter().writeWSDL(wsdlDefinition,out); 580 out.flush(); 581 } else { 582 WSDLFactory.newInstance().newWSDLWriter().writeWSDL(wsdlDefinition,out); 583 out.write("<wsdl>WSDL is NOT found</wsdl>"); 584 out.flush(); 585 } 586 587 588 589 } catch (WSDLException e) { 590 throw new AxisFault(e); 591 } catch (IOException e) { 592 throw new AxisFault(e); 593 } 594 } 595 596 } | Popular Tags |