1 package org.apache.axis2.wsdl.codegen.emitter; 2 3 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration; 4 import org.apache.axis2.wsdl.codegen.CodeGenerationException; 5 import org.apache.axis2.wsdl.codegen.Constants; 6 import org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder; 7 import org.apache.axis2.wsdl.codegen.writer.*; 8 import org.apache.axis2.wsdl.databinding.TypeMapper; 9 import org.apache.crimson.tree.XmlDocument; 10 import org.apache.wsdl.*; 11 import org.apache.wsdl.extensions.ExtensionConstants; 12 import org.apache.wsdl.extensions.SOAPBody; 13 import org.apache.wsdl.extensions.SOAPOperation; 14 import org.w3c.dom.Attr ; 15 import org.w3c.dom.Element ; 16 import org.w3c.dom.Text ; 17 18 import java.io.ByteArrayInputStream ; 19 import java.io.ByteArrayOutputStream ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 28 29 60 61 62 public abstract class MultiLanguageClientEmitter implements Emitter{ 63 private static final String CALL_BACK_HANDLER_SUFFIX = "CallbackHandler"; 64 private static final String STUB_SUFFIX = "Stub"; 65 private static final String TEST_SUFFIX = "Test"; 66 private static final String LOCAL_TEST_SUFFIX = "LocalTest"; 67 private static final String SERVICE_CLASS_SUFFIX ="Skeleton"; 68 private static final String TEST_PACKAGE_NAME_SUFFIX =".test"; 69 private static final String DATABINDING_SUPPORTER_NAME_SUFFIX ="DatabindingSupporter"; 70 private static final String DATABINDING_PACKAGE_NAME_SUFFIX =".databinding"; 71 private static final String TEST_SERVICE_CLASS_NAME_SUFFIX ="SkeletonTest"; 72 private static final String MESSAGE_RECEIVER_SUFFIX = "MessageReceiver"; 73 74 75 protected InputStream xsltStream = null; 76 protected CodeGenConfiguration configuration; 77 protected TypeMapper mapper; 78 79 84 public void setMapper(TypeMapper mapper) { 85 this.mapper = mapper; 86 } 87 88 92 public void setCodeGenConfiguration(CodeGenConfiguration configuration) { 93 this.configuration = configuration; 94 } 95 96 100 public void emitStub() throws CodeGenerationException { 101 try { 102 WSDLDescription wom = this.configuration.getWom(); 104 WSDLBinding axisBinding = wom.getBinding(AxisBindingBuilder.AXIS_BINDING_QNAME); 105 WSDLService axisService = null; 106 Map services = wom.getServices(); 108 if (!services.isEmpty()) { 109 if (services.size()==1){ 110 axisService = (WSDLService)services.values().toArray()[0]; 111 }else{ 112 throw new UnsupportedOperationException ("Single service WSDL files only"); 113 } 114 } 115 testCompatibiltyAll(axisBinding); 117 writeInterface(axisBinding); 119 writeInterfaceImplementation(axisBinding,axisService); 121 writeCallBackHandlers(axisBinding); 123 writeDatabindingSupporters(axisBinding); 127 } catch (Exception e) { 132 e.printStackTrace(); 133 throw new CodeGenerationException(e); 134 } 135 } 136 137 138 protected void writeTestSkeletonImpl(WSDLBinding binding)throws Exception { 139 if (configuration.isWriteTestCase()){ 140 XmlDocument classModel = createDocumentForTestSkeletonImpl(binding); 141 TestSkeletonImplWriter callbackWriter = 142 new TestSkeletonImplWriter(this.configuration.getOutputLocation(), 143 this.configuration.getOutputLanguage() 144 ); 145 writeClass(classModel,callbackWriter); 146 } 147 } 148 149 152 protected void writeCallBackHandlers(WSDLBinding binding) throws Exception { 153 154 if (configuration.isAsyncOn()){ 155 XmlDocument interfaceModel = createDOMDocumentForCallbackHandler(binding); 156 CallbackHandlerWriter callbackWriter = 157 new CallbackHandlerWriter(this.configuration.getOutputLocation(), 158 this.configuration.getOutputLanguage() 159 ); 160 writeClass(interfaceModel,callbackWriter); 161 } 162 163 } 164 165 172 protected void writeLocalTestClasses(WSDLBinding binding) throws Exception { 173 174 if (configuration.isWriteTestCase()){ 175 XmlDocument classModel = createDOMDocuementForLocalTestCase(binding); 176 LocalTestClassWriter callbackWriter = 177 new LocalTestClassWriter(this.configuration.getOutputLocation(), 178 this.configuration.getOutputLanguage() 179 ); 180 writeClass(classModel,callbackWriter); 181 } 182 } 183 186 protected void writeTestClasses(WSDLBinding binding) throws Exception { 187 188 if (configuration.isWriteTestCase()){ 189 XmlDocument classModel = createDOMDocuementForTestCase(binding); 190 TestClassWriter callbackWriter = 191 new TestClassWriter(this.configuration.getOutputLocation(), 192 this.configuration.getOutputLanguage() 193 ); 194 writeClass(classModel,callbackWriter); 195 } 196 197 } 198 203 protected void writeInterface(WSDLBinding axisBinding) throws Exception { 204 XmlDocument interfaceModel = createDOMDocuementForInterface(axisBinding); 205 InterfaceWriter interfaceWriter = 206 new InterfaceWriter(this.configuration.getOutputLocation(), 207 this.configuration.getOutputLanguage() 208 ); 209 writeClass(interfaceModel,interfaceWriter); 210 } 211 212 217 protected void writeSkeleton(WSDLBinding axisBinding) throws Exception { 218 219 XmlDocument skeletonModel = createDOMDocuementForSkeleton(axisBinding); 221 ClassWriter skeletonWriter = new SkeletonWriter(this.configuration.getOutputLocation(), 222 this.configuration.getOutputLanguage() 223 ); 224 writeClass(skeletonModel,skeletonWriter); 225 226 227 } 228 229 234 protected void writeDatabindingSupporters(WSDLBinding axisBinding) throws Exception { 235 Collection col = axisBinding.getBoundInterface().getOperations().values(); 236 for (Iterator iterator = col.iterator(); iterator.hasNext();) { 237 XmlDocument databindingSupporterModel = createDOMDocumentforSerialization((WSDLOperation)iterator.next()); 240 ClassWriter databindingSupportWriter = new DatabindingSupportClassWriter(this.configuration.getOutputLocation(), 241 this.configuration.getOutputLanguage(),this.configuration.getDatabindingType() 242 ); 243 writeClass(databindingSupporterModel,databindingSupportWriter); 244 } 245 246 } 247 248 protected void writeTestServiceXML(WSDLBinding axisBinding) throws Exception { 249 if (this.configuration.isWriteTestCase()){ 250 XmlDocument skeletonModel = createDOMDocuementForServiceXML(axisBinding, true); 252 TestServiceXMLWriter testServiceXmlWriter = new TestServiceXMLWriter(this.configuration.getOutputLocation(), 253 this.configuration.getOutputLanguage() 254 ); 255 writeClass(skeletonModel,testServiceXmlWriter); 256 } 257 } 258 259 264 protected void writeServiceXml(WSDLBinding axisBinding) throws Exception { 265 if (this.configuration.isGenerateDeployementDescriptor()){ 266 XmlDocument skeletonModel = createDOMDocuementForServiceXML(axisBinding, false); 267 ClassWriter serviceXmlWriter = new ServiceXMLWriter(this.configuration.getOutputLocation(), 268 this.configuration.getOutputLanguage() 269 ); 270 writeClass(skeletonModel,serviceXmlWriter); 271 } 272 } 273 274 275 280 protected void writeInterfaceImplementation(WSDLBinding axisBinding,WSDLService service) throws Exception { 281 XmlDocument interfaceImplModel = createDOMDocuementForInterfaceImplementation(axisBinding, service); 282 InterfaceImplementationWriter writer = 283 new InterfaceImplementationWriter(this.configuration.getOutputLocation(), 284 this.configuration.getOutputLanguage() 285 ); 286 writeClass(interfaceImplModel,writer); 287 } 288 289 protected void writeMessageReceiver(WSDLBinding axisBinding)throws Exception { 290 if (configuration.isWriteMessageReceiver()){ 291 XmlDocument classModel = createDocumentForMessageReceiver(axisBinding); 292 MessageReceiverWriter writer = 293 new MessageReceiverWriter(this.configuration.getOutputLocation(), 294 this.configuration.getOutputLanguage() 295 ); 296 writeClass(classModel,writer); 297 } 298 } 299 300 305 protected void writeBeans(WSDLTypes wsdlType) throws Exception { 306 Collection collection= wsdlType.getExtensibilityElements(); 307 if (collection != null){ 308 for (Iterator iterator = collection.iterator(); iterator.hasNext();) { 309 XmlDocument interfaceModel = createDOMDocuementForBean(); 310 BeanWriter beanWriter = 311 new BeanWriter(this.configuration.getOutputLocation(), 312 this.configuration.getOutputLanguage() 313 ); 314 writeClass(interfaceModel,beanWriter); 315 } 316 } 317 318 } 319 326 protected void writeClass(XmlDocument model,ClassWriter writer) throws IOException ,Exception { 327 ByteArrayOutputStream memoryStream = new ByteArrayOutputStream (); 328 model.write(memoryStream); 329 writer.loadTemplate(); 330 writer.createOutFile(model.getDocumentElement().getAttribute("package"), 331 model.getDocumentElement().getAttribute("name")); 332 writer.writeOutFile(new ByteArrayInputStream (memoryStream.toByteArray())); 333 } 334 335 338 public void emitSkeleton() throws CodeGenerationException { 339 try { 340 WSDLBinding axisBinding = this.configuration.getWom().getBinding(AxisBindingBuilder.AXIS_BINDING_QNAME); 342 testCompatibiltyAll(axisBinding); 344 writeSkeleton(axisBinding); 346 writeServiceXml(axisBinding); 348 writeTestSkeletonImpl(axisBinding); 352 writeTestServiceXML(axisBinding); 354 writeMessageReceiver(axisBinding); 356 emitStub(); 359 360 } catch (Exception e) { 361 e.printStackTrace(); 362 throw new CodeGenerationException(e); 363 } 364 } 365 366 protected XmlDocument createDocumentForTestSkeletonImpl(WSDLBinding binding){ 367 WSDLInterface boundInterface = binding.getBoundInterface(); 368 369 XmlDocument doc = new XmlDocument(); 370 Element rootElement = doc.createElement("class"); 371 addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX, rootElement); 372 addAttribute(doc,"servicename",boundInterface.getName().getLocalPart()+SERVICE_CLASS_SUFFIX,rootElement); 373 addAttribute(doc, "implpackage", configuration.getPackageName(), rootElement); 374 addAttribute(doc,"name",boundInterface.getName().getLocalPart()+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement); 375 addAttribute(doc, "namespace", boundInterface.getName().getNamespaceURI(), rootElement); 376 fillSyncAttributes(doc, rootElement); 377 loadOperations(boundInterface, doc, rootElement); 378 doc.appendChild(rootElement); 379 return doc; 380 } 381 382 387 protected XmlDocument createDOMDocumentForCallbackHandler(WSDLBinding binding){ 388 WSDLInterface boundInterface = binding.getBoundInterface(); 389 XmlDocument doc = new XmlDocument(); 390 Element rootElement = doc.createElement("callback"); 391 addAttribute(doc,"package",configuration.getPackageName(),rootElement); 392 addAttribute(doc,"name",boundInterface.getName().getLocalPart()+CALL_BACK_HANDLER_SUFFIX,rootElement); 393 addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement); 394 395 this.loadOperations(boundInterface, doc, rootElement); 397 399 doc.appendChild(rootElement); 400 return doc; 401 } 402 403 409 protected Element getInputElement(XmlDocument doc,WSDLOperation operation){ 410 Element inputElt = doc.createElement("input"); 411 Element param = getInputParamElement(doc, operation); 412 inputElt.appendChild(param); 413 return inputElt; 414 } 415 416 private Element getInputParamElement(XmlDocument doc, WSDLOperation operation) { 417 Element param = doc.createElement("param"); 419 MessageReference inputMessage = operation.getInputMessage(); 420 addAttribute(doc,"name",this.mapper.getParameterName(inputMessage.getElement()),param); 421 String typeMapping = this.mapper.getTypeMapping(inputMessage.getElement()); 422 String typeMappingStr =typeMapping==null?"":typeMapping; 423 addAttribute(doc,"type",typeMappingStr,param); 424 return param; 425 } 426 427 433 protected Element getOutputElement(XmlDocument doc,WSDLOperation operation){ 434 Element outputElt = doc.createElement("output"); 435 Element param = getOutputParamElement(doc, operation); 436 outputElt.appendChild(param); 437 return outputElt; 438 } 439 440 private Element getOutputParamElement(XmlDocument doc, WSDLOperation operation) { 441 Element param = doc.createElement("param"); 442 addAttribute(doc,"name",this.mapper.getParameterName(operation.getOutputMessage().getElement()),param); 443 444 String typeMapping = this.mapper.getTypeMapping(operation.getOutputMessage().getElement()); 445 String typeMappingStr=typeMapping==null?"":typeMapping; 446 addAttribute(doc,"type",typeMappingStr,param); 447 return param; 448 } 449 450 454 protected XmlDocument createDOMDocuementForBean(){ 455 return null; 456 } 457 458 protected XmlDocument createDOMDocuementForServiceXML(WSDLBinding binding, boolean forTesting) { 459 WSDLInterface boundInterface = binding.getBoundInterface(); 460 461 XmlDocument doc = new XmlDocument(); 462 Element rootElement = doc.createElement("interface"); 463 String localPart = boundInterface.getName().getLocalPart(); 464 if(forTesting){ 465 addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX, rootElement); 466 addAttribute(doc,"name",localPart+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement); 467 addAttribute(doc,"servicename",localPart+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement); 468 }else{ 469 addAttribute(doc,"package",configuration.getPackageName(), rootElement); 470 addAttribute(doc,"name",localPart+SERVICE_CLASS_SUFFIX,rootElement); 471 addAttribute(doc,"servicename",localPart,rootElement); 472 } 473 474 addAttribute(doc,"messagereceiver",localPart+MESSAGE_RECEIVER_SUFFIX,rootElement); 475 fillSyncAttributes(doc, rootElement); 476 loadOperations(boundInterface, doc, rootElement); 477 doc.appendChild(rootElement); 478 479 return doc; 480 } 481 482 483 protected XmlDocument createDocumentForMessageReceiver(WSDLBinding binding){ 484 WSDLInterface boundInterface = binding.getBoundInterface(); 485 486 XmlDocument doc = new XmlDocument(); 487 Element rootElement = doc.createElement("interface"); 488 addAttribute(doc,"package",configuration.getPackageName(), rootElement); 489 String localPart = boundInterface.getName().getLocalPart(); 490 addAttribute(doc,"name",localPart+MESSAGE_RECEIVER_SUFFIX,rootElement); 491 addAttribute(doc,"skeletonname",localPart + SERVICE_CLASS_SUFFIX,rootElement); 492 addAttribute(doc, "basereceiver", "org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver", rootElement); 493 addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement); 494 fillSyncAttributes(doc, rootElement); 495 loadOperations(boundInterface, doc, rootElement, binding); 496 doc.appendChild(rootElement); 497 498 499 return doc; 500 } 501 506 protected XmlDocument createDOMDocuementForInterface(WSDLBinding binding){ 507 WSDLInterface boundInterface = binding.getBoundInterface(); 508 509 XmlDocument doc = new XmlDocument(); 510 Element rootElement = doc.createElement("interface"); 511 addAttribute(doc,"package",configuration.getPackageName(), rootElement); 512 addAttribute(doc,"name",boundInterface.getName().getLocalPart(),rootElement); 513 addAttribute(doc,"callbackname",boundInterface.getName().getLocalPart() + CALL_BACK_HANDLER_SUFFIX,rootElement); 514 fillSyncAttributes(doc, rootElement); 515 loadOperations(boundInterface, doc, rootElement); 516 doc.appendChild(rootElement); 517 return doc; 518 519 } 520 521 protected XmlDocument createDOMDocuementForSkeleton(WSDLBinding binding){ 522 WSDLInterface boundInterface = binding.getBoundInterface(); 523 524 XmlDocument doc = new XmlDocument(); 525 Element rootElement = doc.createElement("interface"); 526 addAttribute(doc,"package",configuration.getPackageName(), rootElement); 527 addAttribute(doc,"name",boundInterface.getName().getLocalPart()+SERVICE_CLASS_SUFFIX,rootElement); 528 addAttribute(doc,"callbackname",boundInterface.getName().getLocalPart() + CALL_BACK_HANDLER_SUFFIX,rootElement); 529 fillSyncAttributes(doc, rootElement); 530 loadOperations(boundInterface, doc, rootElement); 531 doc.appendChild(rootElement); 532 return doc; 533 534 } 535 private void fillSyncAttributes(XmlDocument doc, Element rootElement) { 536 addAttribute(doc,"isAsync",this.configuration.isAsyncOn()?"1":"0",rootElement); 537 addAttribute(doc,"isSync",this.configuration.isSyncOn()?"1":"0",rootElement); 538 } 539 540 private void loadOperations(WSDLInterface boundInterface, XmlDocument doc, Element rootElement){ 541 loadOperations(boundInterface, doc, rootElement, null); 542 } 543 544 private void loadOperations(WSDLInterface boundInterface, XmlDocument doc, Element rootElement,WSDLBinding binding) { 545 Collection col = boundInterface.getOperations().values(); 546 Element methodElement = null; 547 WSDLOperation operation = null; 548 549 for (Iterator iterator = col.iterator(); iterator.hasNext();) { 550 operation = (WSDLOperation) iterator.next(); 551 methodElement = doc.createElement("method"); 552 String localPart = operation.getName().getLocalPart(); 553 addAttribute(doc,"name",localPart,methodElement); 554 addAttribute(doc,"namespace",operation.getName().getNamespaceURI(),methodElement); 555 addAttribute(doc,"style",operation.getStyle(),methodElement); 556 addAttribute(doc,"dbsupportname",localPart+DATABINDING_SUPPORTER_NAME_SUFFIX,methodElement); 557 if(null != binding){ 558 WSDLBindingOperation bindingOperation = binding.getBindingOperation(operation.getName()); 559 addSOAPAction(doc,methodElement,bindingOperation); 560 testCompatibilityInput(bindingOperation); 561 testCompatibilityOutput(bindingOperation); 562 } 563 addAttribute(doc,"mep",operation.getMessageExchangePattern(), methodElement); 564 methodElement.appendChild(getInputElement(doc,operation)); 565 methodElement.appendChild(getOutputElement(doc,operation)); 566 rootElement.appendChild(methodElement); 567 } 568 } 569 570 571 private void addSOAPAction(XmlDocument doc,Element rootElement,WSDLBindingOperation binding){ 572 Iterator extIterator = binding.getExtensibilityElements().iterator(); 573 boolean actionAdded = false; 574 while(extIterator.hasNext()){ 575 WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next(); 576 if(element.getType().equals(ExtensionConstants.SOAP_OPERATION)){ 577 addAttribute(doc,"soapaction", ((SOAPOperation)element).getSoapAction(),rootElement); 578 actionAdded = true ; 579 } 580 } 581 582 if (!actionAdded){ 583 addAttribute(doc,"soapaction", "",rootElement); 584 } 585 } 586 587 protected XmlDocument createDOMDocuementForTestCase(WSDLBinding binding) { 588 WSDLInterface boundInterface = binding.getBoundInterface(); 589 590 XmlDocument doc = new XmlDocument(); 591 Element rootElement = doc.createElement("class"); 592 addAttribute(doc,"package",configuration.getPackageName(),rootElement); 593 String localPart = boundInterface.getName().getLocalPart(); 594 addAttribute(doc,"name",localPart+TEST_SUFFIX,rootElement); 595 addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement); 596 addAttribute(doc,"interfaceName",localPart,rootElement); 597 addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement); 598 addAttribute(doc,"stubname",localPart + STUB_SUFFIX,rootElement); 599 addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement); 600 fillSyncAttributes(doc, rootElement); 601 loadOperations(boundInterface, doc, rootElement); 602 doc.appendChild(rootElement); 603 return doc; 604 605 } 606 607 protected XmlDocument createDOMDocuementForLocalTestCase(WSDLBinding binding) { 608 WSDLInterface boundInterface = binding.getBoundInterface(); 609 610 XmlDocument doc = new XmlDocument(); 611 Element rootElement = doc.createElement("class"); 612 String serviceXMLPath = configuration.getPackageName().replace('.','/')+TEST_PACKAGE_NAME_SUFFIX.replace('.','/')+"/testservice.xml"; 613 addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX,rootElement); 614 addAttribute(doc, "servicexmlpath", serviceXMLPath, rootElement); 615 addAttribute(doc, "implpackage", configuration.getPackageName(), rootElement); 616 String localPart = boundInterface.getName().getLocalPart(); 617 addAttribute(doc,"name",localPart+LOCAL_TEST_SUFFIX,rootElement); 618 addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement); 619 addAttribute(doc,"interfaceName",localPart,rootElement); 620 addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement); 621 addAttribute(doc,"stubname",localPart + STUB_SUFFIX,rootElement); 622 addAttribute(doc, "address", "http://localhost:"+Constants.TEST_PORT+"/services/"+boundInterface.getName().getLocalPart()+TEST_SERVICE_CLASS_NAME_SUFFIX, rootElement); 623 fillSyncAttributes(doc, rootElement); 624 loadOperations(boundInterface, doc, rootElement); 625 doc.appendChild(rootElement); 626 return doc; 627 628 } 629 630 protected XmlDocument createDOMDocumentforSerialization(WSDLOperation operation){ 631 XmlDocument doc = new XmlDocument(); 632 Element rootElement = doc.createElement("class"); 633 addAttribute(doc,"package",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement); 634 String localPart =operation.getName().getLocalPart(); 635 addAttribute(doc,"name",localPart+DATABINDING_SUPPORTER_NAME_SUFFIX,rootElement); 636 addAttribute(doc,"methodname",localPart,rootElement); 637 addAttribute(doc,"namespace",operation.getName().getNamespaceURI(),rootElement); 638 rootElement.appendChild(getInputParamElement(doc,operation)); 639 rootElement.appendChild(getOutputParamElement(doc,operation)); 640 doc.appendChild(rootElement); 641 return doc; 642 } 643 644 650 protected XmlDocument createDOMDocuementForInterfaceImplementation(WSDLBinding binding, WSDLService service) { 651 WSDLInterface boundInterface = binding.getBoundInterface(); 652 653 WSDLEndpoint endpoint = null; 654 HashMap endpoints = service.getEndpoints(); 655 XmlDocument doc = new XmlDocument(); 656 Element rootElement = doc.createElement("class"); 657 addAttribute(doc,"package",configuration.getPackageName(),rootElement); 658 String localPart = boundInterface.getName().getLocalPart(); 659 addAttribute(doc,"name",localPart+STUB_SUFFIX,rootElement); 660 addAttribute(doc,"servicename",localPart,rootElement); 661 addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement); 662 addAttribute(doc,"interfaceName",localPart,rootElement); 663 addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement); 664 addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement); 665 addEndpoints(doc,rootElement,endpoints); 666 fillSyncAttributes(doc, rootElement); 667 loadOperations(boundInterface, doc, rootElement,binding); 668 doc.appendChild(rootElement); 669 670 671 672 return doc; 673 674 } 675 676 protected void addEndpoints(XmlDocument doc,Element rootElement,HashMap endpointMap){ 677 Object [] endpoints = endpointMap.values().toArray(); 678 WSDLEndpoint endpoint; 679 Element endpointElement; 680 Text text; 681 for (int i = 0; i < endpoints.length; i++) { 682 endpoint = (WSDLEndpoint)endpoints[i]; 683 endpointElement = doc.createElement("endpoint"); 684 org.apache.wsdl.extensions.SOAPAddress address = null; 685 Iterator iterator = endpoint.getExtensibilityElements().iterator(); 686 while(iterator.hasNext()) { 687 WSDLExtensibilityElement element = (WSDLExtensibilityElement)iterator.next(); 688 if (element.getType().equals(ExtensionConstants.SOAP_ADDRESS)){ 689 address = (org.apache.wsdl.extensions.SOAPAddress)element; 690 } 691 } 692 text = doc.createTextNode(address.getLocationURI()); endpointElement.appendChild(text); 694 rootElement.appendChild(endpointElement); 695 } 696 697 } 698 699 protected void addAttribute(XmlDocument document,String AttribName, String attribValue, Element element){ 700 Attr attribute = document.createAttribute(AttribName); 701 attribute.setValue(attribValue); 702 element.setAttributeNode(attribute); 703 } 704 705 protected String removeUnsuitableCharacters(String word){ 706 return word.replaceAll("\\W","_"); 707 } 708 709 private void testCompatibiltyAll(WSDLBinding binding){ 710 HashMap map = binding.getBindingOperations(); 711 WSDLBindingOperation bindingOp; 712 Collection col = map.values(); 713 for (Iterator iterator = col.iterator(); iterator.hasNext();) { 714 bindingOp = (WSDLBindingOperation)iterator.next(); 715 testCompatibilityInput(bindingOp); 716 testCompatibilityOutput(bindingOp); 717 } 718 719 720 } 721 private void testCompatibilityInput(WSDLBindingOperation binding){ 722 723 Iterator extIterator = binding.getInput().getExtensibilityElements().iterator(); 724 while(extIterator.hasNext()){ 725 WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next(); 726 if(element.getType().equals(ExtensionConstants.SOAP_BODY)){ 727 if(WSDLConstants.WSDL_USE_ENCODED.equals(((SOAPBody)element).getUse())){ 728 throw new RuntimeException ("The use 'encoded' is not supported!"); 729 } 730 } 731 } 732 } 733 734 private void testCompatibilityOutput(WSDLBindingOperation binding){ 735 736 Iterator extIterator = binding.getOutput().getExtensibilityElements().iterator(); 737 while(extIterator.hasNext()){ 738 WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next(); 739 if(element.getType().equals(ExtensionConstants.SOAP_BODY)){ 740 if(WSDLConstants.WSDL_USE_ENCODED.equals(((SOAPBody)element).getUse())){ 741 throw new RuntimeException ("The use 'encoded' is not supported!"); 742 } 743 } 744 } 745 } 746 } 747 748 | Popular Tags |