1 55 package org.jboss.axis.wsdl.toJava; 56 57 import org.jboss.axis.Constants; 58 import org.jboss.axis.enums.Style; 59 import org.jboss.axis.enums.Use; 60 import org.jboss.axis.utils.JavaUtils; 61 import org.jboss.axis.utils.Messages; 62 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 63 import org.jboss.axis.wsdl.symbolTable.CollectionTE; 64 import org.jboss.axis.wsdl.symbolTable.Element; 65 import org.jboss.axis.wsdl.symbolTable.FaultInfo; 66 import org.jboss.axis.wsdl.symbolTable.MimeInfo; 67 import org.jboss.axis.wsdl.symbolTable.Parameter; 68 import org.jboss.axis.wsdl.symbolTable.Parameters; 69 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 70 import org.jboss.axis.wsdl.symbolTable.TypeEntry; 71 72 import javax.wsdl.Binding; 73 import javax.wsdl.BindingOperation; 74 import javax.wsdl.Fault; 75 import javax.wsdl.Message; 76 import javax.wsdl.Operation; 77 import javax.wsdl.OperationType; 78 import javax.wsdl.Part; 79 import javax.wsdl.PortType; 80 import javax.wsdl.extensions.UnknownExtensibilityElement; 81 import javax.wsdl.extensions.soap.SOAPBinding; 82 import javax.wsdl.extensions.soap.SOAPOperation; 83 import javax.xml.namespace.QName ; 84 import java.io.IOException ; 85 import java.io.PrintWriter ; 86 import java.util.ArrayList ; 87 import java.util.Collection ; 88 import java.util.HashMap ; 89 import java.util.HashSet ; 90 import java.util.Iterator ; 91 import java.util.List ; 92 import java.util.Map ; 93 import java.util.Vector ; 94 95 99 public class JavaStubWriter extends JavaClassWriter 100 { 101 private BindingEntry bEntry; 102 private Binding binding; 103 private SymbolTable symbolTable; 104 105 static String [] modeStrings = new String []{"", 106 "org.jboss.axis.description.ParameterDesc.IN", 107 "org.jboss.axis.description.ParameterDesc.OUT", 108 "org.jboss.axis.description.ParameterDesc.INOUT"}; 109 static HashMap styles = new HashMap (); 110 static HashMap uses = new HashMap (); 111 112 static 113 { 114 styles.put(Style.DOCUMENT, "org.jboss.axis.enums.Style.DOCUMENT"); 115 styles.put(Style.RPC, "org.jboss.axis.enums.Style.RPC"); 116 styles.put(Style.MESSAGE, "org.jboss.axis.enums.Style.MESSAGE"); 117 styles.put(Style.WRAPPED, "org.jboss.axis.enums.Style.WRAPPED"); 118 uses.put(Use.ENCODED, "org.jboss.axis.enums.Use.ENCODED"); 119 uses.put(Use.LITERAL, "org.jboss.axis.enums.Use.LITERAL"); 120 } 121 122 125 protected JavaStubWriter(Emitter emitter, 126 BindingEntry bEntry, 127 SymbolTable symbolTable) 128 { 129 super(emitter, bEntry.getName() + "Stub", "stub"); 130 this.bEntry = bEntry; 131 this.binding = bEntry.getBinding(); 132 this.symbolTable = symbolTable; 133 } 135 138 protected String getExtendsText() 139 { 140 return "extends org.jboss.axis.client.Stub "; 141 } 143 146 protected String getImplementsText() 147 { 148 return "implements " + bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME) + " "; 149 } 151 154 protected void writeFileBody(PrintWriter pw) throws IOException 155 { 156 PortType portType = binding.getPortType(); 157 158 HashSet types = getTypesInPortType(portType); 159 boolean hasMIME = Utils.hasMIME(bEntry); 160 if (types.size() > 0 || hasMIME) 161 { 162 pw.println(" private java.util.Vector cachedSerClasses = new java.util.Vector();"); 163 pw.println(" private java.util.Vector cachedSerQNames = new java.util.Vector();"); 164 pw.println(" private java.util.Vector cachedSerFactories = new java.util.Vector();"); 165 pw.println(" private java.util.Vector cachedDeserFactories = new java.util.Vector();"); 166 } 167 pw.println(); 168 169 pw.println(" static org.jboss.axis.description.OperationDesc [] _operations;"); 170 pw.println(); 171 writeOperationMap(pw); 172 pw.println(); 173 174 pw.println(" public " + className + "() throws org.jboss.axis.AxisFault {"); 175 pw.println(" this(null);"); 176 pw.println(" }"); 177 pw.println(); 178 179 pw.println(" public " + className + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.jboss.axis.AxisFault {"); 180 pw.println(" this(service);"); 181 pw.println(" super.cachedEndpoint = endpointURL;"); 182 pw.println(" }"); 183 pw.println(); 184 185 pw.println(" public " + className + "(javax.xml.rpc.Service service) throws org.jboss.axis.AxisFault {"); 186 pw.println(" if (service == null) {"); 187 pw.println(" super.service = new org.jboss.axis.client.Service();"); 188 pw.println(" } else {"); 189 pw.println(" super.service = service;"); 190 pw.println(" }"); 191 192 int typeMappingCount = 0; 194 if (types.size() > 0) 195 { 196 Iterator it = types.iterator(); 197 while (it.hasNext()) 198 { 199 TypeEntry type = (TypeEntry)it.next(); 200 202 if ((type.getBaseType() != null && type.getRefType() == null) || 210 type instanceof CollectionTE || 211 type instanceof Element || 212 !type.isReferenced() || 213 type.isOnlyLiteralReferenced()) 214 { 215 continue; 216 } 217 218 if (typeMappingCount == 0) 220 { 221 writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI()); 222 } 223 224 writeSerializationInit(pw, type); 226 227 typeMappingCount++; 229 } 230 } 231 if (typeMappingCount == 0 && hasMIME) 234 { 235 writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI()); 236 typeMappingCount++; 237 } 238 239 pw.println(" }"); 240 pw.println(); 241 pw.println(" private org.jboss.axis.client.Call createCall() throws java.rmi.RemoteException {"); 242 pw.println(" try {"); 243 pw.println(" org.jboss.axis.client.Call _call ="); 244 pw.println(" (org.jboss.axis.client.Call) super.service.createCall();"); 245 pw.println(" if (super.maintainSessionSet) {"); 246 pw.println(" _call.setMaintainSession(super.maintainSession);"); 247 pw.println(" }"); 248 pw.println(" if (super.cachedUsername != null) {"); 249 pw.println(" _call.setUsername(super.cachedUsername);"); 250 251 pw.println(" }"); 252 pw.println(" if (super.cachedPassword != null) {"); 253 pw.println(" _call.setPassword(super.cachedPassword);"); 254 pw.println(" }"); 255 pw.println(" if (super.cachedEndpoint != null) {"); 256 pw.println(" _call.setTargetEndpointAddress(super.cachedEndpoint);"); 257 pw.println(" }"); 258 pw.println(" if (super.cachedTimeout != null) {"); 259 pw.println(" _call.setTimeout(super.cachedTimeout);"); 260 pw.println(" }"); 261 pw.println(" if (super.cachedPortName != null) {"); 262 pw.println(" _call.setPortName(super.cachedPortName);"); 263 pw.println(" }"); 264 pw.println(" java.util.Enumeration keys = super.cachedProperties.keys();"); 265 pw.println(" while (keys.hasMoreElements()) {"); 266 pw.println(" java.lang.String key = (java.lang.String) keys.nextElement();"); 267 pw.println(" _call.setProperty(key, super.cachedProperties.get(key));"); 268 pw.println(" }"); 269 if (typeMappingCount > 0) 270 { 271 pw.println(" // " + Messages.getMessage("typeMap00")); 272 pw.println(" // " + Messages.getMessage("typeMap01")); 273 pw.println(" // " + Messages.getMessage("typeMap02")); 274 pw.println(" // " + Messages.getMessage("typeMap03")); 275 pw.println(" // " + Messages.getMessage("typeMap04")); 276 pw.println(" synchronized (this) {"); 277 pw.println(" if (firstCall()) {"); 278 279 pw.println(" // " 282 + Messages.getMessage("mustSetStyle")); 283 if (bEntry.hasLiteral()) 284 { 285 pw.println(" _call.setEncodingStyle(null);"); 286 } 287 else 288 { 289 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator(); 290 while (iterator.hasNext()) 291 { 292 Object obj = iterator.next(); 293 if (obj instanceof SOAPBinding) 294 { 295 pw.println(" _call.setSOAPVersion(org.jboss.axis.soap.SOAPConstants.SOAP11_CONSTANTS);"); 296 pw.println(" _call.setEncodingStyle(org.jboss.axis.Constants.URI_SOAP11_ENC);"); 297 } 298 else if (obj instanceof UnknownExtensibilityElement) 299 { 300 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 302 QName name = unkElement.getElementType(); 303 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 304 name.getLocalPart().equals("binding")) 305 { 306 pw.println(" _call.setSOAPVersion(org.jboss.axis.soap.SOAPConstants.SOAP12_CONSTANTS);"); 307 pw.println(" _call.setEncodingStyle(org.jboss.axis.Constants.URI_SOAP12_ENC);"); 308 } 309 } 310 } 311 } 312 313 pw.println(" for (int i = 0; i < cachedSerFactories.size(); ++i) {"); 314 pw.println(" java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);"); 315 pw.println(" javax.xml.namespace.QName qName ="); 316 pw.println(" (javax.xml.namespace.QName) cachedSerQNames.get(i);"); 317 pw.println(" java.lang.Class sf = (java.lang.Class)"); 318 pw.println(" cachedSerFactories.get(i);"); 319 pw.println(" java.lang.Class df = (java.lang.Class)"); 320 pw.println(" cachedDeserFactories.get(i);"); 321 pw.println(" _call.registerTypeMapping(cls, qName, sf, df, false);"); 322 pw.println(" }"); 323 pw.println(" }"); 324 pw.println(" }"); 325 } 326 pw.println(" return _call;"); 327 pw.println(" }"); 328 pw.println(" catch (java.lang.Throwable t) {"); 329 pw.println(" throw new org.jboss.axis.AxisFault(\"" 330 + Messages.getMessage("badCall01") + "\", t);"); 331 pw.println(" }"); 332 pw.println(" }"); 333 pw.println(); 334 335 List operations = binding.getBindingOperations(); 336 for (int i = 0; i < operations.size(); ++i) 337 { 338 BindingOperation operation = (BindingOperation)operations.get(i); 339 Parameters parameters = 340 bEntry.getParameters(operation.getOperation()); 341 342 String soapAction = ""; 344 String opStyle = null; 345 Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator(); 346 for (; operationExtensibilityIterator.hasNext();) 347 { 348 Object obj = operationExtensibilityIterator.next(); 349 if (obj instanceof SOAPOperation) 350 { 351 soapAction = ((SOAPOperation)obj).getSoapActionURI(); 352 opStyle = ((SOAPOperation)obj).getStyle(); 353 break; 354 } 355 else if (obj instanceof UnknownExtensibilityElement) 356 { 357 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 359 QName name = unkElement.getElementType(); 360 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 361 name.getLocalPart().equals("operation")) 362 { 363 if (unkElement.getElement().getAttribute("soapAction") != null) 364 { 365 soapAction = unkElement.getElement().getAttribute("soapAction"); 366 } 367 opStyle = unkElement.getElement().getAttribute("style"); 368 } 369 } 370 } 371 Operation ptOperation = operation.getOperation(); 372 OperationType type = ptOperation.getStyle(); 373 374 if (type == OperationType.NOTIFICATION 377 || type == OperationType.SOLICIT_RESPONSE) 378 { 379 pw.println(parameters.signature); 380 pw.println(); 381 } 382 else 383 { 384 writeOperation(pw, operation, parameters, soapAction, opStyle, 385 type == OperationType.ONE_WAY, i); 386 } 387 } 388 } 390 private void writeOperationMap(PrintWriter pw) 391 { 392 List operations = binding.getBindingOperations(); 393 pw.println(" static {"); 394 pw.println(" _operations = new org.jboss.axis.description.OperationDesc[" + 395 operations.size() + "];"); 396 pw.println(" org.jboss.axis.description.OperationDesc oper;"); 397 for (int i = 0; i < operations.size(); ++i) 398 { 399 BindingOperation operation = (BindingOperation)operations.get(i); 400 Parameters parameters = 401 bEntry.getParameters(operation.getOperation()); 402 403 String opStyle = null; 405 Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator(); 406 for (; operationExtensibilityIterator.hasNext();) 407 { 408 Object obj = operationExtensibilityIterator.next(); 409 if (obj instanceof SOAPOperation) 410 { 411 opStyle = ((SOAPOperation)obj).getStyle(); 412 break; 413 } 414 else if (obj instanceof UnknownExtensibilityElement) 415 { 416 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 418 QName name = unkElement.getElementType(); 419 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 420 name.getLocalPart().equals("operation")) 421 { 422 opStyle = unkElement.getElement().getAttribute("style"); 423 } 424 } 425 } 426 Operation ptOperation = operation.getOperation(); 427 OperationType type = ptOperation.getStyle(); 428 429 if (type == OperationType.NOTIFICATION 432 || type == OperationType.SOLICIT_RESPONSE) 433 { 434 pw.println(parameters.signature); 435 pw.println(); 436 } 437 438 String operName = operation.getName(); 439 String indent = " "; 440 pw.println(indent + "oper = new org.jboss.axis.description.OperationDesc();"); 441 pw.println(indent + "oper.setName(\"" + operName + "\");"); 442 443 for (int j = 0; j < parameters.list.size(); ++j) 445 { 446 Parameter p = (Parameter)parameters.list.get(j); 447 448 QName paramType = Utils.getXSIType(p); 450 451 String javaType = null; 453 if (p.getMIMEInfo() != null) 454 { 455 MimeInfo mimeInfo = p.getMIMEInfo(); 456 javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions() + ".class, "; 457 } 458 else 459 { 460 javaType = p.getType().getName(); 461 if (javaType != null) 462 { 463 javaType += ".class, "; 464 } 465 else 466 { 467 javaType = "null, "; 468 } 469 } 470 471 String paramNameText = Utils.getNewQName(p.getQName()); 473 String paramTypeText = Utils.getNewQName(paramType); 474 475 boolean isInHeader = p.isInHeader(); 478 boolean isOutHeader = p.isOutHeader(); 479 pw.println(" oper.addParameter(" + paramNameText 480 + ", " + paramTypeText + ", " 481 + javaType + modeStrings[p.getMode()] 482 + ", " + isInHeader + ", " + isOutHeader + ");"); 483 } 484 if (parameters.returnParam != null) 486 { 487 488 QName returnType = Utils.getXSIType(parameters.returnParam); 490 491 String javaType = null; 493 if (parameters.returnParam.getMIMEInfo() != null) 494 { 495 MimeInfo mimeInfo = parameters.returnParam.getMIMEInfo(); 496 javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions(); 497 } 498 else 499 { 500 javaType = parameters.returnParam.getType().getName(); 501 } 502 if (javaType == null) 503 { 504 javaType = ""; 505 } 506 else 507 { 508 javaType = javaType + ".class"; 509 } 510 pw.println(" oper.setReturnType(" + 511 512 Utils.getNewQName(returnType) + ");"); 513 pw.println(" oper.setReturnClass(" 514 + javaType + ");"); 515 QName returnQName = parameters.returnParam.getQName(); 516 if (returnQName != null) 517 { 518 pw.println(" oper.setReturnQName(" + 519 Utils.getNewQName(returnQName) + ");"); 520 } 521 if (parameters.returnParam.isOutHeader()) 522 { 523 pw.println(" oper.setReturnHeader(true);"); 524 } 525 } 526 else 527 { 528 pw.println(" oper.setReturnType(org.jboss.axis.encoding.XMLType.AXIS_VOID);"); 529 } 530 531 boolean hasMIME = Utils.hasMIME(bEntry, operation); 532 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 533 Use use = bEntry.getInputBodyType(operation.getOperation()); 534 if (style == Style.DOCUMENT && symbolTable.isWrapped()) 535 { 536 style = Style.WRAPPED; 537 } 538 539 if (!hasMIME) 540 { 541 pw.println(" oper.setStyle(" + styles.get(style) + ");"); 542 pw.println(" oper.setUse(" + uses.get(use) + ");"); 543 } 544 545 writeFaultInfo(pw, operation); 547 548 pw.println(indent + "_operations[" + i + "] = oper;"); 549 pw.println(""); 550 } 551 pw.println(" }"); 552 } 553 554 558 private HashSet getTypesInPortType(PortType portType) 559 { 560 HashSet types = new HashSet (); 561 HashSet firstPassTypes = new HashSet (); 562 563 List operations = portType.getOperations(); 565 566 for (int i = 0; i < operations.size(); ++i) 567 { 568 Operation op = (Operation)operations.get(i); 569 firstPassTypes.addAll(getTypesInOperation(op)); 570 } 571 572 Iterator i = firstPassTypes.iterator(); 575 while (i.hasNext()) 576 { 577 TypeEntry type = (TypeEntry)i.next(); 578 if (!types.contains(type)) 579 { 580 types.add(type); 581 types.addAll(Utils.getNestedTypes(type, symbolTable, true)); 582 } 583 } 584 return types; 585 } 587 591 private HashSet getTypesInOperation(Operation operation) 592 { 593 HashSet types = new HashSet (); 594 Vector v = new Vector (); 595 596 Parameters params = bEntry.getParameters(operation); 597 598 for (int i = 0; i < params.list.size(); i++) 600 { 601 Parameter p = (Parameter)params.list.get(i); 602 v.add(p.getType()); 603 } 604 605 if (params.returnParam != null) 607 v.add(params.returnParam.getType()); 608 609 Map faults = operation.getFaults(); 611 612 if (faults != null) 613 { 614 Iterator i = faults.values().iterator(); 615 616 while (i.hasNext()) 617 { 618 Fault f = (Fault)i.next(); 619 partTypes(v, 620 f.getMessage().getOrderedParts(null)); 621 } 622 } 623 for (int i = 0; i < v.size(); i++) 625 types.add(v.get(i)); 626 627 return types; 628 } 630 633 private void partTypes(Vector v, Collection parts) 634 { 635 Iterator i = parts.iterator(); 636 637 while (i.hasNext()) 638 { 639 Part part = (Part)i.next(); 640 641 QName qType = part.getTypeName(); 642 if (qType != null) 643 { 644 v.add(symbolTable.getType(qType)); 645 } 646 else 647 { 648 qType = part.getElementName(); 649 if (qType != null) 650 { 651 v.add(symbolTable.getElement(qType)); 652 } 653 } 654 } 656 } 658 661 private void writeFaultInfo(PrintWriter pw, BindingOperation bindOp) 662 { 663 Map faultMap = bEntry.getFaults(); 664 ArrayList faults = (ArrayList )faultMap.get(bindOp); 666 667 if (faults == null) 669 { 670 return; 671 } 672 for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) 674 { 675 FaultInfo info = (FaultInfo)faultIt.next(); 676 QName qname = info.getQName(); 677 Message message = info.getMessage(); 678 679 if (qname == null) 681 { 682 continue; 683 } 684 685 String className = Utils.getFullExceptionName(message, symbolTable); 687 688 pw.println(" oper.addFault(new org.jboss.axis.description.FaultDesc("); 690 pw.println(" " + Utils.getNewQName(qname) + ","); 691 pw.println(" \"" + className + "\","); 692 pw.println(" " + Utils.getNewQName(info.getXMLType()) + ", "); 693 pw.println(" " + Utils.isFaultComplex(message, symbolTable)); 694 pw.println(" ));"); 695 } 696 } 697 698 701 702 private void writeSerializationDecls(PrintWriter pw, boolean hasMIME, 703 String namespace) 704 { 705 pw.println(" java.lang.Class cls;"); 706 pw.println(" javax.xml.namespace.QName qName;"); 707 pw.println(" java.lang.Class beansf = org.jboss.axis.encoding.ser.BeanSerializerFactory.class;"); 708 pw.println(" java.lang.Class beandf = org.jboss.axis.encoding.ser.BeanDeserializerFactory.class;"); 709 pw.println(" java.lang.Class enumsf = org.jboss.axis.encoding.ser.EnumSerializerFactory.class;"); 710 pw.println(" java.lang.Class enumdf = org.jboss.axis.encoding.ser.EnumDeserializerFactory.class;"); 711 pw.println(" java.lang.Class arraysf = org.jboss.axis.encoding.ser.ArraySerializerFactory.class;"); 712 pw.println(" java.lang.Class arraydf = org.jboss.axis.encoding.ser.ArrayDeserializerFactory.class;"); 713 pw.println(" java.lang.Class simplesf = org.jboss.axis.encoding.ser.SimpleSerializerFactory.class;"); 714 pw.println(" java.lang.Class simpledf = org.jboss.axis.encoding.ser.SimpleDeserializerFactory.class;"); 715 716 if (hasMIME) 717 { 718 pw.println(" java.lang.Class mimesf = org.jboss.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;"); 719 pw.println(" java.lang.Class mimedf = org.jboss.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;"); 720 pw.println(); 721 QName qname = new QName (namespace, "DataHandler"); 722 723 pw.println(" qName = new javax.xml.namespace.QName(\"" 724 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart() 725 + "\");"); 726 pw.println(" cachedSerQNames.add(qName);"); 727 pw.println(" cls = javax.activation.DataHandler.class;"); 728 pw.println(" cachedSerClasses.add(cls);"); 729 pw.println(" cachedSerFactories.add(mimesf);"); 730 pw.println(" cachedDeserFactories.add(mimedf);"); 731 pw.println(); 732 } 733 } 735 private void writeSerializationInit(PrintWriter pw, TypeEntry type) 736 { 737 738 QName qname = type.getQName(); 739 740 pw.println(" qName = new javax.xml.namespace.QName(\"" 741 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart() 742 + "\");"); 743 pw.println(" cachedSerQNames.add(qName);"); 744 pw.println(" cls = " + type.getName() + ".class;"); 745 pw.println(" cachedSerClasses.add(cls);"); 746 if (type.getName().endsWith("[]")) 747 { 748 pw.println(" cachedSerFactories.add(arraysf);"); 749 pw.println(" cachedDeserFactories.add(arraydf);"); 750 } 751 else if (type.getNode() != null && 752 Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null) 753 { 754 pw.println(" cachedSerFactories.add(enumsf);"); 755 pw.println(" cachedDeserFactories.add(enumdf);"); 756 } 757 else if (type.isSimpleType()) 758 { 759 pw.println(" cachedSerFactories.add(simplesf);"); 760 pw.println(" cachedDeserFactories.add(simpledf);"); 761 } 762 else if (type.getBaseType() != null) 763 { 764 pw.println(" cachedSerFactories.add(null);"); 773 pw.println(" cachedDeserFactories.add(simpledf);"); 774 } 775 else 776 { 777 pw.println(" cachedSerFactories.add(beansf);"); 778 pw.println(" cachedDeserFactories.add(beandf);"); 779 } 780 pw.println(); 781 } 783 786 private void writeOperation(PrintWriter pw, 787 BindingOperation operation, 788 Parameters parms, 789 String soapAction, 790 String opStyle, 791 boolean oneway, 792 int opIndex) 793 { 794 795 writeComment(pw, operation.getDocumentationElement()); 796 797 pw.println(parms.signature + " {"); 798 pw.println(" if (super.cachedEndpoint == null) {"); 799 pw.println(" throw new org.jboss.axis.NoEndPointException();"); 800 pw.println(" }"); 801 pw.println(" org.jboss.axis.client.Call _call = createCall();"); 802 803 pw.println(" _call.setOperation(_operations[" + opIndex + "]);"); 804 805 if (soapAction != null) 807 { 808 pw.println(" _call.setUseSOAPAction(true);"); 809 pw.println(" _call.setSOAPActionURI(\"" + soapAction + "\");"); 810 } 811 812 boolean hasMIME = Utils.hasMIME(bEntry, operation); 813 814 Use use = bEntry.getInputBodyType(operation.getOperation()); 816 if (use == Use.LITERAL) 817 { 818 pw.println(" _call.setEncodingStyle(null);"); 820 pw.println(" _call.setProperty(org.jboss.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);"); 822 } 823 if (hasMIME || use == Use.LITERAL) 824 { 825 pw.println(" _call.setProperty(org.jboss.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);"); 831 } 832 833 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 834 if (style == Style.DOCUMENT && symbolTable.isWrapped()) 835 { 836 style = Style.WRAPPED; 837 } 838 839 840 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator(); 841 while (iterator.hasNext()) 842 { 843 Object obj = iterator.next(); 844 if (obj instanceof SOAPBinding) 845 { 846 pw.println(" _call.setSOAPVersion(org.jboss.axis.soap.SOAPConstants.SOAP11_CONSTANTS);"); 847 } 848 else if (obj instanceof UnknownExtensibilityElement) 849 { 850 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 852 QName name = unkElement.getElementType(); 853 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 854 name.getLocalPart().equals("binding")) 855 { 856 pw.println(" _call.setSOAPVersion(org.jboss.axis.soap.SOAPConstants.SOAP12_CONSTANTS);"); 857 } 858 } 859 } 860 861 if (style == Style.WRAPPED) 863 { 864 Map partsMap = operation.getOperation().getInput().getMessage().getParts(); 868 Part p = (Part)partsMap.values().iterator().next(); 869 QName q = p.getElementName(); 870 pw.println(" _call.setOperationName(" + Utils.getNewQName(q) + ");"); 871 } 872 else 873 { 874 QName elementQName = 875 Utils.getOperationQName(operation, bEntry, symbolTable); 876 if (elementQName != null) 877 { 878 pw.println(" _call.setOperationName(" + 879 Utils.getNewQName(elementQName) + ");"); 880 } 881 } 882 pw.println(); 883 884 pw.println(" setRequestHeaders(_call);"); 886 887 pw.println(" setAttachments(_call);"); 889 890 if (bEntry.isOperationDIME(operation.getOperation().getName())) 892 { 893 pw.println(" _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);"); 894 } 895 896 if (oneway) 898 { 899 pw.print(" _call.invokeOneWay("); 900 } 901 else 902 { 903 pw.print(" java.lang.Object _resp = _call.invoke("); 904 } 905 pw.print("new java.lang.Object[] {"); 906 writeParameters(pw, parms); 907 pw.println("});"); 908 pw.println(); 909 910 if (!oneway) 911 { 912 writeResponseHandling(pw, parms); 913 } 914 pw.println(" }"); 915 pw.println(); 916 } 918 private void writeParameters(PrintWriter pw, Parameters parms) 919 { 920 boolean needComma = false; 922 for (int i = 0; i < parms.list.size(); ++i) 923 { 924 Parameter p = (Parameter)parms.list.get(i); 925 926 if (p.getMode() != Parameter.OUT) 927 { 928 if (needComma) 929 { 930 pw.print(", "); 931 } 932 else 933 { 934 needComma = true; 935 } 936 937 String javifiedName = Utils.xmlNameToJava(p.getName()); 938 if (p.getMode() != Parameter.IN) 939 { 940 javifiedName += ".value"; 941 } 942 if (p.getMIMEInfo() == null) 943 { 944 javifiedName = Utils.wrapPrimitiveType(p.getType(), javifiedName); 945 } 946 pw.print(javifiedName); 947 } 948 } 949 } 951 private void writeResponseHandling(PrintWriter pw, Parameters parms) 952 { 953 pw.println(" if (_resp instanceof java.rmi.RemoteException) {"); 954 pw.println(" throw (java.rmi.RemoteException)_resp;"); 955 pw.println(" }"); 956 957 int allOuts = parms.outputs + parms.inouts; 958 if (allOuts > 0) 959 { 960 pw.println(" else {"); 961 pw.println(" extractAttachments(_call);"); 962 963 if (allOuts == 1) 964 { 965 if (parms.returnParam != null) 966 { 967 writeOutputAssign(pw, "return ", parms.returnParam.getType(), 968 parms.returnParam.getMIMEInfo(), "_resp"); 969 } 970 else 971 { 972 int i = 0; 974 Parameter p = (Parameter)parms.list.get(i); 975 976 while (p.getMode() == Parameter.IN) 977 { 978 p = (Parameter)parms.list.get(++i); 979 } 980 String javifiedName = Utils.xmlNameToJava(p.getName()); 981 String qnameName = Utils.getNewQName(p.getQName()); 982 983 pw.println(" java.util.Map _output;"); 984 pw.println(" _output = _call.getOutputParams();"); 985 writeOutputAssign(pw, javifiedName + ".value = ", 986 p.getType(), p.getMIMEInfo(), 987 "_output.get(" + qnameName + ")"); 988 } 989 } 990 else 991 { 992 pw.println(" java.util.Map _output;"); 994 pw.println(" _output = _call.getOutputParams();"); 995 for (int i = 0; i < parms.list.size(); ++i) 996 { 997 Parameter p = (Parameter)parms.list.get(i); 998 String javifiedName = Utils.xmlNameToJava(p.getName()); 999 String qnameName = Utils.getNewQName(p.getQName()); 1000 if (p.getMode() != Parameter.IN) 1001 { 1002 writeOutputAssign(pw, javifiedName + ".value = ", 1003 p.getType(), p.getMIMEInfo(), 1004 "_output.get(" + qnameName + ")"); 1005 } 1006 } 1007 if (parms.returnParam != null) 1008 { 1009 writeOutputAssign(pw, "return ", parms.returnParam.getType(), 1010 parms.returnParam.getMIMEInfo(), "_resp"); 1011 } 1012 1013 } 1014 pw.println(" }"); 1015 } 1016 else 1017 { 1018 pw.println(" extractAttachments(_call);"); 1019 } 1020 } 1022 1029 private void writeOutputAssign(PrintWriter pw, String target, 1030 TypeEntry type, MimeInfo mimeInfo, 1031 String source) 1032 { 1033 if (type != null && type.getName() != null) 1034 { 1035 pw.println(" try {"); 1038 1039 pw.println(" " + target + 1040 Utils.getResponseString(type, mimeInfo, source)); 1041 1042 pw.println(" } catch (java.lang.Exception _exception) {"); 1043 pw.println(" " + target + 1044 Utils.getResponseString(type, mimeInfo, 1045 "org.jboss.axis.utils.JavaUtils.convert(" + 1046 source + ", " + type.getName() + ".class)")); 1047 pw.println(" }"); 1048 } 1049 else 1050 { 1051 pw.println(" " + target + 1052 Utils.getResponseString(type, mimeInfo, source)); 1053 } 1054 } 1055 1056} | Popular Tags |