1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.Constants; 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.constants.Style; 21 import org.apache.axis.constants.Use; 22 import org.apache.axis.utils.Messages; 23 import org.apache.axis.utils.JavaUtils; 24 import org.apache.axis.utils.StringUtils; 25 import org.apache.axis.wsdl.symbolTable.BindingEntry; 26 import org.apache.axis.wsdl.symbolTable.DefinedType; 27 import org.apache.axis.wsdl.symbolTable.FaultInfo; 28 import org.apache.axis.wsdl.symbolTable.Parameter; 29 import org.apache.axis.wsdl.symbolTable.Parameters; 30 import org.apache.axis.wsdl.symbolTable.SchemaUtils; 31 import org.apache.axis.wsdl.symbolTable.SymbolTable; 32 import org.apache.axis.wsdl.symbolTable.TypeEntry; 33 import org.apache.axis.wsdl.symbolTable.DefinedElement; 34 import org.apache.commons.logging.Log; 35 36 import javax.wsdl.Binding; 37 import javax.wsdl.BindingOperation; 38 import javax.wsdl.Fault; 39 import javax.wsdl.Message; 40 import javax.wsdl.Operation; 41 import javax.wsdl.OperationType; 42 import javax.wsdl.Part; 43 import javax.wsdl.PortType; 44 import javax.wsdl.extensions.UnknownExtensibilityElement; 45 import javax.wsdl.extensions.soap.SOAPBinding; 46 import javax.wsdl.extensions.soap.SOAPOperation; 47 import javax.xml.namespace.QName ; 48 import java.io.IOException ; 49 import java.io.PrintWriter ; 50 import java.util.ArrayList ; 51 import java.util.Collection ; 52 import java.util.HashMap ; 53 import java.util.HashSet ; 54 import java.util.Iterator ; 55 import java.util.List ; 56 import java.util.Map ; 57 import java.util.Vector ; 58 import java.util.Arrays ; 59 import java.util.Comparator ; 60 import java.util.Collections ; 61 62 66 public class JavaStubWriter extends JavaClassWriter { 67 68 69 protected static Log log = LogFactory.getLog(JavaStubWriter.class.getName()); 70 71 72 private BindingEntry bEntry; 73 74 75 private Binding binding; 76 77 78 private SymbolTable symbolTable; 79 80 85 86 private static final int MAXIMUM_BINDINGS_PER_METHOD = 100; 87 88 89 static String [] modeStrings = new String []{"", 90 "org.apache.axis.description.ParameterDesc.IN", 91 "org.apache.axis.description.ParameterDesc.OUT", 92 "org.apache.axis.description.ParameterDesc.INOUT"}; 93 94 95 static Map styles = new HashMap (); 96 97 98 static Map uses = new HashMap (); 99 100 static { 101 styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT"); 102 styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC"); 103 styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE"); 104 styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED"); 105 uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED"); 106 uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL"); 107 } 108 109 110 static int OPERDESC_PER_BLOCK = 10; 111 112 119 public JavaStubWriter(Emitter emitter, BindingEntry bEntry, 120 SymbolTable symbolTable) { 121 122 super(emitter, bEntry.getName() + "Stub", "stub"); 123 124 this.bEntry = bEntry; 125 this.binding = bEntry.getBinding(); 126 this.symbolTable = symbolTable; 127 } 129 134 protected String getExtendsText() { 135 return "extends org.apache.axis.client.Stub "; 136 } 138 143 protected String getImplementsText() { 144 return "implements " 145 + bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME) + " "; 146 } 148 154 protected void writeFileBody(PrintWriter pw) throws IOException { 155 156 PortType portType = binding.getPortType(); 157 HashSet types = getTypesInPortType(portType); 158 boolean hasMIME = Utils.hasMIME(bEntry); 159 160 if ((types.size() > 0) || hasMIME) { 161 pw.println( 162 " private java.util.Vector cachedSerClasses = new java.util.Vector();"); 163 pw.println( 164 " private java.util.Vector cachedSerQNames = new java.util.Vector();"); 165 pw.println( 166 " private java.util.Vector cachedSerFactories = new java.util.Vector();"); 167 pw.println( 168 " private java.util.Vector cachedDeserFactories = new java.util.Vector();"); 169 } 170 171 pw.println(); 172 pw.println( 173 " static org.apache.axis.description.OperationDesc [] _operations;"); 174 pw.println(); 175 writeOperationMap(pw); 176 pw.println(); 177 pw.println(" public " + className 178 + "() throws org.apache.axis.AxisFault {"); 179 pw.println(" this(null);"); 180 pw.println(" }"); 181 pw.println(); 182 pw.println( 183 " public " + className 184 + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {"); 185 pw.println(" this(service);"); 186 pw.println(" super.cachedEndpoint = endpointURL;"); 187 pw.println(" }"); 188 pw.println(); 189 pw.println( 190 " public " + className 191 + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {"); 192 pw.println(" if (service == null) {"); 193 pw.println( 194 " super.service = new org.apache.axis.client.Service();"); 195 pw.println(" } else {"); 196 pw.println(" super.service = service;"); 197 pw.println(" }"); 198 pw.println(" ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\"" + emitter.getTypeMappingVersion() + "\");"); 199 200 List deferredBindings = new ArrayList (); 201 202 int typeMappingCount = 0; 204 205 if (types.size() > 0) { 206 Iterator it = types.iterator(); 207 208 while (it.hasNext()) { 209 TypeEntry type = (TypeEntry) it.next(); 210 211 if (!Utils.shouldEmit(type)) { 212 continue; 213 } 214 215 if (typeMappingCount == 0) { 217 writeSerializationDecls( 218 pw, hasMIME, binding.getQName().getNamespaceURI()); 219 } 220 221 deferredBindings.add(type); 224 225 typeMappingCount++; 227 } 228 } 229 230 Collections.sort(deferredBindings, new Comparator () { 232 public int compare(Object a, Object b) { 233 TypeEntry type1 = (TypeEntry)a; 234 TypeEntry type2 = (TypeEntry)b; 235 return type1.getQName().toString().compareToIgnoreCase(type2.getQName().toString()); 236 } 237 }); 238 239 if ((typeMappingCount == 0) && hasMIME) { 242 writeSerializationDecls(pw, hasMIME, 243 binding.getQName().getNamespaceURI()); 244 245 typeMappingCount++; 246 } 247 248 boolean needsMultipleBindingMethods = false; 251 252 if (deferredBindings.size() < MAXIMUM_BINDINGS_PER_METHOD) { 253 254 for (Iterator it = deferredBindings.iterator(); it.hasNext();) { 256 writeSerializationInit(pw, (TypeEntry) it.next()); 257 } 258 } else { 259 needsMultipleBindingMethods = true; 260 261 int methodCount = calculateBindingMethodCount(deferredBindings); 262 263 for (int i = 0; i < methodCount; i++) { 266 pw.println(" addBindings" + i + "();"); 267 } 268 } 269 270 pw.println(" }"); 271 pw.println(); 272 273 if (needsMultipleBindingMethods) { 275 writeBindingMethods(pw, deferredBindings); 276 pw.println(); 277 } 278 279 pw.println( 280 " protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {"); 281 pw.println(" try {"); 282 pw.println(" org.apache.axis.client.Call _call = super._createCall();"); 283 pw.println(" if (super.maintainSessionSet) {"); 284 pw.println( 285 " _call.setMaintainSession(super.maintainSession);"); 286 pw.println(" }"); 287 pw.println(" if (super.cachedUsername != null) {"); 288 pw.println(" _call.setUsername(super.cachedUsername);"); 289 pw.println(" }"); 290 pw.println(" if (super.cachedPassword != null) {"); 291 pw.println(" _call.setPassword(super.cachedPassword);"); 292 pw.println(" }"); 293 pw.println(" if (super.cachedEndpoint != null) {"); 294 pw.println( 295 " _call.setTargetEndpointAddress(super.cachedEndpoint);"); 296 pw.println(" }"); 297 pw.println(" if (super.cachedTimeout != null) {"); 298 pw.println(" _call.setTimeout(super.cachedTimeout);"); 299 pw.println(" }"); 300 pw.println(" if (super.cachedPortName != null) {"); 301 pw.println(" _call.setPortName(super.cachedPortName);"); 302 pw.println(" }"); 303 pw.println( 304 " java.util.Enumeration keys = super.cachedProperties.keys();"); 305 pw.println(" while (keys.hasMoreElements()) {"); 306 pw.println( 307 " java.lang.String key = (java.lang.String) keys.nextElement();"); 308 pw.println( 309 " _call.setProperty(key, super.cachedProperties.get(key));"); 310 pw.println(" }"); 311 312 if (typeMappingCount > 0) { 313 pw.println(" // " + Messages.getMessage("typeMap00")); 314 pw.println(" // " + Messages.getMessage("typeMap01")); 315 pw.println(" // " + Messages.getMessage("typeMap02")); 316 pw.println(" // " + Messages.getMessage("typeMap03")); 317 pw.println(" // " + Messages.getMessage("typeMap04")); 318 pw.println(" synchronized (this) {"); 319 pw.println(" if (firstCall()) {"); 320 321 pw.println(" // " 324 + Messages.getMessage("mustSetStyle")); 325 326 if (bEntry.hasLiteral()) { 327 pw.println(" _call.setEncodingStyle(null);"); 328 } else { 329 Iterator iterator = 330 bEntry.getBinding().getExtensibilityElements().iterator(); 331 332 while (iterator.hasNext()) { 333 Object obj = iterator.next(); 334 335 if (obj instanceof SOAPBinding) { 336 pw.println( 337 " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);"); 338 pw.println( 339 " _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);"); 340 } else if (obj instanceof UnknownExtensibilityElement) { 341 342 UnknownExtensibilityElement unkElement = 344 (UnknownExtensibilityElement) obj; 345 QName name = 346 unkElement.getElementType(); 347 348 if (name.getNamespaceURI().equals( 349 Constants.URI_WSDL12_SOAP) 350 && name.getLocalPart().equals("binding")) { 351 pw.println( 352 " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);"); 353 pw.println( 354 " _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);"); 355 } 356 } 357 } 358 } 359 360 pw.println( 361 " for (int i = 0; i < cachedSerFactories.size(); ++i) {"); 362 pw.println( 363 " java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);"); 364 pw.println( 365 " javax.xml.namespace.QName qName ="); 366 pw.println( 367 " (javax.xml.namespace.QName) cachedSerQNames.get(i);"); 368 pw.println( 369 " java.lang.Object x = cachedSerFactories.get(i);"); 370 pw.println( 371 " if (x instanceof Class) {"); 372 pw.println( 373 " java.lang.Class sf = (java.lang.Class)"); 374 pw.println( 375 " cachedSerFactories.get(i);"); 376 pw.println( 377 " java.lang.Class df = (java.lang.Class)"); 378 pw.println( 379 " cachedDeserFactories.get(i);"); 380 pw.println( 381 " _call.registerTypeMapping(cls, qName, sf, df, false);"); 382 383 pw.println(" }"); 384 pw.println( 385 " else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) {"); 386 pw.println( 387 " org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory)"); 388 pw.println( 389 " cachedSerFactories.get(i);"); 390 pw.println( 391 " org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory)"); 392 pw.println( 393 " cachedDeserFactories.get(i);"); 394 pw.println( 395 " _call.registerTypeMapping(cls, qName, sf, df, false);"); 396 397 pw.println(" }"); 398 pw.println(" }"); 399 pw.println(" }"); 400 pw.println(" }"); 401 } 402 403 pw.println(" return _call;"); 404 pw.println(" }"); 405 pw.println(" catch (java.lang.Throwable _t) {"); 406 pw.println(" throw new org.apache.axis.AxisFault(\"" 407 + Messages.getMessage("badCall01") + "\", _t);"); 408 pw.println(" }"); 409 pw.println(" }"); 410 pw.println(); 411 412 List operations = binding.getBindingOperations(); 413 414 for (int i = 0; i < operations.size(); ++i) { 415 BindingOperation operation = (BindingOperation) operations.get(i); 416 Parameters parameters = 417 bEntry.getParameters(operation.getOperation()); 418 419 String soapAction = ""; 421 String opStyle = null; 422 Iterator operationExtensibilityIterator = 423 operation.getExtensibilityElements().iterator(); 424 425 for (; operationExtensibilityIterator.hasNext();) { 426 Object obj = operationExtensibilityIterator.next(); 427 428 if (obj instanceof SOAPOperation) { 429 soapAction = ((SOAPOperation) obj).getSoapActionURI(); 430 opStyle = ((SOAPOperation) obj).getStyle(); 431 432 break; 433 } else if (obj instanceof UnknownExtensibilityElement) { 434 435 UnknownExtensibilityElement unkElement = 437 (UnknownExtensibilityElement) obj; 438 QName name = 439 unkElement.getElementType(); 440 441 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 442 && name.getLocalPart().equals("operation")) { 443 if (unkElement.getElement().getAttribute("soapAction") 444 != null) { 445 soapAction = unkElement.getElement().getAttribute( 446 "soapAction"); 447 } 448 449 opStyle = unkElement.getElement().getAttribute("style"); 450 } 451 } 452 } 453 454 Operation ptOperation = operation.getOperation(); 455 OperationType type = ptOperation.getStyle(); 456 457 if ((OperationType.NOTIFICATION.equals(type)) 460 || (OperationType.SOLICIT_RESPONSE.equals(type))) { 461 pw.println(parameters.signature); 462 pw.println(); 463 } else { 464 writeOperation(pw, operation, parameters, soapAction, opStyle, 465 type == OperationType.ONE_WAY, i); 466 } 467 } 468 } 470 477 private int calculateBindingMethodCount(List deferredBindings) { 478 479 int methodCount = deferredBindings.size() / MAXIMUM_BINDINGS_PER_METHOD; 480 481 if ((deferredBindings.size() % MAXIMUM_BINDINGS_PER_METHOD) != 0) { 482 methodCount++; 483 } 484 485 return methodCount; 486 } 487 488 499 protected void writeBindingMethods(PrintWriter pw, List deferredBindings) { 500 501 int methodCount = calculateBindingMethodCount(deferredBindings); 502 503 for (int i = 0; i < methodCount; i++) { 504 pw.println(" private void addBindings" + i + "() {"); 505 506 writeSerializationDecls(pw, false, null); 509 510 for (int j = 0; j < MAXIMUM_BINDINGS_PER_METHOD; j++) { 511 int absolute = i * MAXIMUM_BINDINGS_PER_METHOD + j; 512 513 if (absolute == deferredBindings.size()) { 514 break; } 516 517 writeSerializationInit( 518 pw, (TypeEntry) deferredBindings.get(absolute)); 519 } 520 521 pw.println(" }"); 522 } 523 } 524 525 530 protected void writeOperationMap(PrintWriter pw) { 531 532 List operations = binding.getBindingOperations(); 533 534 pw.println(" static {"); 535 pw.println( 536 " _operations = new org.apache.axis.description.OperationDesc[" 537 + operations.size() + "];"); 538 539 for (int j = 0, k = 0; j < operations.size(); ++j) { 540 if ((j % OPERDESC_PER_BLOCK) == 0) { 541 k++; 542 543 pw.println(" _initOperationDesc" + k + "();"); 544 } 545 } 546 547 for (int i = 0, k = 0; i < operations.size(); ++i) { 548 if ((i % OPERDESC_PER_BLOCK) == 0) { 549 k++; 550 551 pw.println(" }\n"); 552 pw.println(" private static void _initOperationDesc" + k 553 + "(){"); 554 pw.println( 555 " org.apache.axis.description.OperationDesc oper;"); 556 pw.println( 557 " org.apache.axis.description.ParameterDesc param;"); 558 } 559 560 BindingOperation operation = (BindingOperation) operations.get(i); 561 Parameters parameters = 562 bEntry.getParameters(operation.getOperation()); 563 564 String opStyle = null; 566 Iterator operationExtensibilityIterator = 567 operation.getExtensibilityElements().iterator(); 568 569 for (; operationExtensibilityIterator.hasNext();) { 570 Object obj = operationExtensibilityIterator.next(); 571 572 if (obj instanceof SOAPOperation) { 573 opStyle = ((SOAPOperation) obj).getStyle(); 574 575 break; 576 } else if (obj instanceof UnknownExtensibilityElement) { 577 578 UnknownExtensibilityElement unkElement = 580 (UnknownExtensibilityElement) obj; 581 QName name = 582 unkElement.getElementType(); 583 584 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 585 && name.getLocalPart().equals("operation")) { 586 opStyle = unkElement.getElement().getAttribute("style"); 587 } 588 } 589 } 590 591 Operation ptOperation = operation.getOperation(); 592 OperationType type = ptOperation.getStyle(); 593 594 if ((OperationType.NOTIFICATION.equals(type)) 597 || (OperationType.SOLICIT_RESPONSE.equals(type))) { 598 pw.println(parameters.signature); 599 pw.println(); 600 } 601 602 String operName = operation.getName(); 603 String indent = " "; 604 605 pw.println( 606 indent 607 + "oper = new org.apache.axis.description.OperationDesc();"); 608 pw.println(indent + "oper.setName(\"" + operName + "\");"); 609 610 for (int j = 0; j < parameters.list.size(); ++j) { 612 Parameter p = (Parameter) parameters.list.get(j); 613 614 QName paramType = Utils.getXSIType(p); 616 617 String javaType = Utils.getParameterTypeName(p); 619 if (javaType != null) { 620 javaType += ".class, "; 621 } else { 622 javaType = "null, "; 623 } 624 625 String paramNameText = Utils.getNewQNameWithLastLocalPart(p.getQName()); 627 String paramTypeText = Utils.getNewQName(paramType); 628 629 boolean isInHeader = p.isInHeader(); 632 boolean isOutHeader = p.isOutHeader(); 633 634 pw.println(" param = new org.apache.axis.description.ParameterDesc(" + 635 paramNameText + ", " + 636 modeStrings[p.getMode()] + ", " + 637 paramTypeText + ", " + 638 javaType + 639 isInHeader + ", " + isOutHeader + ");"); 640 641 QName itemQName = Utils.getItemQName(p.getType()); 642 if (itemQName != null) { 643 pw.println(" param.setItemQName(" + 644 Utils.getNewQName(itemQName) + ");"); 645 } 646 647 pw.println(" oper.addParameter(param);"); 648 } 649 650 Parameter returnParam = parameters.returnParam; 652 if (returnParam != null) { 653 654 QName returnType = Utils.getXSIType(returnParam); 656 657 String javaType = Utils.getParameterTypeName(returnParam); 659 660 if (javaType == null) { 661 javaType = ""; 662 } else { 663 javaType += ".class"; 664 } 665 666 pw.println(" oper.setReturnType(" 667 + Utils.getNewQName(returnType) + ");"); 668 pw.println(" oper.setReturnClass(" + javaType + ");"); 669 670 QName returnQName = returnParam.getQName(); 671 672 if (returnQName != null) { 673 pw.println(" oper.setReturnQName(" 674 + Utils.getNewQNameWithLastLocalPart(returnQName) + ");"); 675 } 676 677 if (returnParam.isOutHeader()) { 678 pw.println(" oper.setReturnHeader(true);"); 679 } 680 681 QName itemQName = Utils.getItemQName(returnParam.getType()); 682 if (itemQName != null) { 683 pw.println(" param = oper.getReturnParamDesc();"); 684 pw.println(" param.setItemQName(" + 685 Utils.getNewQName(itemQName) + ");"); 686 } 687 688 } else { 689 pw.println( 690 " oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);"); 691 } 692 693 boolean hasMIME = Utils.hasMIME(bEntry, operation); 694 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 695 Use use = bEntry.getInputBodyType(operation.getOperation()); 696 697 if ((style == Style.DOCUMENT) && symbolTable.isWrapped()) { 698 style = Style.WRAPPED; 699 } 700 701 if (!hasMIME) { 702 pw.println(" oper.setStyle(" + styles.get(style) + ");"); 703 pw.println(" oper.setUse(" + uses.get(use) + ");"); 704 } 705 706 writeFaultInfo(pw, operation); 708 pw.println(indent + "_operations[" + i + "] = oper;"); 709 pw.println(""); 710 } 711 712 pw.println(" }"); 713 } 714 715 722 private HashSet getTypesInPortType(PortType portType) { 723 724 HashSet types = new HashSet (); 725 HashSet firstPassTypes = new HashSet (); 726 727 List operations = portType.getOperations(); 729 730 for (int i = 0; i < operations.size(); ++i) { 731 Operation op = (Operation) operations.get(i); 732 733 firstPassTypes.addAll(getTypesInOperation(op)); 734 } 735 736 Iterator i = firstPassTypes.iterator(); 739 740 while (i.hasNext()) { 741 TypeEntry type = (TypeEntry) i.next(); 742 743 if (!types.contains(type)) { 744 types.add(type); 745 types.addAll(type.getNestedTypes(symbolTable, true)); 746 } 747 } 748 749 if(emitter.isAllWanted()) { 750 HashMap rawSymbolTable = symbolTable.getHashMap(); 751 for(Iterator j = rawSymbolTable.values().iterator(); j.hasNext(); ) { 752 Vector typeVector = (Vector )j.next(); 753 for(Iterator k = typeVector.iterator(); k.hasNext(); ) { 754 Object symbol = k.next(); 755 if(symbol instanceof DefinedType) { 756 TypeEntry type = (TypeEntry)symbol; 757 if(!types.contains(type)) { 758 types.add(type); 759 } 760 } 761 } 762 } 763 } 764 return types; 765 } 767 774 private HashSet getTypesInOperation(Operation operation) { 775 776 HashSet types = new HashSet (); 777 Vector v = new Vector (); 778 Parameters params = bEntry.getParameters(operation); 779 780 for (int i = 0; i < params.list.size(); i++) { 782 Parameter p = (Parameter) params.list.get(i); 783 784 v.add(p.getType()); 785 } 786 787 if (params.returnParam != null) { 789 v.add(params.returnParam.getType()); 790 } 791 792 Map faults = operation.getFaults(); 794 795 if (faults != null) { 796 Iterator i = faults.values().iterator(); 797 798 while (i.hasNext()) { 799 Fault f = (Fault) i.next(); 800 801 partTypes(v, f.getMessage().getOrderedParts(null)); 802 } 803 } 804 805 for (int i = 0; i < v.size(); i++) { 807 types.add(v.get(i)); 808 } 809 810 return types; 811 } 813 819 private void partTypes(Vector v, Collection parts) { 820 821 Iterator i = parts.iterator(); 822 823 while (i.hasNext()) { 824 Part part = (Part) i.next(); 825 QName qType = part.getTypeName(); 826 827 if (qType != null) { 828 v.add(symbolTable.getType(qType)); 829 } else { 830 qType = part.getElementName(); 831 832 if (qType != null) { 833 v.add(symbolTable.getElement(qType)); 834 } 835 } 836 } } 839 845 protected void writeFaultInfo(PrintWriter pw, BindingOperation bindOp) { 846 847 Map faultMap = bEntry.getFaults(); 848 849 ArrayList faults = (ArrayList ) faultMap.get(bindOp); 851 852 if (faults == null) { 854 return; 855 } 856 857 for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) { 859 FaultInfo info = (FaultInfo) faultIt.next(); 860 QName qname = info.getQName(); 861 Message message = info.getMessage(); 862 863 if (qname == null) { 865 continue; 866 } 867 868 String className = Utils.getFullExceptionName(message, symbolTable); 870 871 pw.println( 873 " oper.addFault(new org.apache.axis.description.FaultDesc("); 874 pw.println(" " + Utils.getNewQName(qname) 875 + ","); 876 pw.println(" \"" + className + "\","); 877 pw.println(" " 878 + Utils.getNewQName(info.getXMLType()) + ", "); 879 pw.println(" " 880 + Utils.isFaultComplex(message, symbolTable)); 881 pw.println(" ));"); 882 } 883 } 884 885 892 protected void writeSerializationDecls(PrintWriter pw, boolean hasMIME, 893 String namespace) { 894 895 pw.println(" java.lang.Class cls;"); 896 pw.println(" javax.xml.namespace.QName qName;"); 897 pw.println(" javax.xml.namespace.QName qName2;"); 898 pw.println( 899 " java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;"); 900 pw.println( 901 " java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;"); 902 pw.println( 903 " java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;"); 904 pw.println( 905 " java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;"); 906 pw.println( 907 " java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;"); 908 pw.println( 909 " java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;"); 910 pw.println( 911 " java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;"); 912 pw.println( 913 " java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;"); 914 pw.println( 915 " java.lang.Class simplelistsf = org.apache.axis.encoding.ser.SimpleListSerializerFactory.class;"); 916 pw.println( 917 " java.lang.Class simplelistdf = org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class;"); 918 919 if (hasMIME) { 920 pw.println( 921 " java.lang.Class mimesf = org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;"); 922 pw.println( 923 " java.lang.Class mimedf = org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;"); 924 pw.println(); 925 926 QName qname = new QName (namespace, "DataHandler"); 927 928 pw.println(" qName = new javax.xml.namespace.QName(\"" 929 + qname.getNamespaceURI() + "\", \"" 930 + qname.getLocalPart() + "\");"); 931 pw.println(" cachedSerQNames.add(qName);"); 932 pw.println(" cls = javax.activation.DataHandler.class;"); 933 pw.println(" cachedSerClasses.add(cls);"); 934 pw.println(" cachedSerFactories.add(mimesf);"); 935 pw.println(" cachedDeserFactories.add(mimedf);"); 936 pw.println(); 937 } 938 } 940 946 protected void writeSerializationInit(PrintWriter pw, TypeEntry type) { 947 948 QName qname = type.getQName(); 949 950 pw.println(" qName = new javax.xml.namespace.QName(\"" 951 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart() 952 + "\");"); 953 pw.println(" cachedSerQNames.add(qName);"); 954 pw.println(" cls = " + type.getName() + ".class;"); 955 pw.println(" cachedSerClasses.add(cls);"); 956 957 if (type.getName().endsWith("[]")) { 958 if (SchemaUtils.isListWithItemType(type.getNode())) { 959 pw.println(" cachedSerFactories.add(simplelistsf);"); 960 pw.println(" cachedDeserFactories.add(simplelistdf);"); 961 } else { 962 if (type.getComponentType() != null) { 965 QName ct = type.getComponentType(); 966 QName name = type.getItemQName(); 967 pw.println(" qName = new javax.xml.namespace.QName(\"" 968 + ct.getNamespaceURI() + "\", \"" + ct.getLocalPart() 969 + "\");"); 970 if(name != null) { 971 pw.println(" qName2 = new javax.xml.namespace.QName(\"" 972 + name.getNamespaceURI() + "\", \"" + name.getLocalPart() 973 + "\");"); 974 } else { 975 pw.println(" qName2 = null;"); 976 } 977 pw.println(" cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));"); 978 pw.println(" cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());"); 979 } else { 980 pw.println(" cachedSerFactories.add(arraysf);"); 981 pw.println(" cachedDeserFactories.add(arraydf);"); 982 } 983 } 984 } else if ((type.getNode() != null) && (Utils.getEnumerationBaseAndValues( 985 type.getNode(), symbolTable) != null)) { 986 pw.println(" cachedSerFactories.add(enumsf);"); 987 pw.println(" cachedDeserFactories.add(enumdf);"); 988 } else if (type.isSimpleType()) { 989 pw.println(" cachedSerFactories.add(simplesf);"); 990 pw.println(" cachedDeserFactories.add(simpledf);"); 991 } else if (type.getBaseType() != null) { 992 993 pw.println(" cachedSerFactories.add(null);"); 1002 pw.println(" cachedDeserFactories.add(simpledf);"); 1003 } else { 1004 pw.println(" cachedSerFactories.add(beansf);"); 1005 pw.println(" cachedDeserFactories.add(beandf);"); 1006 } 1007 1008 pw.println(); 1009 } 1011 1022 protected void writeOperation(PrintWriter pw, BindingOperation operation, 1023 Parameters parms, String soapAction, 1024 String opStyle, boolean oneway, int opIndex) { 1025 1026 writeComment(pw, operation.getDocumentationElement(), true); 1027 pw.println(parms.signature + " {"); 1028 pw.println(" if (super.cachedEndpoint == null) {"); 1029 pw.println( 1030 " throw new org.apache.axis.NoEndPointException();"); 1031 pw.println(" }"); 1032 pw.println(" org.apache.axis.client.Call _call = createCall();"); 1033 pw.println(" _call.setOperation(_operations[" + opIndex + "]);"); 1034 1035 if (soapAction != null) { 1037 pw.println(" _call.setUseSOAPAction(true);"); 1038 pw.println(" _call.setSOAPActionURI(\"" + soapAction 1039 + "\");"); 1040 } 1041 1042 boolean hasMIME = Utils.hasMIME(bEntry, operation); 1043 1044 Use use = bEntry.getInputBodyType(operation.getOperation()); 1046 1047 if (use == Use.LITERAL) { 1048 1049 pw.println(" _call.setEncodingStyle(null);"); 1051 1052 pw.println( 1054 " _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);"); 1055 } 1056 1057 if (hasMIME || (use == Use.LITERAL)) { 1058 1059 pw.println( 1065 " _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);"); 1066 } 1067 1068 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle()); 1069 1070 if ((style == Style.DOCUMENT) && symbolTable.isWrapped()) { 1071 style = Style.WRAPPED; 1072 } 1073 1074 Iterator iterator = 1075 bEntry.getBinding().getExtensibilityElements().iterator(); 1076 1077 while (iterator.hasNext()) { 1078 Object obj = iterator.next(); 1079 1080 if (obj instanceof SOAPBinding) { 1081 pw.println( 1082 " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);"); 1083 } else if (obj instanceof UnknownExtensibilityElement) { 1084 1085 UnknownExtensibilityElement unkElement = 1087 (UnknownExtensibilityElement) obj; 1088 QName name = 1089 unkElement.getElementType(); 1090 1091 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 1092 && name.getLocalPart().equals("binding")) { 1093 pw.println( 1094 " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);"); 1095 } 1096 } 1097 } 1098 1099 if (style == Style.WRAPPED) { 1101 1102 Map partsMap = 1106 operation.getOperation().getInput().getMessage().getParts(); 1107 Iterator i = partsMap.values().iterator(); 1108 if(i.hasNext()) { 1109 Part p = (Part) partsMap.values().iterator().next(); 1110 QName q = p.getElementName(); 1111 1112 pw.println(" _call.setOperationName(" + Utils.getNewQName(q) 1113 + ");"); 1114 } else { 1115 log.warn(Messages.getMessage("missingPartsForMessage00",operation.getOperation().getInput().getMessage().getQName().toString())); 1116 } 1117 } else { 1118 QName elementQName = Utils.getOperationQName(operation, bEntry, 1119 symbolTable); 1120 1121 if (elementQName != null) { 1122 pw.println(" _call.setOperationName(" 1123 + Utils.getNewQName(elementQName) + ");"); 1124 } 1125 } 1126 1127 pw.println(); 1128 1129 pw.println(" setRequestHeaders(_call);"); 1131 1132 pw.println(" setAttachments(_call);"); 1134 1135 if (bEntry.isOperationDIME(operation.getOperation().getName())) { 1137 pw.println( 1138 " _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);"); 1139 } 1140 1141 if (oneway) { 1143 pw.print(" _call.invokeOneWay("); 1144 } else { 1145 pw.print(" try {"); 1146 pw.print(" java.lang.Object _resp = _call.invoke("); 1147 } 1148 1149 pw.print("new java.lang.Object[] {"); 1150 writeParameters(pw, parms); 1151 pw.println("});"); 1152 pw.println(); 1153 1154 if (!oneway) { 1155 writeResponseHandling(pw, parms); 1156 } 1157 1158 pw.println(" }"); 1159 pw.println(); 1160 } 1162 1168 protected void writeParameters(PrintWriter pw, Parameters parms) { 1169 1170 boolean needComma = false; 1172 1173 for (int i = 0; i < parms.list.size(); ++i) { 1174 Parameter p = (Parameter) parms.list.get(i); 1175 1176 if (p.getMode() != Parameter.OUT) { 1177 if (needComma) { 1178 pw.print(", "); 1179 } else { 1180 needComma = true; 1181 } 1182 1183 String javifiedName = Utils.xmlNameToJava(p.getName()); 1184 1185 if (p.getMode() != Parameter.IN) { 1186 javifiedName += ".value"; 1187 } 1188 1189 if (p.getMIMEInfo() == null && !p.isOmittable()) { 1190 javifiedName = Utils.wrapPrimitiveType(p.getType(), 1191 javifiedName); 1192 } 1193 1194 pw.print(javifiedName); 1195 } 1196 } 1197 } 1199 1205 protected void writeResponseHandling(PrintWriter pw, Parameters parms) { 1206 1207 pw.println(" if (_resp instanceof java.rmi.RemoteException) {"); 1208 pw.println(" throw (java.rmi.RemoteException)_resp;"); 1209 pw.println(" }"); 1210 1211 int allOuts = parms.outputs + parms.inouts; 1212 1213 if (allOuts > 0) { 1214 pw.println(" else {"); 1215 pw.println(" extractAttachments(_call);"); 1216 1217 if (allOuts == 1) { 1218 if (parms.returnParam != null) { 1219 writeOutputAssign(pw, "return ", 1220 parms.returnParam, "_resp"); 1221 } else { 1222 1223 int i = 0; 1225 Parameter p = (Parameter) parms.list.get(i); 1226 1227 while (p.getMode() == Parameter.IN) { 1228 p = (Parameter) parms.list.get(++i); 1229 } 1230 1231 String javifiedName = Utils.xmlNameToJava(p.getName()); 1232 String qnameName = Utils.getNewQNameWithLastLocalPart(p.getQName()); 1233 1234 pw.println(" java.util.Map _output;"); 1235 pw.println( 1236 " _output = _call.getOutputParams();"); 1237 writeOutputAssign(pw, 1238 javifiedName + ".value = ", 1239 p, 1240 "_output.get(" + qnameName + ")"); 1241 } 1242 } else { 1243 1244 pw.println(" java.util.Map _output;"); 1246 pw.println(" _output = _call.getOutputParams();"); 1247 1248 for (int i = 0; i < parms.list.size(); ++i) { 1249 Parameter p = (Parameter) parms.list.get(i); 1250 String javifiedName = Utils.xmlNameToJava(p.getName()); 1251 String qnameName = 1252 Utils.getNewQNameWithLastLocalPart(p.getQName()); 1253 1254 if (p.getMode() != Parameter.IN) { 1255 writeOutputAssign(pw, 1256 javifiedName + ".value = ", 1257 p, 1258 "_output.get(" + qnameName + ")"); 1259 } 1260 } 1261 1262 if (parms.returnParam != null) { 1263 writeOutputAssign(pw, 1264 "return ", 1265 parms.returnParam, 1266 "_resp"); 1267 } 1268 } 1269 1270 pw.println(" }"); 1271 } else { 1272 pw.println(" extractAttachments(_call);"); 1273 } 1274 Map faults = parms.faults; 1277 List exceptionsThrowsList = new ArrayList (); 1279 int index = parms.signature.indexOf("throws"); 1280 if (index != -1) { 1281 String [] thrExcep = StringUtils.split(parms.signature.substring(index+6),','); 1282 for (int i = 0; i < thrExcep.length; i++) { 1283 exceptionsThrowsList.add(thrExcep[i].trim()); 1284 } 1285 } 1286 pw.println(" } catch (org.apache.axis.AxisFault axisFaultException) {"); 1287 if (faults != null && faults.size() > 0) { 1288 pw.println(" if (axisFaultException.detail != null) {"); 1289 for (Iterator faultIt = exceptionsThrowsList.iterator(); faultIt 1290 .hasNext();) { 1291 String exceptionFullName = (String ) faultIt.next(); 1292 pw.println(" if (axisFaultException.detail instanceof " 1293 + exceptionFullName + ") {"); 1294 pw.println(" throw (" + exceptionFullName 1295 + ") axisFaultException.detail;"); 1296 pw.println(" }"); 1297 } 1298 pw.println(" }"); 1299 } 1300 pw.println(" throw axisFaultException;"); 1301 pw.println("}"); 1302 } 1304 1311 protected void writeOutputAssign(PrintWriter pw, String target, 1312 Parameter param, 1313 String source) { 1314 1315 TypeEntry type = param.getType(); 1316 1317 if ((type != null) && (type.getName() != null)) { 1318 1319 String typeName = type.getName(); 1320 if ((param.isOmittable() && param.getType().getDimensions().equals("")) 1323 || param.getType().getUnderlTypeNillable()) { 1324 1325 typeName = Utils.getWrapperType(type); 1326 } 1327 1328 pw.println(" try {"); 1331 pw.println(" " + target 1332 + Utils.getResponseString(param, source)); 1333 pw.println( 1334 " } catch (java.lang.Exception _exception) {"); 1335 pw.println( 1336 " " + target 1337 + Utils.getResponseString(param, 1338 "org.apache.axis.utils.JavaUtils.convert(" + 1339 source + ", " + typeName + ".class)")); 1340 pw.println(" }"); 1341 } else { 1342 pw.println(" " + target 1343 + Utils.getResponseString(param, source)); 1344 } 1345 } 1346} | Popular Tags |