src/share/jaxws_classes/com/sun/tools/internal/ws/processor/modeler/wsdl/WSDLModeler.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.processor.modeler.wsdl;
  27 
  28 import com.sun.codemodel.internal.JType;

  29 import com.sun.istack.internal.SAXParseException2;
  30 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
  31 import com.sun.tools.internal.ws.processor.generator.Names;
  32 import com.sun.tools.internal.ws.processor.model.*;
  33 import com.sun.tools.internal.ws.processor.model.Fault;
  34 import com.sun.tools.internal.ws.processor.model.Operation;
  35 import com.sun.tools.internal.ws.processor.model.Port;
  36 import com.sun.tools.internal.ws.processor.model.Service;
  37 import com.sun.tools.internal.ws.processor.model.java.*;
  38 import com.sun.tools.internal.ws.processor.model.jaxb.*;
  39 import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
  40 import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
  41 import com.sun.tools.internal.ws.resources.ModelerMessages;
  42 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
  43 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
  44 import com.sun.tools.internal.ws.wsdl.document.*;
  45 import com.sun.tools.internal.ws.wsdl.document.Message;
  46 import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
  47 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
  48 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
  49 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
  50 import com.sun.tools.internal.ws.wsdl.document.soap.*;
  51 import com.sun.tools.internal.ws.wsdl.framework.*;
  52 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
  53 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
  54 import com.sun.tools.internal.xjc.api.S2JJAXBModel;
  55 import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
  56 import com.sun.tools.internal.xjc.api.XJC;
  57 import com.sun.xml.internal.ws.spi.db.BindingContext;
  58 import com.sun.xml.internal.ws.spi.db.BindingHelper;
  59 import com.sun.xml.internal.ws.util.xml.XmlUtil;
  60 import org.xml.sax.InputSource;
  61 import org.xml.sax.Locator;
  62 import org.xml.sax.SAXException;
  63 import org.xml.sax.SAXParseException;
  64 import org.xml.sax.helpers.LocatorImpl;
  65 
  66 import javax.jws.WebParam.Mode;
  67 import javax.xml.namespace.QName;
  68 import java.util.*;
  69 import java.io.IOException;
  70 
  71 
  72 /**
  73  * The WSDLModeler processes a WSDL to create a Model.
  74  *
  75  * @author WS Development Team
  76  */
  77 public class WSDLModeler extends WSDLModelerBase {
  78 
  79     //map of wsdl:operation QName to <soapenv:Body> child, as per BP it must be unique in a port
  80     private final Map<QName, Operation> uniqueBodyBlocks = new HashMap<QName, Operation>();
  81     private final QName VOID_BODYBLOCK = new QName("");
  82     private final ClassNameCollector classNameCollector;
  83     private final String explicitDefaultPackage;
  84 
  85     public WSDLModeler(WsimportOptions options, ErrorReceiver receiver, MetadataFinder forest) {
  86         super(options, receiver,forest);
  87         this.classNameCollector = new ClassNameCollector();
  88         this.explicitDefaultPackage = options.defaultPackage;
  89     }
  90 
  91 
  92     protected enum StyleAndUse {
  93         RPC_LITERAL, DOC_LITERAL
  94     }
  95 
  96     private JAXBModelBuilder jaxbModelBuilder;
  97 

  98     public Model buildModel() {
  99         try {
 100             parser = new WSDLParser(options, errReceiver, forest);
 101             parser.addParserListener(new ParserListener() {

 102                 public void ignoringExtension(Entity entity, QName name, QName parent) {
 103                     if (parent.equals(WSDLConstants.QNAME_TYPES)) {
 104                         // check for a schema element with the wrong namespace URI
 105                         if (name.getLocalPart().equals("schema")
 106                                 && !name.getNamespaceURI().equals("")) {
 107                             warning(entity, ModelerMessages.WSDLMODELER_WARNING_IGNORING_UNRECOGNIZED_SCHEMA_EXTENSION(name.getNamespaceURI()));
 108                         }
 109                     }
 110 
 111                 }
 112 

 113                 public void doneParsingEntity(QName element, Entity entity) {
 114                 }
 115             });
 116 
 117             document = parser.parse();
 118             if (document == null || document.getDefinitions() == null)
 119                 return null;

 120 
 121             document.validateLocally();
 122             Model model = internalBuildModel(document);
 123             if(model == null || errReceiver.hadError())
 124                 return null;

 125             //ClassNameCollector classNameCollector = new ClassNameCollector();
 126             classNameCollector.process(model);
 127             if (classNameCollector.getConflictingClassNames().isEmpty()) {
 128                 if(errReceiver.hadError())
 129                     return null;

 130                 return model;
 131             }
 132             // do another pass, this time with conflict resolution enabled
 133             model = internalBuildModel(document);
 134 
 135             classNameCollector.process(model);
 136             if (classNameCollector.getConflictingClassNames().isEmpty()) {
 137                 // we're done
 138                 if(errReceiver.hadError())
 139                     return null;

 140                 return model;
 141             }
 142             // give up
 143             StringBuffer conflictList = new StringBuffer();
 144             boolean first = true;
 145             for (Iterator iter =
 146                     classNameCollector.getConflictingClassNames().iterator();
 147                  iter.hasNext();
 148                     ) {
 149                 if (!first) {
 150                     conflictList.append(", ");
 151                 } else {
 152                     first = false;
 153                 }
 154                 conflictList.append((String) iter.next());
 155             }
 156             error(document.getDefinitions(), ModelerMessages.WSDLMODELER_UNSOLVABLE_NAMING_CONFLICTS(conflictList.toString()));
 157         } catch (ModelException e) {
 158             reportError(document.getDefinitions(), e.getMessage(), e);
 159         } catch (ParseException e) {
 160             errReceiver.error(e);
 161         } catch (ValidationException e) {
 162             errReceiver.error(e.getMessage(), e);
 163         } catch (SAXException e) {


 191         model.setProperty(
 192                 ModelProperties.PROPERTY_MODELER_NAME,
 193                 ModelProperties.WSDL_MODELER_NAME);
 194 
 195         _javaExceptions = new HashMap<String, JavaException>();
 196         _bindingNameToPortMap = new HashMap<QName, Port>();
 197 
 198         // grab target namespace
 199         model.setTargetNamespaceURI(document.getDefinitions().getTargetNamespaceURI());
 200 
 201         setDocumentationIfPresent(model,
 202                 document.getDefinitions().getDocumentation());
 203 
 204         boolean hasServices = document.getDefinitions().services().hasNext();
 205         if (hasServices) {
 206             for (Iterator iter = document.getDefinitions().services();
 207                  iter.hasNext();
 208                     ) {
 209                 processService((com.sun.tools.internal.ws.wsdl.document.Service) iter.next(),
 210                         model, document);
 211                 hasServices = true;
 212             }
 213         } else {
 214             // emit a warning if there are no service definitions
 215             warning(model.getEntity(), ModelerMessages.WSDLMODELER_WARNING_NO_SERVICE_DEFINITIONS_FOUND());
 216         }
 217 
 218         return model;
 219     }
 220 
 221     /* (non-Javadoc)
 222      * @see WSDLModelerBase#processService(Service, Model, WSDLDocument)
 223      */
 224     protected void processService(com.sun.tools.internal.ws.wsdl.document.Service wsdlService, Model model, WSDLDocument document) {
 225         QName serviceQName = getQNameOf(wsdlService);
 226         String serviceInterface = getServiceInterfaceName(serviceQName, wsdlService);
 227         if (isConflictingServiceClassName(serviceInterface)) {
 228             serviceInterface += "_Service";
 229         }
 230         Service service =
 231                 new Service(


 259 
 260             //clear the  unique block map
 261             uniqueBodyBlocks.clear();
 262 
 263             QName portQName = getQNameOf(wsdlPort);
 264             Port port = new Port(portQName, wsdlPort);
 265 
 266             setDocumentationIfPresent(port, wsdlPort.getDocumentation());
 267 
 268             SOAPAddress soapAddress =
 269                     (SOAPAddress) getExtensionOfType(wsdlPort, SOAPAddress.class);
 270             if (soapAddress == null) {
 271                 if(options.isExtensionMode()){
 272                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_SOAP_ADDRESS(wsdlPort.getName()));
 273                 }else{
 274                     // not a SOAP port, ignore it
 275                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT_NO_ADDRESS(wsdlPort.getName()));
 276                     return false;
 277                 }
 278             }
 279             if(soapAddress != null)
 280                 port.setAddress(soapAddress.getLocation());

 281             Binding binding = wsdlPort.resolveBinding(document);
 282             QName bindingName = getQNameOf(binding);
 283             PortType portType = binding.resolvePortType(document);
 284 
 285             port.setProperty(
 286                     ModelProperties.PROPERTY_WSDL_PORT_NAME,
 287                     getQNameOf(wsdlPort));
 288             port.setProperty(
 289                     ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
 290                     getQNameOf(portType));
 291             port.setProperty(
 292                     ModelProperties.PROPERTY_WSDL_BINDING_NAME,
 293                     bindingName);
 294 
 295             boolean isProvider = isProvider(wsdlPort);
 296             if (_bindingNameToPortMap.containsKey(bindingName) && !isProvider) {
 297                 // this binding has been processed before
 298                 Port existingPort =
 299                         _bindingNameToPortMap.get(bindingName);
 300                 port.setOperations(existingPort.getOperations());


 376                         if (operation
 377                                 .getName()
 378                                 .equals(bindingOperation.getName())) {
 379                             break;
 380                         } else if (!itr.hasNext()) {
 381                             error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(operation.getName(), bindingOperation.getName()));
 382                         }
 383                     }
 384                 }
 385 
 386                 Map headers = new HashMap();
 387                 boolean hasOperations = false;
 388                 for (Iterator iter = binding.operations(); iter.hasNext();) {
 389                     BindingOperation bindingOperation =
 390                             (BindingOperation) iter.next();
 391 
 392                     com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation =
 393                             null;
 394                     Set operations =
 395                             portType.getOperationsNamed(bindingOperation.getName());
 396                     if (operations.size() == 0) {
 397                         // the WSDL document is invalid
 398                         error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_IN_PORT_TYPE(bindingOperation.getName(), binding.getName()));
 399                     } else if (operations.size() == 1) {
 400                         portTypeOperation =
 401                                 (com.sun.tools.internal.ws.wsdl.document.Operation) operations
 402                                         .iterator()
 403                                         .next();
 404                     } else {
 405                         boolean found = false;
 406                         String expectedInputName =
 407                                 bindingOperation.getInput().getName();
 408                         String expectedOutputName =
 409                                 bindingOperation.getOutput().getName();
 410 
 411                         for (Iterator iter2 = operations.iterator(); iter2.hasNext();) {
 412                             com.sun.tools.internal.ws.wsdl.document.Operation candidateOperation =
 413                                     (com.sun.tools.internal.ws.wsdl.document.Operation) iter2
 414                                             .next();
 415 
 416                             if (expectedInputName == null) {


 438                         }
 439                         if (!found) {
 440                             // the WSDL document is invalid
 441                             error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(bindingOperation.getName(), binding.getName()));
 442                         }
 443                     }
 444                     if (!isProvider) {
 445                         this.info =
 446                                 new ProcessSOAPOperationInfo(
 447                                         port,
 448                                         wsdlPort,
 449                                         portTypeOperation,
 450                                         bindingOperation,
 451                                         soapBinding,
 452                                         document,
 453                                         hasOverloadedOperations,
 454                                         headers);
 455 
 456 
 457                         Operation operation;
 458                         if(soapBinding != null)
 459                             operation = processSOAPOperation();
 460                         else{
 461                             operation = processNonSOAPOperation();
 462                         }
 463                         if (operation != null) {
 464                             port.addOperation(operation);
 465                             hasOperations = true;
 466                         }
 467                     }
 468                 }
 469                 if (!isProvider && !hasOperations) {
 470                     // emit a warning if there are no operations, except when its a provider port
 471                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_OPERATIONS_IN_PORT(wsdlPort.getName()));
 472                     return false;
 473                 }
 474                 createJavaInterfaceForPort(port, isProvider);
 475                 PortType pt = binding.resolvePortType(document);
 476                 String jd = (pt.getDocumentation() != null) ? pt.getDocumentation().getContent() : null;
 477                 port.getJavaInterface().setJavaDoc(jd);
 478                 _bindingNameToPortMap.put(bindingName, port);
 479             }
 480 


 583         Binding binding = info.port.resolveBinding(document);
 584         PortType portType = binding.resolvePortType(document);
 585         if (isAsync(portType, info.portTypeOperation)) {
 586             warning(portType, "Can not generate Async methods for non-soap binding!");
 587         }
 588         return info.operation;
 589     }
 590 
 591     /**
 592      * This method is added to fix one of the use case for j2ee se folks, so that we determine
 593      * for non_soap wsdl what could be the style - rpc or document based on parts in the message.
 594      *
 595      * We assume that the message parts could have either all of them with type attribute (RPC)
 596      * or element (DOCUMENT)
 597      *
 598      * Shall this check if parts are mixed and throw error message?
 599      */
 600     private void setNonSoapStyle(Message inputMessage, Message outputMessage) {
 601         SOAPStyle style = SOAPStyle.DOCUMENT;
 602         for(MessagePart part:inputMessage.getParts()){
 603             if(part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
 604                 style = SOAPStyle.RPC;
 605             else
 606                 style = SOAPStyle.DOCUMENT;
 607         }

 608 
 609         //check the outputMessage parts
 610         if(outputMessage != null){
 611             for(MessagePart part:outputMessage.getParts()){
 612                 if(part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
 613                     style = SOAPStyle.RPC;
 614                 else
 615                     style = SOAPStyle.DOCUMENT;
 616             }
 617         }

 618         info.modelPort.setStyle(style);
 619     }
 620 
 621     /* (non-Javadoc)
 622      * @see WSDLModelerBase#processSOAPOperation()
 623      */
 624     protected Operation processSOAPOperation() {
 625         Operation operation =
 626                 new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
 627 
 628         setDocumentationIfPresent(
 629                 operation,
 630                 info.portTypeOperation.getDocumentation());
 631 
 632         if (info.portTypeOperation.getStyle()
 633                 != OperationStyle.REQUEST_RESPONSE
 634                 && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
 635             if (options.isExtensionMode()) {
 636                 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
 637                 return null;


 649                         SOAPOperation.class);
 650 
 651         if (soapOperation != null) {
 652             if (soapOperation.getStyle() != null) {
 653                 soapStyle = soapOperation.getStyle();
 654             }
 655             if (soapOperation.getSOAPAction() != null) {
 656                 operation.setSOAPAction(soapOperation.getSOAPAction());
 657             }
 658         }
 659 
 660         operation.setStyle(soapStyle);
 661 
 662         String uniqueOperationName =
 663                 getUniqueName(info.portTypeOperation, info.hasOverloadedOperations);
 664         if (info.hasOverloadedOperations) {
 665             operation.setUniqueName(uniqueOperationName);
 666         }
 667 
 668         info.operation = operation;
 669         info.uniqueOperationName = uniqueOperationName;
 670 
 671         //attachment
 672         SOAPBody soapRequestBody = getSOAPRequestBody();
 673         if (soapRequestBody == null) {
 674             // the WSDL document is invalid
 675             error(info.bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
 676         }
 677 
 678         if (soapStyle == SOAPStyle.RPC) {
 679             if (soapRequestBody.isEncoded()) {
 680                 if(options.isExtensionMode()){
 681                     warning(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
 682                     processNonSOAPOperation();
 683                 }else{
 684                     error(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
 685                 }
 686             }
 687             return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
 688         }
 689         // document style
 690         return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
 691     }
 692 
 693     protected Operation processLiteralSOAPOperation(StyleAndUse styleAndUse) {
 694         //returns false if the operation name is not acceptable
 695         if (!applyOperationNameCustomization())
 696             return null;

 697 
 698         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
 699         Message inputMessage = getInputMessage();
 700         Request request = new Request(inputMessage, errReceiver);
 701         request.setErrorReceiver(errReceiver);
 702         info.operation.setUse(SOAPUse.LITERAL);
 703         info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
 704         SOAPBody soapRequestBody = getSOAPRequestBody();
 705         if ((StyleAndUse.DOC_LITERAL == styleAndUse) && (soapRequestBody.getNamespace() != null)) {
 706             warning(soapRequestBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
 707         }
 708 
 709 
 710         Response response;
 711 
 712         SOAPBody soapResponseBody = null;
 713         Message outputMessage = null;
 714         if (isRequestResponse) {
 715             soapResponseBody = getSOAPResponseBody();
 716             if (isOperationDocumentLiteral(styleAndUse) && (soapResponseBody.getNamespace() != null)) {
 717                 warning(soapResponseBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
 718             }
 719             outputMessage = getOutputMessage();
 720             response = new Response(outputMessage, errReceiver);
 721         }else{
 722             response = new Response(null, errReceiver);
 723         }
 724 
 725         //ignore operation if there are more than one root part
 726         if (!validateMimeParts(getMimeParts(info.bindingOperation.getInput())) ||
 727                 !validateMimeParts(getMimeParts(info.bindingOperation.getOutput())))
 728             return null;
 729 
 730 
 731         if (!validateBodyParts(info.bindingOperation)) {
 732             // BP 1.1
 733             // R2204   A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s),
 734             // only to wsdl:part element(s) that have been defined using the element attribute.
 735 
 736             // R2203   An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s),
 737             // only to wsdNl:part element(s) that have been defined using the type attribute.
 738             if (isOperationDocumentLiteral(styleAndUse))
 739                 if (options.isExtensionMode())
 740                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_TYPE_MESSAGE_PART(info.portTypeOperation.getName()));
 741                 else
 742                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_DOCLITOPERATION(info.portTypeOperation.getName()));
 743             else if (isOperationRpcLiteral(styleAndUse)) {
 744                 if (options.isExtensionMode())

 745                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_ELEMENT_MESSAGE_PART(info.portTypeOperation.getName()));
 746                 else
 747                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_RPCLITOPERATION(info.portTypeOperation.getName()));
 748             }

 749             return null;
 750         }
 751 
 752         // Process parameterOrder and get the parameterList
 753         List<MessagePart> parameterList = getParameterOrder();
 754 
 755         //binding is invalid in the wsdl, ignore the operation.
 756         if (!setMessagePartsBinding(styleAndUse))
 757             return null;

 758 
 759         List<Parameter> params = null;
 760         boolean unwrappable = isUnwrappable();
 761         info.operation.setWrapped(unwrappable);
 762         if (isOperationDocumentLiteral(styleAndUse)) {
 763             params = getDoclitParameters(request, response, parameterList);
 764         } else if (isOperationRpcLiteral(styleAndUse)) {
 765             String operationName = info.bindingOperation.getName();
 766             Block reqBlock = null;
 767             if (inputMessage != null) {
 768                 QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
 769                 RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
 770                 rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
 771                 reqBlock = new Block(name, rpcStruct, inputMessage);
 772                 request.addBodyBlock(reqBlock);
 773             }
 774 
 775             Block resBlock = null;
 776             if (isRequestResponse && outputMessage != null) {
 777                 QName name = new QName(getResponseNamespaceURI(soapResponseBody), operationName + "Response");


 885         Set duplicateNames = getDuplicateFaultNames();
 886 
 887         // handle soap:fault
 888         handleLiteralSOAPFault(response, duplicateNames);
 889         info.operation.setProperty(
 890                 WSDL_PARAMETER_ORDER,
 891                 definitiveParameterList);
 892 
 893         //set Async property
 894         Binding binding = info.port.resolveBinding(document);
 895         PortType portType = binding.resolvePortType(document);
 896         if (isAsync(portType, info.portTypeOperation)) {
 897             addAsyncOperations(info.operation, styleAndUse);
 898         }
 899 
 900         return info.operation;
 901     }
 902 
 903 
 904     private boolean validateParameterName(List<Parameter> params) {
 905         if (options.isExtensionMode())
 906             return true;

 907 
 908         Message msg = getInputMessage();
 909         for (Parameter param : params) {
 910             if (param.isOUT())
 911                 continue;

 912             if (param.getCustomName() != null) {
 913                 if (Names.isJavaReservedWord(param.getCustomName())) {
 914                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
 915                     return false;
 916                 }
 917                 return true;
 918             }
 919             //process doclit wrapper style
 920             if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
 921                 if (Names.isJavaReservedWord(param.getName())) {
 922                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
 923                     return false;
 924                 }
 925             } else {
 926                 //non-wrapper style and rpclit
 927                 if (Names.isJavaReservedWord(param.getName())) {
 928                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
 929                     return false;
 930                 }
 931             }
 932         }
 933 
 934         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
 935         if (isRequestResponse) {
 936             msg = getOutputMessage();
 937             for (Parameter param : params) {
 938                 if (param.isIN())
 939                     continue;

 940                 if (param.getCustomName() != null) {
 941                     if (Names.isJavaReservedWord(param.getCustomName())) {
 942                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
 943                         return false;
 944                     }
 945                     return true;
 946                 }
 947                 //process doclit wrapper style
 948                 if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
 949                     if (param.isReturn())
 950                         continue;

 951                     if (!param.getName().equals("return") && Names.isJavaReservedWord(param.getName())) {
 952                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
 953                         return false;
 954                     }
 955                 } else {
 956                     if (param.isReturn())
 957                         continue;

 958 
 959                     //non-wrapper style and rpclit
 960                     if (Names.isJavaReservedWord(param.getName())) {
 961                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
 962                         return false;
 963                     }
 964                 }
 965             }
 966         }
 967 
 968         return true;
 969     }
 970 
 971     private boolean enableMimeContent() {
 972         //first we look at binding operation
 973         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.bindingOperation, JAXWSBinding.class);
 974         Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
 975         if (mimeContentMapping != null)
 976             return mimeContentMapping;

 977 
 978         //then in wsdl:binding
 979         Binding binding = info.port.resolveBinding(info.document);
 980         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding, JAXWSBinding.class);
 981         mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
 982         if (mimeContentMapping != null)
 983             return mimeContentMapping;

 984 
 985         //at last look in wsdl:definitions
 986         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.document.getDefinitions(), JAXWSBinding.class);
 987         mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
 988         if (mimeContentMapping != null)
 989             return mimeContentMapping;

 990         return false;
 991     }
 992 
 993     private boolean applyOperationNameCustomization() {
 994         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.portTypeOperation, JAXWSBinding.class);
 995         String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization.getMethodName() != null) ? jaxwsCustomization.getMethodName().getName() : null) : null;
 996         if (operationName != null) {
 997             if (Names.isJavaReservedWord(operationName)) {
 998                 if (options.isExtensionMode())
 999                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
1000                 else
1001                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));

1002                 return false;
1003             }
1004 
1005             info.operation.setCustomizedName(operationName);
1006         }
1007 
1008         if (Names.isJavaReservedWord(info.operation.getJavaMethodName())) {
1009             if (options.isExtensionMode())
1010                 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
1011             else
1012                 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));

1013             return false;
1014         }
1015         return true;
1016     }
1017 
1018     protected String getAsyncOperationName(Operation operation) {
1019         String name = operation.getCustomizedName();
1020         if (name == null)
1021             name = operation.getUniqueName();

1022         return name;
1023     }
1024 
1025     /**
1026      * @param styleAndUse
1027      */
1028     private void addAsyncOperations(Operation syncOperation, StyleAndUse styleAndUse) {
1029         Operation operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.POLLING);
1030         if (operation != null)
1031             info.modelPort.addOperation(operation);

1032 
1033         operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.CALLBACK);
1034         if (operation != null)
1035             info.modelPort.addOperation(operation);
1036     }

1037 
1038     private Operation createAsyncOperation(Operation syncOperation, StyleAndUse styleAndUse, AsyncOperationType asyncType) {
1039         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1040         if (!isRequestResponse)
1041             return null;

1042 
1043         //create async operations
1044         AsyncOperation operation = new AsyncOperation(info.operation, info.bindingOperation);
1045 
1046         //creation the async operation name: operationName+Async or customized name
1047         //operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
1048         if (asyncType.equals(AsyncOperationType.CALLBACK))
1049             operation.setUniqueName(info.operation.getUniqueName() + "_async_callback");
1050         else if (asyncType.equals(AsyncOperationType.POLLING))
1051             operation.setUniqueName(info.operation.getUniqueName() + "_async_polling");

1052 
1053         setDocumentationIfPresent(
1054                 operation,
1055                 info.portTypeOperation.getDocumentation());
1056 
1057         operation.setAsyncType(asyncType);
1058         operation.setSOAPAction(info.operation.getSOAPAction());
1059         boolean unwrappable = info.operation.isWrapped();
1060         operation.setWrapped(unwrappable);
1061         SOAPBody soapRequestBody = getSOAPRequestBody();
1062 
1063         Message inputMessage = getInputMessage();
1064         Request request = new Request(inputMessage, errReceiver);
1065 
1066         SOAPBody soapResponseBody = getSOAPResponseBody();
1067         Message outputMessage = getOutputMessage();
1068         Response response = new Response(outputMessage, errReceiver);
1069 
1070         // Process parameterOrder and get the parameterList
1071         java.util.List<String> parameterList = getAsynParameterOrder();


1132         int numOfOutMsgParts = outputParts.size();
1133 
1134         if (numOfOutMsgParts == 1) {
1135             MessagePart part = outputParts.get(0);
1136             if (isOperationDocumentLiteral(styleAndUse)) {
1137                 JAXBType type = getJAXBType(part);
1138                 operation.setResponseBean(type);
1139             } else if (isOperationRpcLiteral(styleAndUse)) {
1140                 String operationName = info.bindingOperation.getName();
1141                 Block resBlock = info.operation.getResponse().getBodyBlocksMap().get(new QName(getResponseNamespaceURI(soapResponseBody),
1142                         operationName + "Response"));
1143 
1144                 RpcLitStructure resBean = (RpcLitStructure) resBlock.getType();
1145                 List<RpcLitMember> members = resBean.getRpcLitMembers();
1146                 operation.setResponseBean(members.get(0));
1147             }
1148         } else {
1149             //create response bean
1150             String nspace = "";
1151             QName responseBeanName = new QName(nspace, getAsyncOperationName(info.operation) + "Response");
1152             JAXBType responseBeanType = jaxbModelBuilder.getJAXBType(responseBeanName);
1153             if (responseBeanType == null) {
1154                 error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation.getName()));
1155             }
1156             operation.setResponseBean(responseBeanType);
1157         }
1158 
1159         QName respBeanName = new QName(soapResponseBody.getNamespace(), getAsyncOperationName(info.operation) + "Response");
1160         Block block = new Block(respBeanName, operation.getResponseBeanType(), outputMessage);
1161         JavaType respJavaType = operation.getResponseBeanJavaType();
1162         JAXBType respType = new JAXBType(respBeanName, respJavaType);
1163         Parameter respParam = ModelerUtils.createParameter(info.operation.getName() + "Response", respType, block);
1164         respParam.setParameterIndex(-1);
1165         response.addParameter(respParam);
1166         operation.setProperty(WSDL_RESULT_PARAMETER, respParam.getName());
1167 
1168 
1169         List<String> definitiveParameterList = new ArrayList<String>();
1170         int parameterOrderPosition = 0;
1171         for (String name : parameterList) {
1172             Parameter inParameter = ModelerUtils.getParameter(name, inParameters);
1173             if (inParameter == null) {
1174                 if (options.isExtensionMode())
1175                     warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
1176                 else
1177                     error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_ERROR_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));

1178                 return null;
1179             }
1180             request.addParameter(inParameter);
1181             inParameter.setParameterIndex(parameterOrderPosition);
1182             definitiveParameterList.add(name);
1183             parameterOrderPosition++;
1184         }
1185 
1186         operation.setResponse(response);
1187 
1188         //  add callback handlerb Parameter to request
1189         if (operation.getAsyncType().equals(AsyncOperationType.CALLBACK)) {
1190             JavaType cbJavaType = operation.getCallBackType();
1191             JAXBType callbackType = new JAXBType(respBeanName, cbJavaType);
1192             Parameter cbParam = ModelerUtils.createParameter("asyncHandler", callbackType, block);
1193             request.addParameter(cbParam);
1194         }
1195 
1196         operation.setRequest(request);
1197 
1198         return operation;
1199     }
1200 
1201     protected boolean isAsync(com.sun.tools.internal.ws.wsdl.document.PortType portType, com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation) {
1202         //First look into wsdl:operation
1203         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(wsdlOperation, JAXWSBinding.class);
1204         Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1205 
1206         if (isAsync != null)
1207             return isAsync;

1208 
1209         // then into wsdl:portType
1210         QName portTypeName = new QName(portType.getDefining().getTargetNamespaceURI(), portType.getName());
1211         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
1212         isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1213         if (isAsync != null)
1214             return isAsync;

1215 
1216         //then wsdl:definitions
1217         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
1218         isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1219         if (isAsync != null)
1220             return isAsync;

1221         return false;
1222     }
1223 
1224     protected void handleLiteralSOAPHeaders(Request request, Response response, Iterator headerParts, Set duplicateNames, List<String> definitiveParameterList, boolean processRequest) {
1225         QName headerName;
1226         Block headerBlock;
1227         JAXBType jaxbType;
1228         int parameterOrderPosition = definitiveParameterList.size();
1229         while (headerParts.hasNext()) {
1230             MessagePart part = (MessagePart) headerParts.next();
1231             headerName = part.getDescriptor();
1232             jaxbType = getJAXBType(part);
1233             headerBlock = new Block(headerName, jaxbType, part);
1234             TWSDLExtensible ext;
1235             if (processRequest) {
1236                 ext = info.bindingOperation.getInput();
1237             } else {
1238                 ext = info.bindingOperation.getOutput();
1239             }
1240             Message headerMessage = getHeaderMessage(part, ext);
1241 
1242             if (processRequest) {
1243                 request.addHeaderBlock(headerBlock);
1244             } else {
1245                 response.addHeaderBlock(headerBlock);
1246             }
1247 
1248             Parameter parameter = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1249             parameter.setParameterIndex(parameterOrderPosition);
1250             setCustomizedParameterName(info.bindingOperation, headerMessage, part, parameter, false);
1251             if (processRequest && definitiveParameterList != null) {
1252                 request.addParameter(parameter);
1253                 definitiveParameterList.add(parameter.getName());
1254             } else {
1255                 if (definitiveParameterList != null) {
1256                     for (Iterator iterInParams = definitiveParameterList.iterator(); iterInParams.hasNext();) {
1257                         String inParamName =
1258                                 (String) iterInParams.next();
1259                         if (inParamName.equals(parameter.getName())) {
1260                             Parameter inParam = request.getParameterByName(inParamName);
1261                             parameter.setLinkedParameter(inParam);
1262                             inParam.setLinkedParameter(parameter);
1263                             //its in/out parameter, input and output parameter have the same order position.
1264                             parameter.setParameterIndex(inParam.getParameterIndex());
1265                         }
1266                     }
1267                     if (!definitiveParameterList.contains(parameter.getName())) {
1268                         definitiveParameterList.add(parameter.getName());
1269                     }
1270                 }
1271                 response.addParameter(parameter);
1272             }
1273             parameterOrderPosition++;
1274         }
1275 
1276     }
1277 
1278     protected void handleLiteralSOAPFault(Response response, Set duplicateNames) {
1279         for (BindingFault bindingFault : info.bindingOperation.faults()) {
1280             com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
1281             for (com.sun.tools.internal.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
1282                 if (aFault.getName().equals(bindingFault.getName())) {
1283                     if (portTypeFault != null) {
1284                         // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
1285                         error(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(), info.bindingOperation.getName()));
1286                     }
1287                     portTypeFault = aFault;
1288                 }
1289             }
1290 


1294 
1295             }
1296         }
1297         for ( com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault : info.portTypeOperation.faults()) {
1298 
1299             BindingFault bindingFault = null ;
1300             for(BindingFault bFault: info.bindingOperation.faults()) {
1301                 if (bFault.getName().equals(portTypeFault.getName())) {
1302                     bindingFault = bFault;
1303                 }
1304             }
1305 
1306             if(bindingFault == null) {
1307                 warning(portTypeFault,ModelerMessages.WSDLMODELER_INVALID_PORT_TYPE_FAULT_NOT_FOUND(portTypeFault.getName(),info.portTypeOperation.getName()));
1308             }
1309             // wsdl:fault message name is used to create the java exception name later on
1310             String faultName = getFaultClassName(portTypeFault);
1311             Fault fault = new Fault(faultName, portTypeFault);
1312             fault.setWsdlFaultName(portTypeFault.getName());
1313             setDocumentationIfPresent(fault, portTypeFault.getDocumentation());
1314             String faultNamespaceURI = null;
1315             if (bindingFault != null) {
1316                 //get the soapbind:fault from wsdl:fault in the binding
1317                 SOAPFault soapFault = (SOAPFault) getExtensionOfType(bindingFault, SOAPFault.class);
1318 
1319                 // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
1320                 if (soapFault == null) {
1321                     if (options.isExtensionMode()) {
1322                         warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1323                         soapFault = new SOAPFault(new LocatorImpl());
1324                     } else {
1325                         error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1326                     }
1327                 }
1328 
1329                 //the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
1330                 if (!soapFault.isLiteral()) {
1331                     if (options.isExtensionMode())
1332                         warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
1333                     else
1334                         error(soapFault, ModelerMessages.WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));

1335                     continue;
1336                 }
1337 
1338                 // the soapFault name must be present
1339                 if (soapFault.getName() == null) {
1340                     warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(bindingFault.getName(), info.bindingOperation.getName()));
1341                 } else if (!soapFault.getName().equals(bindingFault.getName())) {
1342                     warning(soapFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(soapFault.getName(), bindingFault.getName(), info.bindingOperation.getName()));
1343                 } else if (soapFault.getNamespace() != null) {
1344                     warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
1345                 }
1346 
1347                 faultNamespaceURI = soapFault.getNamespace();
1348             }
1349             if (faultNamespaceURI == null) {
1350                 faultNamespaceURI = portTypeFault.getMessage().getNamespaceURI();
1351             }
1352 
1353             com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault.resolveMessage(info.document);
1354             Iterator iter2 = faultMessage.parts();
1355             if (!iter2.hasNext()) {
1356                 // the WSDL document is invalid
1357                 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(portTypeFault.getName(), faultMessage.getName()));
1358             }
1359             MessagePart faultPart = (MessagePart) iter2.next();
1360             QName faultQName = faultPart.getDescriptor();
1361 
1362             // Don't include fault messages with non-unique soap:fault names
1363             if (duplicateNames.contains(faultQName)) {
1364                 warning(faultPart, ModelerMessages.WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(portTypeFault.getName(), info.portTypeOperation.getName(), faultPart.getName()));
1365                 continue;
1366             }
1367 
1368             if (iter2.hasNext()) {
1369                 // the WSDL document is invalid
1370                 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(portTypeFault.getName(), faultMessage.getName()));
1371             }
1372 
1373             if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {



1374                 error(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
1375             }

1376 
1377             JAXBType jaxbType = getJAXBType(faultPart);
1378 
1379             fault.setElementName(faultPart.getDescriptor());
1380             fault.setJavaMemberName(Names.getExceptionClassMemberName());
1381 
1382             Block faultBlock = new Block(faultQName, jaxbType, faultPart);
1383             fault.setBlock(faultBlock);
1384             //createParentFault(fault);
1385             //createSubfaults(fault);
1386             if (!response.getFaultBlocksMap().containsKey(faultBlock.getName()))
1387                 response.addFaultBlock(faultBlock);

1388             info.operation.addFault(fault);
1389         }
1390     }
1391 
1392     private String getFaultClassName(com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault) {
1393         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeFault, JAXWSBinding.class);
1394         if (jaxwsBinding != null) {
1395             CustomName className = jaxwsBinding.getClassName();
1396             if (className != null) {
1397                 return makePackageQualified(className.getName());
1398             }
1399         }
1400         return makePackageQualified(BindingHelper.mangleNameToClassName(portTypeFault.getMessage().getLocalPart()));
1401     }
1402 
1403     protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
1404         SOAPBody inBody = getSOAPRequestBody();
1405         Message inMessage = getInputMessage();
1406         if (!setMessagePartsBinding(inBody, inMessage, styleAndUse, true))
1407             return false;

1408 
1409         if (isRequestResponse()) {
1410             SOAPBody outBody = getSOAPResponseBody();
1411             Message outMessage = getOutputMessage();
1412             if (!setMessagePartsBinding(outBody, outMessage, styleAndUse, false))
1413                 return false;
1414         }

1415         return true;
1416     }
1417 
1418     //returns false if the wsdl is invalid and operation should be ignored
1419     protected boolean setMessagePartsBinding(SOAPBody body, Message message, StyleAndUse styleAndUse, boolean isInput) {
1420         List<MessagePart> parts = new ArrayList<MessagePart>();
1421 
1422         //get Mime parts
1423         List<MessagePart> mimeParts;
1424         List<MessagePart> headerParts;
1425         List<MessagePart> bodyParts = getBodyParts(body, message);
1426 
1427         if (isInput) {
1428             headerParts = getHeaderPartsFromMessage(message, isInput);
1429             mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
1430         } else {
1431             headerParts = getHeaderPartsFromMessage(message, isInput);
1432             mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
1433         }
1434 
1435         //As of now WSDL MIME binding is not supported, so throw the exception when such binding is encounterd
1436 //        if(mimeParts.size() > 0){
1437 //            fail("wsdlmodeler.unsupportedBinding.mime", new Object[]{});
1438 //        }
1439 
1440         //if soap:body parts attribute not there, then all unbounded message parts will
1441         // belong to the soap body
1442         if (bodyParts == null) {
1443             bodyParts = new ArrayList<MessagePart>();
1444             for (Iterator<MessagePart> iter = message.parts(); iter.hasNext();) {
1445                 MessagePart mPart = iter.next();
1446                 //Its a safe assumption that the parts in the message not belonging to header or mime will
1447                 // belong to the body?
1448                 if (mimeParts.contains(mPart) || headerParts.contains(mPart) || boundToFault(mPart.getName())) {
1449                     //throw error that a part cant be bound multiple times, not ignoring operation, if there
1450                     //is conflict it will fail latter
1451                     if (options.isExtensionMode())
1452                         warning(mPart, ModelerMessages.WSDLMODELER_WARNING_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1453                     else
1454                         error(mPart, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1455                 }

1456                 bodyParts.add(mPart);
1457             }
1458         }
1459 
1460         //now build the final parts list with header, mime parts and body parts
1461         for (Iterator iter = message.parts(); iter.hasNext();) {
1462             MessagePart mPart = (MessagePart) iter.next();
1463             if (mimeParts.contains(mPart)) {
1464                 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
1465                 parts.add(mPart);
1466             } else if (headerParts.contains(mPart)) {
1467                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1468                 parts.add(mPart);
1469             } else if (bodyParts.contains(mPart)) {
1470                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1471                 parts.add(mPart);
1472             } else {
1473                 mPart.setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
1474             }
1475         }
1476 
1477         if (isOperationDocumentLiteral(styleAndUse) && bodyParts.size() > 1) {
1478             if (options.isExtensionMode())
1479                 warning(message, ModelerMessages.WSDLMODELER_WARNING_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
1480             else
1481                 error(message, ModelerMessages.WSDLMODELER_INVALID_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));

1482             return false;
1483         }
1484         return true;
1485     }
1486 
1487     private boolean boundToFault(String partName) {
1488         for (BindingFault bindingFault : info.bindingOperation.faults()) {
1489             if (partName.equals(bindingFault.getName()))
1490                 return true;
1491         }

1492         return false;
1493     }
1494 
1495     //get MessagePart(s) referenced by parts attribute of soap:body element
1496     private List<MessagePart> getBodyParts(SOAPBody body, Message message) {
1497         String bodyParts = body.getParts();
1498         if (bodyParts != null) {
1499             List<MessagePart> partsList = new ArrayList<MessagePart>();
1500             StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
1501             while (in.hasMoreTokens()) {
1502                 String part = in.nextToken();
1503                 MessagePart mPart = message.getPart(part);
1504                 if (null == mPart) {
1505                     error(message, ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(part, message.getName()));
1506                 }
1507                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1508                 partsList.add(mPart);
1509             }
1510             return partsList;
1511         }
1512         return null;
1513     }
1514 
1515     List<MessagePart> getAdditionHeaderParts(BindingOperation bindingOperation,Message message, boolean isInput){
1516         List<MessagePart> headerParts = new ArrayList<MessagePart>();
1517         List<MessagePart> parts = message.getParts();
1518         List<MessagePart> headers = getHeaderParts(bindingOperation, isInput);
1519 
1520         for(MessagePart part: headers){
1521             if(parts.contains(part))
1522                 continue;

1523             headerParts.add(part);
1524         }
1525         return headerParts;
1526     }
1527 
1528     private List<MessagePart> getHeaderPartsFromMessage(Message message, boolean isInput) {
1529         List<MessagePart> headerParts = new ArrayList<MessagePart>();
1530         Iterator<MessagePart> parts = message.parts();
1531         List<MessagePart> headers = getHeaderParts(info.bindingOperation, isInput);
1532         while (parts.hasNext()) {
1533             MessagePart part = parts.next();
1534             if (headers.contains(part)) {
1535                 headerParts.add(part);
1536             }
1537         }
1538         return headerParts;
1539     }
1540 
1541     private Message getHeaderMessage(MessagePart part, TWSDLExtensible ext) {
1542         Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1543         while (headers.hasNext()) {
1544             SOAPHeader header = headers.next();
1545             if (!header.isLiteral())
1546                 continue;

1547             com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(), document);
1548             if (headerMessage == null)
1549                 continue;

1550 
1551             MessagePart headerPart = headerMessage.getPart(header.getPart());
1552             if (headerPart == part)
1553                 return headerMessage;
1554         }

1555         return null;
1556     }
1557 
1558     private List<MessagePart> getHeaderParts(BindingOperation bindingOperation, boolean isInput) {
1559         TWSDLExtensible ext;
1560         if (isInput) {
1561             ext = bindingOperation.getInput();
1562         } else {
1563             ext = bindingOperation.getOutput();
1564         }
1565 
1566         List<MessagePart> parts = new ArrayList<MessagePart>();
1567         Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1568         while (headers.hasNext()) {
1569             SOAPHeader header = headers.next();
1570             if (!header.isLiteral()) {
1571                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_LITERAL(header.getPart(), bindingOperation.getName()));
1572             }
1573 
1574             if (header.getNamespace() != null) {
1575                 warning(header, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:header", bindingOperation.getName()));
1576             }
1577             com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(),document);
1578             if (headerMessage == null) {
1579                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_CANT_RESOLVE_MESSAGE(header.getMessage(), bindingOperation.getName()));
1580             }
1581 
1582             MessagePart part = headerMessage.getPart(header.getPart());
1583             if (part == null) {
1584                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_FOUND(header.getPart(), bindingOperation.getName()));
1585             }
1586             if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {



1587                 error(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
1588             }

1589             part.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1590             parts.add(part);
1591         }
1592         return parts;
1593     }
1594 
1595     private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
1596         return StyleAndUse.DOC_LITERAL == styleAndUse;
1597     }
1598 
1599     private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
1600         return StyleAndUse.RPC_LITERAL == styleAndUse;
1601     }
1602 
1603     /**
1604      * @param part
1605      * @return Returns a JAXBType object
1606      */
1607     private JAXBType getJAXBType(MessagePart part) {
1608         JAXBType type;
1609         QName name = part.getDescriptor();
1610         if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
1611             type = jaxbModelBuilder.getJAXBType(name);
1612             if(type == null){
1613                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1614             }
1615         } else {
1616             S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
1617             TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
1618             if (typeAnno == null) {
1619                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1620             }
1621             JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno));
1622             type = new JAXBType(new QName("", part.getName()), javaType);
1623         }
1624         return type;
1625     }
1626 
1627     private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
1628         if (parameterList.size() == 0)
1629             return new ArrayList<Parameter>();

1630         List<Parameter> params = new ArrayList<Parameter>();
1631         Message inMsg = getInputMessage();
1632         Message outMsg = getOutputMessage();
1633         boolean unwrappable = isUnwrappable();
1634         List<Parameter> outParams = null;
1635         int pIndex = 0;
1636         for (MessagePart part : parameterList) {
1637             QName reqBodyName = part.getDescriptor();
1638             JAXBType jaxbType = getJAXBType(part);
1639             Block block = new Block(reqBodyName, jaxbType, part);
1640             if (unwrappable) {
1641                 //So build body and header blocks and set to request and response
1642                 JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
1643                 block = new Block(reqBodyName, jaxbStructType, part);
1644                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1645                     if (part.isIN()) {
1646                         req.addBodyBlock(block);
1647                     } else if (part.isOUT()) {
1648                         res.addBodyBlock(block);
1649                     } else if (part.isINOUT()) {
1650                         req.addBodyBlock(block);
1651                         res.addBodyBlock(block);
1652                     }
1653                 } else if (ModelerUtils.isUnbound(part)) {
1654                     if (part.isIN())
1655                         req.addUnboundBlock(block);
1656                     else if (part.isOUT())
1657                         res.addUnboundBlock(block);
1658                     else if (part.isINOUT()) {
1659                         req.addUnboundBlock(block);
1660                         res.addUnboundBlock(block);
1661                     }
1662 
1663                 }
1664                 if (part.isIN() || part.isINOUT()) {
1665                     params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1666                     int index = 0;
1667                     Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
1668                     for (Parameter param : params) {
1669                         param.setParameterIndex(index++);
1670                         param.setMode(mode);
1671                         setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
1672                     }
1673                 } else if (part.isOUT()) {
1674                     outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1675                     for (Parameter param : outParams) {
1676                         param.setMode(Mode.OUT);
1677                         setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
1678                     }
1679                 }
1680             } else {
1681                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1682                     if (part.isIN()) {


1739                         }
1740                     }
1741                 } else if (ModelerUtils.isUnbound(part)) {
1742                     if (part.isIN()) {
1743                         req.addUnboundBlock(block);
1744                     } else if (part.isOUT()) {
1745                         res.addUnboundBlock(block);
1746                     } else if (part.isINOUT()) {
1747                         req.addUnboundBlock(block);
1748                         res.addUnboundBlock(block);
1749                     }
1750                 }
1751                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
1752                 param.setMode(part.getMode());
1753                 if (part.isReturn()) {
1754                     param.setParameterIndex(-1);
1755                 } else {
1756                     param.setParameterIndex(pIndex++);
1757                 }
1758 
1759                 if (part.isIN())
1760                     setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, false);
1761                 else if (outMsg != null)
1762                     setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, false);

1763 
1764                 params.add(param);
1765             }
1766         }
1767         if (unwrappable && (outParams != null)) {
1768             int index = params.size();
1769             for (Parameter param : outParams) {
1770                 if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
1771                     param.setParameterIndex(-1);
1772                 } else {
1773                     Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
1774                     if ((inParam != null) && inParam.isIN()) {
1775                         QName inElementName = inParam.getType().getName();
1776                         QName outElementName = param.getType().getName();
1777                         String inJavaType = inParam.getTypeName();
1778                         String outJavaType = param.getTypeName();
1779                         TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
1780                         TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
1781                         QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
1782                         QName outRawTypeName = ModelerUtils.getRawTypeName(param);


1790                     }
1791                     if (outParams.size() == 1) {
1792                         param.setParameterIndex(-1);
1793                     } else {
1794                         param.setParameterIndex(index++);
1795                     }
1796                 }
1797                 params.add(param);
1798             }
1799         }
1800         return params;
1801     }
1802 
1803     private List<Parameter> getRpcLitParameters(Request req, Response res, Block reqBlock, Block resBlock, List<MessagePart> paramList) {
1804         List<Parameter> params = new ArrayList<Parameter>();
1805         Message inMsg = getInputMessage();
1806         Message outMsg = getOutputMessage();
1807         S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType()).getJaxbModel().getS2JJAXBModel();
1808         List<Parameter> inParams = ModelerUtils.createRpcLitParameters(inMsg, reqBlock, jaxbModel, errReceiver);
1809         List<Parameter> outParams = null;
1810         if (outMsg != null)
1811             outParams = ModelerUtils.createRpcLitParameters(outMsg, resBlock, jaxbModel, errReceiver);

1812 
1813         //create parameters for header and mime parts
1814         int index = 0;
1815         for (MessagePart part : paramList) {
1816             Parameter param = null;
1817             if (ModelerUtils.isBoundToSOAPBody(part)) {
1818                 if (part.isIN()) {
1819                     param = ModelerUtils.getParameter(part.getName(), inParams);
1820                 } else if (outParams != null) {
1821                     param = ModelerUtils.getParameter(part.getName(), outParams);
1822                 }
1823             } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1824                 QName headerName = part.getDescriptor();
1825                 JAXBType jaxbType = getJAXBType(part);
1826                 Block headerBlock = new Block(headerName, jaxbType, part);
1827                 param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1828                 if (part.isIN()) {
1829                     req.addHeaderBlock(headerBlock);
1830                 } else if (part.isOUT()) {
1831                     res.addHeaderBlock(headerBlock);
1832                 } else if (part.isINOUT()) {
1833                     req.addHeaderBlock(headerBlock);
1834                     res.addHeaderBlock(headerBlock);
1835                 }
1836             } else if (ModelerUtils.isBoundToMimeContent(part)) {
1837                 List<MIMEContent> mimeContents;
1838                 if (part.isIN() || part.isINOUT())
1839                     mimeContents = getMimeContents(info.bindingOperation.getInput(),
1840                             getInputMessage(), part.getName());
1841                 else
1842                     mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1843                             getOutputMessage(), part.getName());

1844 
1845                 JAXBType type = getAttachmentType(mimeContents, part);
1846                 //create Parameters in request or response
1847                 //Block mimeBlock = new Block(new QName(part.getName()), type);
1848                 Block mimeBlock = new Block(type.getName(), type, part);
1849                 param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
1850                 if (part.isIN()) {
1851                     req.addAttachmentBlock(mimeBlock);
1852                 } else if (part.isOUT()) {
1853                     res.addAttachmentBlock(mimeBlock);
1854                 } else if (part.isINOUT()) {
1855                     mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1856                             getOutputMessage(), part.getName());
1857                     JAXBType outJaxbType = getAttachmentType(mimeContents, part);
1858 
1859                     String inType = type.getJavaType().getType().getName();
1860                     String outType = outJaxbType.getJavaType().getType().getName();
1861                     if (!inType.equals(outType)) {
1862                         String javaType = "javax.activation.DataHandler";
1863                         JType jt = options.getCodeModel().ref(javaType);


1875                     req.addUnboundBlock(unboundBlock);
1876                 } else if (part.isOUT()) {
1877                     res.addUnboundBlock(unboundBlock);
1878                 } else if (part.isINOUT()) {
1879                     req.addUnboundBlock(unboundBlock);
1880                     res.addUnboundBlock(unboundBlock);
1881                 }
1882                 param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
1883             }
1884             if (param != null) {
1885                 if (part.isReturn()) {
1886                     param.setParameterIndex(-1);
1887                 } else {
1888                     param.setParameterIndex(index++);
1889                 }
1890                 param.setMode(part.getMode());
1891                 params.add(param);
1892             }
1893         }
1894         for (Parameter param : params) {
1895             if (param.isIN())
1896                 setCustomizedParameterName(info.portTypeOperation, inMsg, inMsg.getPart(param.getName()), param, false);
1897             else if (outMsg != null)
1898                 setCustomizedParameterName(info.portTypeOperation, outMsg, outMsg.getPart(param.getName()), param, false);
1899         }

1900         return params;
1901     }
1902 
1903     private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
1904         Message inputMessage = getInputMessage();
1905         //there is no input message, return zero parameters
1906         if (inputMessage != null && !inputMessage.parts().hasNext())
1907             return new ArrayList<Parameter>();

1908 
1909         List<Parameter> inParameters = null;
1910         QName reqBodyName;
1911         Block reqBlock;
1912         JAXBType jaxbReqType;
1913         boolean unwrappable = isUnwrappable();
1914         boolean doneSOAPBody = false;
1915         //setup request parameters
1916         for (String inParamName : parameterList) {
1917             MessagePart part = inputMessage.getPart(inParamName);
1918             if (part == null)
1919                 continue;

1920             reqBodyName = part.getDescriptor();
1921             jaxbReqType = getJAXBType(part);
1922             if (unwrappable) {
1923                 //So build body and header blocks and set to request and response
1924                 JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
1925                 reqBlock = new Block(reqBodyName, jaxbRequestType, part);
1926                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1927                     request.addBodyBlock(reqBlock);
1928                 } else if (ModelerUtils.isUnbound(part)) {
1929                     request.addUnboundBlock(reqBlock);
1930                 }
1931                 inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
1932                 for (Parameter param : inParameters) {
1933                     setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
1934                 }
1935             } else {
1936                 reqBlock = new Block(reqBodyName, jaxbReqType, part);
1937                 if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
1938                     doneSOAPBody = true;
1939                     request.addBodyBlock(reqBlock);
1940                 } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1941                     request.addHeaderBlock(reqBlock);
1942                 } else if (ModelerUtils.isBoundToMimeContent(part)) {
1943                     List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
1944                             getInputMessage(), part.getName());
1945                     jaxbReqType = getAttachmentType(mimeContents, part);
1946                     //reqBlock = new Block(new QName(part.getName()), jaxbReqType);
1947                     reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
1948                     request.addAttachmentBlock(reqBlock);
1949                 } else if (ModelerUtils.isUnbound(part)) {
1950                     request.addUnboundBlock(reqBlock);
1951                 }
1952                 if (inParameters == null)
1953                     inParameters = new ArrayList<Parameter>();

1954                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
1955                 setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
1956                 inParameters.add(param);
1957             }
1958         }
1959         return inParameters;
1960     }
1961 
1962     /**
1963      * @param part
1964      * @param param
1965      * @param wrapperStyle TODO
1966      */
1967     private void setCustomizedParameterName(TWSDLExtensible extension, Message msg, MessagePart part, Parameter param, boolean wrapperStyle) {
1968         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(extension, JAXWSBinding.class);
1969         if (jaxwsBinding == null)
1970             return;

1971         String paramName = part.getName();
1972         QName elementName = part.getDescriptor();
1973         if (wrapperStyle)
1974             elementName = param.getType().getName();

1975         String customName = jaxwsBinding.getParameterName(msg.getName(), paramName, elementName, wrapperStyle);
1976         if (customName != null && !customName.equals("")) {
1977             param.setCustomName(customName);
1978         }
1979     }
1980 

1981     protected boolean isConflictingPortClassName(String name) {
1982         return false;
1983     }
1984 
1985     protected boolean isUnwrappable() {
1986         if (!getWrapperStyleCustomization())
1987             return false;

1988 
1989         com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
1990         com.sun.tools.internal.ws.wsdl.document.Message outputMessage = getOutputMessage();
1991 
1992         // Wrapper style if the operation's input and output messages each contain
1993         // only a single part
1994         if ((inputMessage != null && inputMessage.numParts() != 1)
1995                 || (outputMessage != null && outputMessage.numParts() != 1)) {
1996             return false;
1997         }
1998 
1999         MessagePart inputPart = inputMessage != null
2000                 ? inputMessage.parts().next() : null;
2001         MessagePart outputPart = outputMessage != null
2002                 ? outputMessage.parts().next() : null;
2003         String operationName = info.portTypeOperation.getName();
2004 
2005         // Wrapper style if the input message part refers to a global element declaration whose localname
2006         // is equal to the operation name
2007         // Wrapper style if the output message part refers to a global element declaration
2008         if ((inputPart != null && !inputPart.getDescriptor().getLocalPart().equals(operationName)) ||
2009                 (outputPart != null && outputPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
2010             return false;

2011 
2012         //check to see if either input or output message part not bound to soapbing:body
2013         //in that case the operation is not wrapper style
2014         if (((inputPart != null) && (inputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)) ||
2015                 ((outputPart != null) && (outputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)))
2016             return false;

2017 
2018         // Wrapper style if the elements referred to by the input and output message parts
2019         // (henceforth referred to as wrapper elements) are both complex types defined
2020         // using the xsd:sequence compositor
2021         // Wrapper style if the wrapper elements only contain child elements, they must not
2022         // contain other structures such as xsd:choice, substitution groups1 or attributes
2023         //These checkins are done by jaxb, we just check if jaxb has wrapper children. If there
2024         // are then its wrapper style
2025         //if(inputPart != null && outputPart != null){
2026         if (inputPart != null) {
2027             boolean inputWrappable = false;
2028             JAXBType inputType = getJAXBType(inputPart);
2029             if (inputType != null) {
2030                 inputWrappable = inputType.isUnwrappable();
2031             }
2032             //if there are no output part (oneway), the operation can still be wrapper style
2033             if (outputPart == null) {
2034                 return inputWrappable;
2035             }
2036             JAXBType outputType = getJAXBType(outputPart);
2037             if ((inputType != null) && (outputType != null))
2038                 return inputType.isUnwrappable() && outputType.isUnwrappable();
2039         }

2040 
2041         return false;
2042     }
2043 
2044     private boolean getWrapperStyleCustomization() {
2045         //first we look into wsdl:portType/wsdl:operation
2046         com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
2047         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeOperation, JAXWSBinding.class);
2048         if (jaxwsBinding != null) {
2049             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2050             if (isWrappable != null)
2051                 return isWrappable;
2052         }

2053 
2054         //then into wsdl:portType
2055         PortType portType = info.port.resolveBinding(document).resolvePortType(document);
2056         jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2057         if (jaxwsBinding != null) {
2058             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2059             if (isWrappable != null)
2060                 return isWrappable;
2061         }

2062 
2063         //then wsdl:definitions
2064         jaxwsBinding = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2065         if (jaxwsBinding != null) {
2066             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2067             if (isWrappable != null)
2068                 return isWrappable;
2069         }

2070         return true;
2071     }
2072 
2073     /* (non-Javadoc)
2074      * @see WSDLModelerBase#isSingleInOutPart(Set, MessagePart)
2075      */
2076     protected boolean isSingleInOutPart(Set inputParameterNames,
2077                                         MessagePart outputPart) {
2078         // As of now, we dont have support for in/out in doc-lit. So return false.
2079         SOAPOperation soapOperation =
2080                 (SOAPOperation) getExtensionOfType(info.bindingOperation,
2081                         SOAPOperation.class);
2082         if ((soapOperation != null) && (soapOperation.isDocument() || info.soapBinding.isDocument())) {
2083             Iterator iter = getInputMessage().parts();
2084             while (iter.hasNext()) {
2085                 MessagePart part = (MessagePart) iter.next();
2086                 if (outputPart.getName().equals(part.getName()) && outputPart.getDescriptor().equals(part.getDescriptor()))
2087                     return true;
2088             }

2089         } else if (soapOperation != null && soapOperation.isRPC() || info.soapBinding.isRPC()) {
2090             com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2091             if (inputParameterNames.contains(outputPart.getName())) {
2092                 if (inputMessage.getPart(outputPart.getName()).getDescriptor().equals(outputPart.getDescriptor())) {
2093                     return true;
2094                 }
2095             }
2096         }
2097         return false;
2098     }
2099 
2100     private List<Parameter> createRpcLitRequestParameters(Request request, List<String> parameterList, Block block) {
2101         Message message = getInputMessage();
2102         S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType()).getJaxbModel().getS2JJAXBModel();
2103         List<Parameter> parameters = ModelerUtils.createRpcLitParameters(message, block, jaxbModel, errReceiver);
2104 
2105         //create parameters for header and mime parts
2106         for (String paramName : parameterList) {
2107             MessagePart part = message.getPart(paramName);
2108             if (part == null)
2109                 continue;

2110             if (ModelerUtils.isBoundToSOAPHeader(part)) {
2111                 if (parameters == null)
2112                     parameters = new ArrayList<Parameter>();

2113                 QName headerName = part.getDescriptor();
2114                 JAXBType jaxbType = getJAXBType(part);
2115                 Block headerBlock = new Block(headerName, jaxbType, part);
2116                 request.addHeaderBlock(headerBlock);
2117                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
2118                 if (param != null) {
2119                     parameters.add(param);
2120                 }
2121             } else if (ModelerUtils.isBoundToMimeContent(part)) {
2122                 if (parameters == null)
2123                     parameters = new ArrayList<Parameter>();

2124                 List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
2125                         getInputMessage(), paramName);
2126 
2127                 JAXBType type = getAttachmentType(mimeContents, part);
2128                 //create Parameters in request or response
2129                 //Block mimeBlock = new Block(new QName(part.getName()), type);
2130                 Block mimeBlock = new Block(type.getName(), type, part);
2131                 request.addAttachmentBlock(mimeBlock);
2132                 Parameter param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
2133                 if (param != null) {
2134                     parameters.add(param);
2135                 }
2136             } else if (ModelerUtils.isUnbound(part)) {
2137                 if (parameters == null)
2138                     parameters = new ArrayList<Parameter>();

2139                 QName name = part.getDescriptor();
2140                 JAXBType type = getJAXBType(part);
2141                 Block unboundBlock = new Block(name, type, part);
2142                 request.addUnboundBlock(unboundBlock);
2143                 Parameter param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
2144                 if (param != null) {
2145                     parameters.add(param);
2146                 }
2147             }
2148         }
2149         for (Parameter param : parameters) {
2150             setCustomizedParameterName(info.portTypeOperation, message, message.getPart(param.getName()), param, false);
2151         }
2152         return parameters;
2153     }
2154 
2155     private String getJavaTypeForMimeType(String mimeType) {
2156         if (mimeType.equals("image/jpeg") || mimeType.equals("image/gif")) {
2157             return "java.awt.Image";
2158         } else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) {


2169         List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
2170         if (mimeTypes.size() > 1) {
2171             javaType = "javax.activation.DataHandler";
2172         } else {
2173             javaType = getJavaTypeForMimeType(mimeTypes.get(0));
2174         }
2175 
2176         S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
2177         JType jt = options.getCodeModel().ref(javaType);
2178         QName desc = part.getDescriptor();
2179         TypeAndAnnotation typeAnno = null;
2180 
2181         if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
2182             typeAnno = jaxbModel.getJavaType(desc);
2183             desc = new QName("", part.getName());
2184         } else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
2185             typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
2186             if(typeAnno == null){
2187                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part.getDescriptor(), part.getName()));
2188             }
2189             for (Iterator mimeTypeIter = mimeTypes.iterator(); mimeTypeIter.hasNext();) {
2190                 String mimeType = (String) mimeTypeIter.next();
2191                 if ((!mimeType.equals("text/xml") &&
2192                         !mimeType.equals("application/xml"))) {
2193                     //According to AP 1.0,
2194                     //RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
2195                     //global element declaration (via the element attribute of the wsdl:part
2196                     //element) then the value of the type attribute of a mime:content element
2197                     //that binds that part MUST be a content type suitable for carrying an
2198                     //XML serialization.
2199                     //should we throw warning?
2200                     //type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
2201                     warning(part, ModelerMessages.MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(part.getName(), mimeType));
2202                 }
2203             }
2204         }
2205         if (typeAnno == null) {
2206             error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part.getName()));
2207         }
2208         return new JAXBType(desc, new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno, jt)),
2209                 null, getJAXBModelBuilder().getJAXBModel());
2210     }
2211 
2212     protected void buildJAXBModel(WSDLDocument wsdlDocument) {
2213         JAXBModelBuilder jaxbModelBuilder = new JAXBModelBuilder(options, classNameCollector, forest, errReceiver);
2214         //set the java package where wsdl artifacts will be generated
2215         //if user provided package name  using -p switch (or package property on wsimport ant task)
2216         //ignore the package customization in the wsdl and schema bidnings
2217         //formce the -p option only in the first pass
2218         if (explicitDefaultPackage != null) {
2219             jaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(options.defaultPackage);
2220         } else {
2221             options.defaultPackage = getJavaPackage();
2222         }
2223 
2224         //create pseudo schema for async operations(if any) response bean
2225         List<InputSource> schemas = PseudoSchemaBuilder.build(this, options, errReceiver);
2226         for (InputSource schema : schemas) {
2227             jaxbModelBuilder.getJAXBSchemaCompiler().parseSchema(schema);
2228         }
2229         jaxbModelBuilder.bind();
2230         this.jaxbModelBuilder = jaxbModelBuilder;
2231     }
2232 
2233     protected String getJavaPackage() {
2234         String jaxwsPackage = null;
2235         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2236         if (jaxwsCustomization != null && jaxwsCustomization.getJaxwsPackage() != null) {
2237             jaxwsPackage = jaxwsCustomization.getJaxwsPackage().getName();
2238         }
2239         if (jaxwsPackage != null) {
2240             return jaxwsPackage;
2241         }
2242         String wsdlUri = document.getDefinitions().getTargetNamespaceURI();
2243         return XJC.getDefaultPackageName(wsdlUri);
2244 
2245     }
2246 
2247     protected void createJavaInterfaceForProviderPort(Port port) {
2248         String interfaceName = "javax.xml.ws.Provider";
2249         JavaInterface intf = new JavaInterface(interfaceName);
2250         port.setJavaInterface(intf);


2253     protected void createJavaInterfaceForPort(Port port, boolean isProvider) {
2254         if (isProvider) {
2255             createJavaInterfaceForProviderPort(port);
2256             return;
2257         }
2258         String interfaceName = getJavaNameOfSEI(port);
2259 
2260         if (isConflictingPortClassName(interfaceName)) {
2261             interfaceName += "_PortType";
2262         }
2263 
2264         JavaInterface intf = new JavaInterface(interfaceName);
2265         for (Operation operation : port.getOperations()) {
2266             createJavaMethodForOperation(
2267                     port,
2268                     operation,
2269                     intf);
2270 
2271             for (JavaParameter jParam : operation.getJavaMethod().getParametersList()) {
2272                 Parameter param = jParam.getParameter();
2273                 if (param.getCustomName() != null)
2274                     jParam.setName(param.getCustomName());
2275             }
2276         }

2277 
2278         port.setJavaInterface(intf);
2279     }
2280 
2281     protected String getServiceInterfaceName(QName serviceQName, com.sun.tools.internal.ws.wsdl.document.Service wsdlService) {
2282         String serviceName = wsdlService.getName();
2283         JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(wsdlService, JAXWSBinding.class);
2284         if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2285             CustomName name = jaxwsCust.getClassName();
2286             if (name != null && !name.getName().equals(""))
2287                 return makePackageQualified(name.getName());
2288         }

2289         return makePackageQualified(BindingHelper.mangleNameToClassName(serviceName));
2290     }
2291 
2292     protected String getJavaNameOfSEI(Port port) {
2293         QName portTypeName =
2294                 (QName) port.getProperty(
2295                         ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
2296         PortType pt = (PortType) document.find(Kinds.PORT_TYPE, portTypeName);
2297         //populate the portType map here. We should get rid of all these properties
2298         // lets not do it as it may break NB
2299         //TODO: clean all these stuff part of NB RFE
2300         port.portTypes.put(portTypeName, pt);
2301         JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt, JAXWSBinding.class);
2302         if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2303             CustomName name = jaxwsCust.getClassName();
2304             if (name != null && !name.getName().equals("")) {
2305                 return makePackageQualified(name.getName());
2306             }
2307         }
2308 
2309         String interfaceName;
2310         if (portTypeName != null) {
2311             // got portType information from WSDL, use it to name the interface
2312             interfaceName =
2313                     makePackageQualified(BindingHelper.mangleNameToClassName(portTypeName.getLocalPart()));
2314         } else {
2315             // somehow we only got the port name, so we use that
2316             interfaceName =
2317                     makePackageQualified(BindingHelper.mangleNameToClassName(port.getName().getLocalPart()));
2318         }
2319         return interfaceName;
2320     }
2321 
2322     private void createJavaMethodForAsyncOperation(Port port, Operation operation,
2323                                                    JavaInterface intf) {
2324         String candidateName = getJavaNameForOperation(operation);
2325         JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
2326         Request request = operation.getRequest();
2327         Iterator requestBodyBlocks = request.getBodyBlocks();
2328         Block requestBlock =
2329                 (requestBodyBlocks.hasNext()
2330                         ? request.getBodyBlocks().next()
2331                         : null);
2332 

2333         Response response = operation.getResponse();
2334         Iterator responseBodyBlocks = null;
2335         Block responseBlock;
2336         if (response != null) {
2337             responseBodyBlocks = response.getBodyBlocks();
2338             responseBlock =
2339                     responseBodyBlocks.hasNext()
2340                             ? response.getBodyBlocks().next()
2341                             : null;
2342         }
2343 
2344         // build a signature of the form "opName%arg1type%arg2type%...%argntype so that we
2345         // detect overloading conflicts in the generated java interface/classes
2346         String signature = candidateName;
2347         for (Iterator iter = request.getParameters(); iter.hasNext();) {
2348             Parameter parameter = (Parameter) iter.next();
2349 
2350             if (parameter.getJavaParameter() != null) {
2351                 error(operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION(operation.getName().getLocalPart()));
2352             }
2353 
2354             JavaType parameterType = parameter.getType().getJavaType();
2355             JavaParameter javaParameter =
2356                     new JavaParameter(
2357                                 BindingHelper.mangleNameToVariableName(parameter.getName()),
2358                             parameterType,
2359                             parameter,
2360                             parameter.getLinkedParameter() != null);
2361             if (javaParameter.isHolder()) {
2362                 javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
2363             }
2364             method.addParameter(javaParameter);
2365             parameter.setJavaParameter(javaParameter);
2366 
2367             signature += "%" + parameterType.getName();
2368         }
2369 
2370         if (response != null) {
2371             String resultParameterName =
2372                     (String) operation.getProperty(WSDL_RESULT_PARAMETER);
2373             Parameter resultParameter =
2374                     response.getParameterByName(resultParameterName);
2375             JavaType returnType = resultParameter.getType().getJavaType();
2376             method.setReturnType(returnType);
2377 
2378         }
2379         operation.setJavaMethod(method);
2380         intf.addMethod(method);
2381     }
2382 
2383     /* (non-Javadoc)
2384      * @see WSDLModelerBase#createJavaMethodForOperation(WSDLPort, WSDLOperation, JavaInterface, Set, Set)
2385      */
2386     protected void createJavaMethodForOperation(Port port, Operation operation, JavaInterface intf) {
2387         if ((operation instanceof AsyncOperation)) {
2388             createJavaMethodForAsyncOperation(port, operation, intf);
2389             return;
2390         }
2391         String candidateName = getJavaNameForOperation(operation);
2392         JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
2393         Request request = operation.getRequest();
2394         Parameter returnParam = (Parameter) operation.getProperty(WSDL_RESULT_PARAMETER);
2395         if (returnParam != null) {
2396             JavaType parameterType = returnParam.getType().getJavaType();
2397             method.setReturnType(parameterType);
2398         } else {
2399             method.setReturnType(JavaSimpleTypeCreator.VOID_JAVATYPE);
2400         }
2401         List<Parameter> parameterOrder = (List<Parameter>) operation.getProperty(WSDL_PARAMETER_ORDER);
2402         for (Parameter param : parameterOrder) {
2403             JavaType parameterType = param.getType().getJavaType();
2404             String name = (param.getCustomName() != null) ? param.getCustomName() : param.getName();
2405             name = BindingHelper.mangleNameToVariableName(name);
2406             //if its a java keyword after name mangling, then we simply put underscore as there is no
2407             //need to ask user to customize the parameter name if its java keyword
2408             if(Names.isJavaReservedWord(name)){
2409                 name = "_"+name;
2410             }
2411             JavaParameter javaParameter =
2412                     new JavaParameter(
2413                             name,


2497 
2498     protected boolean isRequestResponse() {
2499         return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
2500     }
2501 
2502     protected java.util.List<String> getAsynParameterOrder() {
2503         //for async operation ignore the parameterOrder
2504         java.util.List<String> parameterList = new ArrayList<String>();
2505         Message inputMessage = getInputMessage();
2506         List<MessagePart> inputParts = inputMessage.getParts();
2507         for (MessagePart part : inputParts) {
2508             parameterList.add(part.getName());
2509         }
2510         return parameterList;
2511     }
2512 
2513 
2514     protected List<MessagePart> getParameterOrder() {
2515         List<MessagePart> params = new ArrayList<MessagePart>();
2516         String parameterOrder = info.portTypeOperation.getParameterOrder();
2517         java.util.List<String> parameterList = new ArrayList<String>();
2518         boolean parameterOrderPresent = false;
2519         if ((parameterOrder != null) && !(parameterOrder.trim().equals(""))) {
2520             parameterList = XmlUtil.parseTokenList(parameterOrder);
2521             parameterOrderPresent = true;
2522         } else {
2523             parameterList = new ArrayList<String>();
2524         }
2525         Message inputMessage = getInputMessage();
2526         Message outputMessage = getOutputMessage();
2527         List<MessagePart> outputParts = null;
2528         List<MessagePart> inputParts = inputMessage.getParts();
2529         //reset the mode and ret flag, as MEssagePArts aer shared across ports
2530         for (MessagePart part : inputParts) {
2531             part.setMode(Mode.IN);
2532             part.setReturn(false);
2533         }
2534         if (isRequestResponse()) {
2535             outputParts = outputMessage.getParts();
2536             for (MessagePart part : outputParts) {
2537                 part.setMode(Mode.OUT);


2619                         MessagePart resultPart = outputUnlistedParts.get(0);
2620                         resultPart.setReturn(true);
2621                         params.add(resultPart);
2622                         outputUnlistedParts.clear();
2623                     }
2624                 }
2625 
2626                 //add the input and output unlisted parts
2627                 for (MessagePart part : inputUnlistedParts) {
2628                     params.add(part);
2629                 }
2630 
2631                 for (MessagePart part : outputUnlistedParts) {
2632                     params.add(part);
2633                 }
2634                 return params;
2635 
2636             }
2637             //parameterOrder attribute is not valid, we ignore it
2638             warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETER_ORDER_INVALID_PARAMETER_ORDER(info.operation.getName().getLocalPart()));
2639             parameterOrderPresent = false;
2640             parameterList.clear();
2641         }
2642 
2643         List<MessagePart> outParts = new ArrayList<MessagePart>();
2644 
2645         //construct input parameter list with the same order as in input message
2646         for (MessagePart part : inputParts) {
2647             params.add(part);
2648         }
2649 
2650         if (isRequestResponse()) {
2651             for (MessagePart part : outputParts) {
2652                 MessagePart inPart = inputMessage.getPart(part.getName());
2653                 if (inPart != null && part.getDescriptorKind() == inPart.getDescriptorKind() &&
2654                         part.getDescriptor().equals(inPart.getDescriptor())) {
2655                     inPart.setMode(Mode.INOUT);
2656                     continue;
2657                 }
2658                 outParts.add(part);
2659             }
2660 
2661             //append the out parts to the parameterList
2662             for (MessagePart part : outParts) {
2663                 if (outParts.size() == 1)
2664                     part.setReturn(true);

2665                 params.add(part);
2666             }
2667         }
2668         return params;
2669     }
2670 
2671     /**
2672      * @param port
2673      * @param suffix
2674      * @return the Java ClassName for a port
2675      */
2676     protected String getClassName(Port port, String suffix) {
2677         String prefix = BindingHelper.mangleNameToClassName((port.getName().getLocalPart()));
2678         return options.defaultPackage + "." + prefix + suffix;
2679     }
2680 

2681     protected boolean isConflictingServiceClassName(String name) {
2682         return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name) || conflictsWithExceptionClass(name);
2683     }
2684 
2685     private boolean conflictsWithSEIClass(String name) {
2686         Set<String> seiNames = classNameCollector.getSeiClassNames();
2687         return seiNames != null && seiNames.contains(name);
2688     }
2689 
2690     private boolean conflictsWithJAXBClass(String name) {
2691         Set<String> jaxbNames = classNameCollector.getJaxbGeneratedClassNames();
2692         return jaxbNames != null && jaxbNames.contains(name);
2693     }
2694 
2695     private boolean conflictsWithExceptionClass(String name) {
2696         Set<String> exceptionNames = classNameCollector.getExceptionClassNames();
2697         return exceptionNames != null && exceptionNames.contains(name);
2698     }
2699 

2700     protected boolean isConflictingExceptionClassName(String name) {
2701         return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name);
2702     }
2703 
2704     protected JAXBModelBuilder getJAXBModelBuilder() {
2705         return jaxbModelBuilder;
2706     }
2707 
2708     protected boolean validateWSDLBindingStyle(Binding binding) {
2709         SOAPBinding soapBinding =
2710                 (SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
2711 
2712         //dont process the binding
2713         if (soapBinding == null)
2714             soapBinding =
2715                     (SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
2716         if (soapBinding == null)
2717             return false;

2718 
2719         //if soapbind:binding has no style attribute, the default is DOCUMENT
2720         if (soapBinding.getStyle() == null)
2721             soapBinding.setStyle(SOAPStyle.DOCUMENT);

2722 
2723         SOAPStyle opStyle = soapBinding.getStyle();
2724         for (Iterator iter = binding.operations(); iter.hasNext();) {
2725             BindingOperation bindingOperation =
2726                     (BindingOperation) iter.next();
2727             SOAPOperation soapOperation =
2728                     (SOAPOperation) getExtensionOfType(bindingOperation,
2729                             SOAPOperation.class);
2730             if (soapOperation != null) {
2731                 SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation.getStyle() : soapBinding.getStyle();
2732                 //dont check for the first operation
2733                 if (!currOpStyle.equals(opStyle))
2734                     return false;

2735             }
2736         }
2737         return true;
2738     }
2739 
2740     /**
2741      * @param port
2742      */
2743     private void applyWrapperStyleCustomization(Port port, PortType portType) {
2744         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2745         Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding.isEnableWrapperStyle() : null;
2746         if (wrapperStyle != null) {
2747             port.setWrapped(wrapperStyle);
2748         }
2749     }
2750 
2751     protected static void setDocumentationIfPresent(
2752             ModelObject obj,
2753             Documentation documentation) {
2754         if (documentation != null && documentation.getContent() != null) {


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.processor.modeler.wsdl;
  27 
  28 import com.sun.codemodel.internal.JType;
  29 import com.sun.istack.internal.NotNull;
  30 import com.sun.istack.internal.SAXParseException2;
  31 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
  32 import com.sun.tools.internal.ws.processor.generator.Names;
  33 import com.sun.tools.internal.ws.processor.model.*;
  34 import com.sun.tools.internal.ws.processor.model.Fault;
  35 import com.sun.tools.internal.ws.processor.model.Operation;
  36 import com.sun.tools.internal.ws.processor.model.Port;
  37 import com.sun.tools.internal.ws.processor.model.Service;
  38 import com.sun.tools.internal.ws.processor.model.java.*;
  39 import com.sun.tools.internal.ws.processor.model.jaxb.*;
  40 import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
  41 import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
  42 import com.sun.tools.internal.ws.resources.ModelerMessages;
  43 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
  44 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
  45 import com.sun.tools.internal.ws.wsdl.document.*;
  46 import com.sun.tools.internal.ws.wsdl.document.Message;
  47 import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
  48 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
  49 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
  50 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
  51 import com.sun.tools.internal.ws.wsdl.document.soap.*;
  52 import com.sun.tools.internal.ws.wsdl.framework.*;
  53 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
  54 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
  55 import com.sun.tools.internal.xjc.api.S2JJAXBModel;
  56 import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
  57 import com.sun.tools.internal.xjc.api.XJC;

  58 import com.sun.xml.internal.ws.spi.db.BindingHelper;
  59 import com.sun.xml.internal.ws.util.xml.XmlUtil;
  60 import org.xml.sax.InputSource;
  61 import org.xml.sax.Locator;
  62 import org.xml.sax.SAXException;
  63 import org.xml.sax.SAXParseException;
  64 import org.xml.sax.helpers.LocatorImpl;
  65 
  66 import javax.jws.WebParam.Mode;
  67 import javax.xml.namespace.QName;
  68 import java.util.*;
  69 import java.io.IOException;
  70 
  71 
  72 /**
  73  * The WSDLModeler processes a WSDL to create a Model.
  74  *
  75  * @author WS Development Team
  76  */
  77 public class WSDLModeler extends WSDLModelerBase {
  78 
  79     //map of wsdl:operation QName to <soapenv:Body> child, as per BP it must be unique in a port
  80     private final Map<QName, Operation> uniqueBodyBlocks = new HashMap<QName, Operation>();
  81     private final QName VOID_BODYBLOCK = new QName("");
  82     private final ClassNameCollector classNameCollector;
  83     private final String explicitDefaultPackage;
  84 
  85     public WSDLModeler(WsimportOptions options, ErrorReceiver receiver, MetadataFinder forest) {
  86         super(options, receiver,forest);
  87         this.classNameCollector = new ClassNameCollector();
  88         this.explicitDefaultPackage = options.defaultPackage;
  89     }
  90 
  91 
  92     protected enum StyleAndUse {
  93         RPC_LITERAL, DOC_LITERAL
  94     }
  95 
  96     private JAXBModelBuilder jaxbModelBuilder;
  97 
  98     @Override
  99     public Model buildModel() {
 100         try {
 101             parser = new WSDLParser(options, errReceiver, forest);
 102             parser.addParserListener(new ParserListener() {
 103                 @Override
 104                 public void ignoringExtension(Entity entity, QName name, QName parent) {
 105                     if (parent.equals(WSDLConstants.QNAME_TYPES)) {
 106                         // check for a schema element with the wrong namespace URI
 107                         if (name.getLocalPart().equals("schema")
 108                                 && !name.getNamespaceURI().equals("")) {
 109                             warning(entity, ModelerMessages.WSDLMODELER_WARNING_IGNORING_UNRECOGNIZED_SCHEMA_EXTENSION(name.getNamespaceURI()));
 110                         }
 111                     }
 112 
 113                 }
 114 
 115                 @Override
 116                 public void doneParsingEntity(QName element, Entity entity) {
 117                 }
 118             });
 119 
 120             document = parser.parse();
 121             if (document == null || document.getDefinitions() == null) {
 122                 return null;
 123             }
 124 
 125             document.validateLocally();
 126             Model model = internalBuildModel(document);
 127             if (model == null || errReceiver.hadError()) {
 128                 return null;
 129             }
 130             //ClassNameCollector classNameCollector = new ClassNameCollector();
 131             classNameCollector.process(model);
 132             if (classNameCollector.getConflictingClassNames().isEmpty()) {
 133                 if (errReceiver.hadError()) {
 134                     return null;
 135                 }
 136                 return model;
 137             }
 138             // do another pass, this time with conflict resolution enabled
 139             model = internalBuildModel(document);
 140 
 141             classNameCollector.process(model);
 142             if (classNameCollector.getConflictingClassNames().isEmpty()) {
 143                 // we're done
 144                 if (errReceiver.hadError()) {
 145                     return null;
 146                 }
 147                 return model;
 148             }
 149             // give up
 150             StringBuilder conflictList = new StringBuilder();
 151             boolean first = true;
 152             for (Iterator iter =
 153                     classNameCollector.getConflictingClassNames().iterator();
 154                  iter.hasNext();
 155                     ) {
 156                 if (!first) {
 157                     conflictList.append(", ");
 158                 } else {
 159                     first = false;
 160                 }
 161                 conflictList.append((String) iter.next());
 162             }
 163             error(document.getDefinitions(), ModelerMessages.WSDLMODELER_UNSOLVABLE_NAMING_CONFLICTS(conflictList.toString()));
 164         } catch (ModelException e) {
 165             reportError(document.getDefinitions(), e.getMessage(), e);
 166         } catch (ParseException e) {
 167             errReceiver.error(e);
 168         } catch (ValidationException e) {
 169             errReceiver.error(e.getMessage(), e);
 170         } catch (SAXException e) {


 198         model.setProperty(
 199                 ModelProperties.PROPERTY_MODELER_NAME,
 200                 ModelProperties.WSDL_MODELER_NAME);
 201 
 202         _javaExceptions = new HashMap<String, JavaException>();
 203         _bindingNameToPortMap = new HashMap<QName, Port>();
 204 
 205         // grab target namespace
 206         model.setTargetNamespaceURI(document.getDefinitions().getTargetNamespaceURI());
 207 
 208         setDocumentationIfPresent(model,
 209                 document.getDefinitions().getDocumentation());
 210 
 211         boolean hasServices = document.getDefinitions().services().hasNext();
 212         if (hasServices) {
 213             for (Iterator iter = document.getDefinitions().services();
 214                  iter.hasNext();
 215                     ) {
 216                 processService((com.sun.tools.internal.ws.wsdl.document.Service) iter.next(),
 217                         model, document);

 218             }
 219         } else {
 220             // emit a warning if there are no service definitions
 221             warning(model.getEntity(), ModelerMessages.WSDLMODELER_WARNING_NO_SERVICE_DEFINITIONS_FOUND());
 222         }
 223 
 224         return model;
 225     }
 226 
 227     /* (non-Javadoc)
 228      * @see WSDLModelerBase#processService(Service, Model, WSDLDocument)
 229      */
 230     protected void processService(com.sun.tools.internal.ws.wsdl.document.Service wsdlService, Model model, WSDLDocument document) {
 231         QName serviceQName = getQNameOf(wsdlService);
 232         String serviceInterface = getServiceInterfaceName(serviceQName, wsdlService);
 233         if (isConflictingServiceClassName(serviceInterface)) {
 234             serviceInterface += "_Service";
 235         }
 236         Service service =
 237                 new Service(


 265 
 266             //clear the  unique block map
 267             uniqueBodyBlocks.clear();
 268 
 269             QName portQName = getQNameOf(wsdlPort);
 270             Port port = new Port(portQName, wsdlPort);
 271 
 272             setDocumentationIfPresent(port, wsdlPort.getDocumentation());
 273 
 274             SOAPAddress soapAddress =
 275                     (SOAPAddress) getExtensionOfType(wsdlPort, SOAPAddress.class);
 276             if (soapAddress == null) {
 277                 if(options.isExtensionMode()){
 278                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_SOAP_ADDRESS(wsdlPort.getName()));
 279                 }else{
 280                     // not a SOAP port, ignore it
 281                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT_NO_ADDRESS(wsdlPort.getName()));
 282                     return false;
 283                 }
 284             }
 285             if (soapAddress != null) {
 286                 port.setAddress(soapAddress.getLocation());
 287             }
 288             Binding binding = wsdlPort.resolveBinding(document);
 289             QName bindingName = getQNameOf(binding);
 290             PortType portType = binding.resolvePortType(document);
 291 
 292             port.setProperty(
 293                     ModelProperties.PROPERTY_WSDL_PORT_NAME,
 294                     getQNameOf(wsdlPort));
 295             port.setProperty(
 296                     ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
 297                     getQNameOf(portType));
 298             port.setProperty(
 299                     ModelProperties.PROPERTY_WSDL_BINDING_NAME,
 300                     bindingName);
 301 
 302             boolean isProvider = isProvider(wsdlPort);
 303             if (_bindingNameToPortMap.containsKey(bindingName) && !isProvider) {
 304                 // this binding has been processed before
 305                 Port existingPort =
 306                         _bindingNameToPortMap.get(bindingName);
 307                 port.setOperations(existingPort.getOperations());


 383                         if (operation
 384                                 .getName()
 385                                 .equals(bindingOperation.getName())) {
 386                             break;
 387                         } else if (!itr.hasNext()) {
 388                             error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(operation.getName(), bindingOperation.getName()));
 389                         }
 390                     }
 391                 }
 392 
 393                 Map headers = new HashMap();
 394                 boolean hasOperations = false;
 395                 for (Iterator iter = binding.operations(); iter.hasNext();) {
 396                     BindingOperation bindingOperation =
 397                             (BindingOperation) iter.next();
 398 
 399                     com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation =
 400                             null;
 401                     Set operations =
 402                             portType.getOperationsNamed(bindingOperation.getName());
 403                     if (operations.isEmpty()) {
 404                         // the WSDL document is invalid
 405                         error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_IN_PORT_TYPE(bindingOperation.getName(), binding.getName()));
 406                     } else if (operations.size() == 1) {
 407                         portTypeOperation =
 408                                 (com.sun.tools.internal.ws.wsdl.document.Operation) operations
 409                                         .iterator()
 410                                         .next();
 411                     } else {
 412                         boolean found = false;
 413                         String expectedInputName =
 414                                 bindingOperation.getInput().getName();
 415                         String expectedOutputName =
 416                                 bindingOperation.getOutput().getName();
 417 
 418                         for (Iterator iter2 = operations.iterator(); iter2.hasNext();) {
 419                             com.sun.tools.internal.ws.wsdl.document.Operation candidateOperation =
 420                                     (com.sun.tools.internal.ws.wsdl.document.Operation) iter2
 421                                             .next();
 422 
 423                             if (expectedInputName == null) {


 445                         }
 446                         if (!found) {
 447                             // the WSDL document is invalid
 448                             error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(bindingOperation.getName(), binding.getName()));
 449                         }
 450                     }
 451                     if (!isProvider) {
 452                         this.info =
 453                                 new ProcessSOAPOperationInfo(
 454                                         port,
 455                                         wsdlPort,
 456                                         portTypeOperation,
 457                                         bindingOperation,
 458                                         soapBinding,
 459                                         document,
 460                                         hasOverloadedOperations,
 461                                         headers);
 462 
 463 
 464                         Operation operation;
 465                         if (soapBinding != null) {
 466                             operation = processSOAPOperation();
 467                         } else {
 468                             operation = processNonSOAPOperation();
 469                         }
 470                         if (operation != null) {
 471                             port.addOperation(operation);
 472                             hasOperations = true;
 473                         }
 474                     }
 475                 }
 476                 if (!isProvider && !hasOperations) {
 477                     // emit a warning if there are no operations, except when its a provider port
 478                     warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_OPERATIONS_IN_PORT(wsdlPort.getName()));
 479                     return false;
 480                 }
 481                 createJavaInterfaceForPort(port, isProvider);
 482                 PortType pt = binding.resolvePortType(document);
 483                 String jd = (pt.getDocumentation() != null) ? pt.getDocumentation().getContent() : null;
 484                 port.getJavaInterface().setJavaDoc(jd);
 485                 _bindingNameToPortMap.put(bindingName, port);
 486             }
 487 


 590         Binding binding = info.port.resolveBinding(document);
 591         PortType portType = binding.resolvePortType(document);
 592         if (isAsync(portType, info.portTypeOperation)) {
 593             warning(portType, "Can not generate Async methods for non-soap binding!");
 594         }
 595         return info.operation;
 596     }
 597 
 598     /**
 599      * This method is added to fix one of the use case for j2ee se folks, so that we determine
 600      * for non_soap wsdl what could be the style - rpc or document based on parts in the message.
 601      *
 602      * We assume that the message parts could have either all of them with type attribute (RPC)
 603      * or element (DOCUMENT)
 604      *
 605      * Shall this check if parts are mixed and throw error message?
 606      */
 607     private void setNonSoapStyle(Message inputMessage, Message outputMessage) {
 608         SOAPStyle style = SOAPStyle.DOCUMENT;
 609         for(MessagePart part:inputMessage.getParts()){
 610             if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
 611                 style = SOAPStyle.RPC;
 612             } else {
 613                 style = SOAPStyle.DOCUMENT;
 614             }
 615         }
 616 
 617         //check the outputMessage parts
 618         if(outputMessage != null){
 619             for(MessagePart part:outputMessage.getParts()){
 620                 if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
 621                     style = SOAPStyle.RPC;
 622                 } else {
 623                     style = SOAPStyle.DOCUMENT;
 624                 }
 625             }
 626         }
 627         info.modelPort.setStyle(style);
 628     }
 629 
 630     /* (non-Javadoc)
 631      * @see WSDLModelerBase#processSOAPOperation()
 632      */
 633     protected Operation processSOAPOperation() {
 634         Operation operation =
 635                 new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
 636 
 637         setDocumentationIfPresent(
 638                 operation,
 639                 info.portTypeOperation.getDocumentation());
 640 
 641         if (info.portTypeOperation.getStyle()
 642                 != OperationStyle.REQUEST_RESPONSE
 643                 && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
 644             if (options.isExtensionMode()) {
 645                 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
 646                 return null;


 658                         SOAPOperation.class);
 659 
 660         if (soapOperation != null) {
 661             if (soapOperation.getStyle() != null) {
 662                 soapStyle = soapOperation.getStyle();
 663             }
 664             if (soapOperation.getSOAPAction() != null) {
 665                 operation.setSOAPAction(soapOperation.getSOAPAction());
 666             }
 667         }
 668 
 669         operation.setStyle(soapStyle);
 670 
 671         String uniqueOperationName =
 672                 getUniqueName(info.portTypeOperation, info.hasOverloadedOperations);
 673         if (info.hasOverloadedOperations) {
 674             operation.setUniqueName(uniqueOperationName);
 675         }
 676 
 677         info.operation = operation;

 678 
 679         //attachment
 680         SOAPBody soapRequestBody = getSOAPRequestBody();
 681         if (soapRequestBody == null) {
 682             // the WSDL document is invalid
 683             error(info.bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
 684         }
 685 
 686         if (soapStyle == SOAPStyle.RPC) {
 687             if (soapRequestBody.isEncoded()) {
 688                 if(options.isExtensionMode()){
 689                     warning(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
 690                     processNonSOAPOperation();
 691                 }else{
 692                     error(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
 693                 }
 694             }
 695             return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
 696         }
 697         // document style
 698         return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
 699     }
 700 
 701     protected Operation processLiteralSOAPOperation(StyleAndUse styleAndUse) {
 702         //returns false if the operation name is not acceptable
 703         if (!applyOperationNameCustomization()) {
 704             return null;
 705         }
 706 
 707         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
 708         Message inputMessage = getInputMessage();
 709         Request request = new Request(inputMessage, errReceiver);
 710         request.setErrorReceiver(errReceiver);
 711         info.operation.setUse(SOAPUse.LITERAL);
 712         info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
 713         SOAPBody soapRequestBody = getSOAPRequestBody();
 714         if ((StyleAndUse.DOC_LITERAL == styleAndUse) && (soapRequestBody.getNamespace() != null)) {
 715             warning(soapRequestBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
 716         }
 717 
 718 
 719         Response response;
 720 
 721         SOAPBody soapResponseBody = null;
 722         Message outputMessage = null;
 723         if (isRequestResponse) {
 724             soapResponseBody = getSOAPResponseBody();
 725             if (isOperationDocumentLiteral(styleAndUse) && (soapResponseBody.getNamespace() != null)) {
 726                 warning(soapResponseBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
 727             }
 728             outputMessage = getOutputMessage();
 729             response = new Response(outputMessage, errReceiver);
 730         }else{
 731             response = new Response(null, errReceiver);
 732         }
 733 
 734         //ignore operation if there are more than one root part
 735         if (!validateMimeParts(getMimeParts(info.bindingOperation.getInput())) ||
 736                 !validateMimeParts(getMimeParts(info.bindingOperation.getOutput()))) {
 737             return null;
 738         }
 739 
 740         if (!validateBodyParts(info.bindingOperation)) {
 741             // BP 1.1
 742             // R2204   A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s),
 743             // only to wsdl:part element(s) that have been defined using the element attribute.
 744 
 745             // R2203   An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s),
 746             // only to wsdNl:part element(s) that have been defined using the type attribute.
 747             if (isOperationDocumentLiteral(styleAndUse)) {
 748                 if (options.isExtensionMode()) {
 749                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_TYPE_MESSAGE_PART(info.portTypeOperation.getName()));
 750                 } else {
 751                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_DOCLITOPERATION(info.portTypeOperation.getName()));
 752                 }
 753             } else if (isOperationRpcLiteral(styleAndUse)) {
 754                 if (options.isExtensionMode()) {
 755                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_ELEMENT_MESSAGE_PART(info.portTypeOperation.getName()));
 756                 } else {
 757                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_RPCLITOPERATION(info.portTypeOperation.getName()));
 758                 }
 759             }
 760             return null;
 761         }
 762 
 763         // Process parameterOrder and get the parameterList
 764         List<MessagePart> parameterList = getParameterOrder();
 765 
 766         //binding is invalid in the wsdl, ignore the operation.
 767         if (!setMessagePartsBinding(styleAndUse)) {
 768             return null;
 769         }
 770 
 771         List<Parameter> params = null;
 772         boolean unwrappable = isUnwrappable();
 773         info.operation.setWrapped(unwrappable);
 774         if (isOperationDocumentLiteral(styleAndUse)) {
 775             params = getDoclitParameters(request, response, parameterList);
 776         } else if (isOperationRpcLiteral(styleAndUse)) {
 777             String operationName = info.bindingOperation.getName();
 778             Block reqBlock = null;
 779             if (inputMessage != null) {
 780                 QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
 781                 RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
 782                 rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
 783                 reqBlock = new Block(name, rpcStruct, inputMessage);
 784                 request.addBodyBlock(reqBlock);
 785             }
 786 
 787             Block resBlock = null;
 788             if (isRequestResponse && outputMessage != null) {
 789                 QName name = new QName(getResponseNamespaceURI(soapResponseBody), operationName + "Response");


 897         Set duplicateNames = getDuplicateFaultNames();
 898 
 899         // handle soap:fault
 900         handleLiteralSOAPFault(response, duplicateNames);
 901         info.operation.setProperty(
 902                 WSDL_PARAMETER_ORDER,
 903                 definitiveParameterList);
 904 
 905         //set Async property
 906         Binding binding = info.port.resolveBinding(document);
 907         PortType portType = binding.resolvePortType(document);
 908         if (isAsync(portType, info.portTypeOperation)) {
 909             addAsyncOperations(info.operation, styleAndUse);
 910         }
 911 
 912         return info.operation;
 913     }
 914 
 915 
 916     private boolean validateParameterName(List<Parameter> params) {
 917         if (options.isExtensionMode()) {
 918             return true;
 919         }
 920 
 921         Message msg = getInputMessage();
 922         for (Parameter param : params) {
 923             if (param.isOUT()) {
 924                 continue;
 925             }
 926             if (param.getCustomName() != null) {
 927                 if (Names.isJavaReservedWord(param.getCustomName())) {
 928                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
 929                     return false;
 930                 }
 931                 return true;
 932             }
 933             //process doclit wrapper style
 934             if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
 935                 if (Names.isJavaReservedWord(param.getName())) {
 936                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
 937                     return false;
 938                 }
 939             } else {
 940                 //non-wrapper style and rpclit
 941                 if (Names.isJavaReservedWord(param.getName())) {
 942                     error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
 943                     return false;
 944                 }
 945             }
 946         }
 947 
 948         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
 949         if (isRequestResponse) {
 950             msg = getOutputMessage();
 951             for (Parameter param : params) {
 952                 if (param.isIN()) {
 953                     continue;
 954                 }
 955                 if (param.getCustomName() != null) {
 956                     if (Names.isJavaReservedWord(param.getCustomName())) {
 957                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
 958                         return false;
 959                     }
 960                     return true;
 961                 }
 962                 //process doclit wrapper style
 963                 if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
 964                     if (param.isReturn()) {
 965                         continue;
 966                     }
 967                     if (!param.getName().equals("return") && Names.isJavaReservedWord(param.getName())) {
 968                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
 969                         return false;
 970                     }
 971                 } else {
 972                     if (param.isReturn()) {
 973                         continue;
 974                     }
 975 
 976                     //non-wrapper style and rpclit
 977                     if (Names.isJavaReservedWord(param.getName())) {
 978                         error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
 979                         return false;
 980                     }
 981                 }
 982             }
 983         }
 984 
 985         return true;
 986     }
 987 
 988     private boolean enableMimeContent() {
 989         //first we look at binding operation
 990         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.bindingOperation, JAXWSBinding.class);
 991         Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
 992         if (mimeContentMapping != null) {
 993             return mimeContentMapping;
 994         }
 995 
 996         //then in wsdl:binding
 997         Binding binding = info.port.resolveBinding(info.document);
 998         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding, JAXWSBinding.class);
 999         mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
1000         if (mimeContentMapping != null) {
1001             return mimeContentMapping;
1002         }
1003 
1004         //at last look in wsdl:definitions
1005         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.document.getDefinitions(), JAXWSBinding.class);
1006         mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
1007         if (mimeContentMapping != null) {
1008             return mimeContentMapping;
1009         }
1010         return false;
1011     }
1012 
1013     private boolean applyOperationNameCustomization() {
1014         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.portTypeOperation, JAXWSBinding.class);
1015         String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization.getMethodName() != null) ? jaxwsCustomization.getMethodName().getName() : null) : null;
1016         if (operationName != null) {
1017             if (Names.isJavaReservedWord(operationName)) {
1018                 if (options.isExtensionMode()) {
1019                     warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
1020                 } else {
1021                     error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
1022                 }
1023                 return false;
1024             }
1025 
1026             info.operation.setCustomizedName(operationName);
1027         }
1028 
1029         if (Names.isJavaReservedWord(info.operation.getJavaMethodName())) {
1030             if (options.isExtensionMode()) {
1031                 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
1032             } else {
1033                 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
1034             }
1035             return false;
1036         }
1037         return true;
1038     }
1039 
1040     protected String getAsyncOperationName(Operation operation) {
1041         String name = operation.getCustomizedName();
1042         if (name == null) {
1043             name = operation.getUniqueName();
1044         }
1045         return name;
1046     }
1047 
1048     /**
1049      * @param styleAndUse
1050      */
1051     private void addAsyncOperations(Operation syncOperation, StyleAndUse styleAndUse) {
1052         Operation operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.POLLING);
1053         if (operation != null) {
1054             info.modelPort.addOperation(operation);
1055         }
1056 
1057         operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.CALLBACK);
1058         if (operation != null) {
1059             info.modelPort.addOperation(operation);
1060         }
1061     }
1062 
1063     private Operation createAsyncOperation(Operation syncOperation, StyleAndUse styleAndUse, AsyncOperationType asyncType) {
1064         boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1065         if (!isRequestResponse) {
1066             return null;
1067         }
1068 
1069         //create async operations
1070         AsyncOperation operation = new AsyncOperation(info.operation, info.bindingOperation);
1071 
1072         //creation the async operation name: operationName+Async or customized name
1073         //operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
1074         if (asyncType.equals(AsyncOperationType.CALLBACK)) {
1075             operation.setUniqueName(info.operation.getUniqueName() + "_async_callback");
1076         } else if (asyncType.equals(AsyncOperationType.POLLING)) {
1077             operation.setUniqueName(info.operation.getUniqueName() + "_async_polling");
1078         }
1079 
1080         setDocumentationIfPresent(
1081                 operation,
1082                 info.portTypeOperation.getDocumentation());
1083 
1084         operation.setAsyncType(asyncType);
1085         operation.setSOAPAction(info.operation.getSOAPAction());
1086         boolean unwrappable = info.operation.isWrapped();
1087         operation.setWrapped(unwrappable);
1088         SOAPBody soapRequestBody = getSOAPRequestBody();
1089 
1090         Message inputMessage = getInputMessage();
1091         Request request = new Request(inputMessage, errReceiver);
1092 
1093         SOAPBody soapResponseBody = getSOAPResponseBody();
1094         Message outputMessage = getOutputMessage();
1095         Response response = new Response(outputMessage, errReceiver);
1096 
1097         // Process parameterOrder and get the parameterList
1098         java.util.List<String> parameterList = getAsynParameterOrder();


1159         int numOfOutMsgParts = outputParts.size();
1160 
1161         if (numOfOutMsgParts == 1) {
1162             MessagePart part = outputParts.get(0);
1163             if (isOperationDocumentLiteral(styleAndUse)) {
1164                 JAXBType type = getJAXBType(part);
1165                 operation.setResponseBean(type);
1166             } else if (isOperationRpcLiteral(styleAndUse)) {
1167                 String operationName = info.bindingOperation.getName();
1168                 Block resBlock = info.operation.getResponse().getBodyBlocksMap().get(new QName(getResponseNamespaceURI(soapResponseBody),
1169                         operationName + "Response"));
1170 
1171                 RpcLitStructure resBean = (RpcLitStructure) resBlock.getType();
1172                 List<RpcLitMember> members = resBean.getRpcLitMembers();
1173                 operation.setResponseBean(members.get(0));
1174             }
1175         } else {
1176             //create response bean
1177             String nspace = "";
1178             QName responseBeanName = new QName(nspace, getAsyncOperationName(info.operation) + "Response");
1179             JAXBType responseBeanType = getJAXBModelBuilder().getJAXBType(responseBeanName);
1180             if (responseBeanType == null) {
1181                 error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation.getName()));
1182             }
1183             operation.setResponseBean(responseBeanType);
1184         }
1185 
1186         QName respBeanName = new QName(soapResponseBody.getNamespace(), getAsyncOperationName(info.operation) + "Response");
1187         Block block = new Block(respBeanName, operation.getResponseBeanType(), outputMessage);
1188         JavaType respJavaType = operation.getResponseBeanJavaType();
1189         JAXBType respType = new JAXBType(respBeanName, respJavaType);
1190         Parameter respParam = ModelerUtils.createParameter(info.operation.getName() + "Response", respType, block);
1191         respParam.setParameterIndex(-1);
1192         response.addParameter(respParam);
1193         operation.setProperty(WSDL_RESULT_PARAMETER, respParam.getName());
1194 
1195 

1196         int parameterOrderPosition = 0;
1197         for (String name : parameterList) {
1198             Parameter inParameter = ModelerUtils.getParameter(name, inParameters);
1199             if (inParameter == null) {
1200                 if (options.isExtensionMode()) {
1201                     warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
1202                 } else {
1203                     error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_ERROR_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
1204                 }
1205                 return null;
1206             }
1207             request.addParameter(inParameter);
1208             inParameter.setParameterIndex(parameterOrderPosition);

1209             parameterOrderPosition++;
1210         }
1211 
1212         operation.setResponse(response);
1213 
1214         //  add callback handlerb Parameter to request
1215         if (operation.getAsyncType().equals(AsyncOperationType.CALLBACK)) {
1216             JavaType cbJavaType = operation.getCallBackType();
1217             JAXBType callbackType = new JAXBType(respBeanName, cbJavaType);
1218             Parameter cbParam = ModelerUtils.createParameter("asyncHandler", callbackType, block);
1219             request.addParameter(cbParam);
1220         }
1221 
1222         operation.setRequest(request);
1223 
1224         return operation;
1225     }
1226 
1227     protected boolean isAsync(com.sun.tools.internal.ws.wsdl.document.PortType portType, com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation) {
1228         //First look into wsdl:operation
1229         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(wsdlOperation, JAXWSBinding.class);
1230         Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1231 
1232         if (isAsync != null) {
1233             return isAsync;
1234         }
1235 
1236         // then into wsdl:portType

1237         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
1238         isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1239         if (isAsync != null) {
1240             return isAsync;
1241         }
1242 
1243         //then wsdl:definitions
1244         jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
1245         isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1246         if (isAsync != null) {
1247             return isAsync;
1248         }
1249         return false;
1250     }
1251 
1252     protected void handleLiteralSOAPHeaders(Request request, Response response, Iterator headerParts, Set duplicateNames, @NotNull List<String> definitiveParameterList, boolean processRequest) {
1253         QName headerName;
1254         Block headerBlock;
1255         JAXBType jaxbType;
1256         int parameterOrderPosition = definitiveParameterList.size();
1257         while (headerParts.hasNext()) {
1258             MessagePart part = (MessagePart) headerParts.next();
1259             headerName = part.getDescriptor();
1260             jaxbType = getJAXBType(part);
1261             headerBlock = new Block(headerName, jaxbType, part);
1262             TWSDLExtensible ext;
1263             if (processRequest) {
1264                 ext = info.bindingOperation.getInput();
1265             } else {
1266                 ext = info.bindingOperation.getOutput();
1267             }
1268             Message headerMessage = getHeaderMessage(part, ext);
1269 
1270             if (processRequest) {
1271                 request.addHeaderBlock(headerBlock);
1272             } else {
1273                 response.addHeaderBlock(headerBlock);
1274             }
1275 
1276             Parameter parameter = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1277             parameter.setParameterIndex(parameterOrderPosition);
1278             setCustomizedParameterName(info.bindingOperation, headerMessage, part, parameter, false);
1279             if (processRequest) {
1280                 request.addParameter(parameter);
1281                 definitiveParameterList.add(parameter.getName());
1282             } else {
1283                 for (String inParamName : definitiveParameterList) {



1284                     if (inParamName.equals(parameter.getName())) {
1285                         Parameter inParam = request.getParameterByName(inParamName);
1286                         parameter.setLinkedParameter(inParam);
1287                         inParam.setLinkedParameter(parameter);
1288                         //its in/out parameter, input and output parameter have the same order position.
1289                         parameter.setParameterIndex(inParam.getParameterIndex());
1290                     }
1291                 }
1292                 if (!definitiveParameterList.contains(parameter.getName())) {
1293                     definitiveParameterList.add(parameter.getName());
1294                 }

1295                 response.addParameter(parameter);
1296             }
1297             parameterOrderPosition++;
1298         }
1299 
1300     }
1301 
1302     protected void handleLiteralSOAPFault(Response response, Set duplicateNames) {
1303         for (BindingFault bindingFault : info.bindingOperation.faults()) {
1304             com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
1305             for (com.sun.tools.internal.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
1306                 if (aFault.getName().equals(bindingFault.getName())) {
1307                     if (portTypeFault != null) {
1308                         // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
1309                         error(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(), info.bindingOperation.getName()));
1310                     }
1311                     portTypeFault = aFault;
1312                 }
1313             }
1314 


1318 
1319             }
1320         }
1321         for ( com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault : info.portTypeOperation.faults()) {
1322 
1323             BindingFault bindingFault = null ;
1324             for(BindingFault bFault: info.bindingOperation.faults()) {
1325                 if (bFault.getName().equals(portTypeFault.getName())) {
1326                     bindingFault = bFault;
1327                 }
1328             }
1329 
1330             if(bindingFault == null) {
1331                 warning(portTypeFault,ModelerMessages.WSDLMODELER_INVALID_PORT_TYPE_FAULT_NOT_FOUND(portTypeFault.getName(),info.portTypeOperation.getName()));
1332             }
1333             // wsdl:fault message name is used to create the java exception name later on
1334             String faultName = getFaultClassName(portTypeFault);
1335             Fault fault = new Fault(faultName, portTypeFault);
1336             fault.setWsdlFaultName(portTypeFault.getName());
1337             setDocumentationIfPresent(fault, portTypeFault.getDocumentation());

1338             if (bindingFault != null) {
1339                 //get the soapbind:fault from wsdl:fault in the binding
1340                 SOAPFault soapFault = (SOAPFault) getExtensionOfType(bindingFault, SOAPFault.class);
1341 
1342                 // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
1343                 if (soapFault == null) {
1344                     if (options.isExtensionMode()) {
1345                         warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1346                         soapFault = new SOAPFault(new LocatorImpl());
1347                     } else {
1348                         error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1349                     }
1350                 }
1351 
1352                 //the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
1353                 if (!soapFault.isLiteral()) {
1354                     if (options.isExtensionMode()) {
1355                         warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
1356                     } else {
1357                         error(soapFault, ModelerMessages.WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
1358                     }
1359                     continue;
1360                 }
1361 
1362                 // the soapFault name must be present
1363                 if (soapFault.getName() == null) {
1364                     warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(bindingFault.getName(), info.bindingOperation.getName()));
1365                 } else if (!soapFault.getName().equals(bindingFault.getName())) {
1366                     warning(soapFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(soapFault.getName(), bindingFault.getName(), info.bindingOperation.getName()));
1367                 } else if (soapFault.getNamespace() != null) {
1368                     warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
1369                 }
1370 




1371             }
1372 
1373             com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault.resolveMessage(info.document);
1374             Iterator iter2 = faultMessage.parts();
1375             if (!iter2.hasNext()) {
1376                 // the WSDL document is invalid
1377                 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(portTypeFault.getName(), faultMessage.getName()));
1378             }
1379             MessagePart faultPart = (MessagePart) iter2.next();
1380             QName faultQName = faultPart.getDescriptor();
1381 
1382             // Don't include fault messages with non-unique soap:fault names
1383             if (duplicateNames.contains(faultQName)) {
1384                 warning(faultPart, ModelerMessages.WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(portTypeFault.getName(), info.portTypeOperation.getName(), faultPart.getName()));
1385                 continue;
1386             }
1387 
1388             if (iter2.hasNext()) {
1389                 // the WSDL document is invalid
1390                 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(portTypeFault.getName(), faultMessage.getName()));
1391             }
1392 
1393             if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1394                 if (options.isExtensionMode()) {
1395                     warning(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
1396                 } else {
1397                     error(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
1398                 }
1399             }
1400 
1401             JAXBType jaxbType = getJAXBType(faultPart);
1402 
1403             fault.setElementName(faultPart.getDescriptor());
1404             fault.setJavaMemberName(Names.getExceptionClassMemberName());
1405 
1406             Block faultBlock = new Block(faultQName, jaxbType, faultPart);
1407             fault.setBlock(faultBlock);
1408             //createParentFault(fault);
1409             //createSubfaults(fault);
1410             if (!response.getFaultBlocksMap().containsKey(faultBlock.getName())) {
1411                 response.addFaultBlock(faultBlock);
1412             }
1413             info.operation.addFault(fault);
1414         }
1415     }
1416 
1417     private String getFaultClassName(com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault) {
1418         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeFault, JAXWSBinding.class);
1419         if (jaxwsBinding != null) {
1420             CustomName className = jaxwsBinding.getClassName();
1421             if (className != null) {
1422                 return makePackageQualified(className.getName());
1423             }
1424         }
1425         return makePackageQualified(BindingHelper.mangleNameToClassName(portTypeFault.getMessage().getLocalPart()));
1426     }
1427 
1428     protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
1429         SOAPBody inBody = getSOAPRequestBody();
1430         Message inMessage = getInputMessage();
1431         if (!setMessagePartsBinding(inBody, inMessage, styleAndUse, true)) {
1432             return false;
1433         }
1434 
1435         if (isRequestResponse()) {
1436             SOAPBody outBody = getSOAPResponseBody();
1437             Message outMessage = getOutputMessage();
1438             if (!setMessagePartsBinding(outBody, outMessage, styleAndUse, false)) {
1439                 return false;
1440             }
1441         }
1442         return true;
1443     }
1444 
1445     //returns false if the wsdl is invalid and operation should be ignored
1446     protected boolean setMessagePartsBinding(SOAPBody body, Message message, StyleAndUse styleAndUse, boolean isInput) {

1447 
1448         //get Mime parts
1449         List<MessagePart> mimeParts;
1450         List<MessagePart> headerParts;
1451         List<MessagePart> bodyParts = getBodyParts(body, message);
1452 
1453         if (isInput) {
1454             headerParts = getHeaderPartsFromMessage(message, isInput);
1455             mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
1456         } else {
1457             headerParts = getHeaderPartsFromMessage(message, isInput);
1458             mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
1459         }
1460 
1461         //As of now WSDL MIME binding is not supported, so throw the exception when such binding is encounterd
1462 //        if(mimeParts.size() > 0){
1463 //            fail("wsdlmodeler.unsupportedBinding.mime", new Object[]{});
1464 //        }
1465 
1466         //if soap:body parts attribute not there, then all unbounded message parts will
1467         // belong to the soap body
1468         if (bodyParts == null) {
1469             bodyParts = new ArrayList<MessagePart>();
1470             for (Iterator<MessagePart> iter = message.parts(); iter.hasNext();) {
1471                 MessagePart mPart = iter.next();
1472                 //Its a safe assumption that the parts in the message not belonging to header or mime will
1473                 // belong to the body?
1474                 if (mimeParts.contains(mPart) || headerParts.contains(mPart) || boundToFault(mPart.getName())) {
1475                     //throw error that a part cant be bound multiple times, not ignoring operation, if there
1476                     //is conflict it will fail latter
1477                     if (options.isExtensionMode()) {
1478                         warning(mPart, ModelerMessages.WSDLMODELER_WARNING_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1479                     } else {
1480                         error(mPart, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1481                     }
1482                 }
1483                 bodyParts.add(mPart);
1484             }
1485         }
1486 
1487         //now build the final parts list with header, mime parts and body parts
1488         for (Iterator iter = message.parts(); iter.hasNext();) {
1489             MessagePart mPart = (MessagePart) iter.next();
1490             if (mimeParts.contains(mPart)) {
1491                 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);

1492             } else if (headerParts.contains(mPart)) {
1493                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);

1494             } else if (bodyParts.contains(mPart)) {
1495                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);

1496             } else {
1497                 mPart.setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
1498             }
1499         }
1500 
1501         if (isOperationDocumentLiteral(styleAndUse) && bodyParts.size() > 1) {
1502             if (options.isExtensionMode()) {
1503                 warning(message, ModelerMessages.WSDLMODELER_WARNING_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
1504             } else {
1505                 error(message, ModelerMessages.WSDLMODELER_INVALID_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
1506             }
1507             return false;
1508         }
1509         return true;
1510     }
1511 
1512     private boolean boundToFault(String partName) {
1513         for (BindingFault bindingFault : info.bindingOperation.faults()) {
1514             if (partName.equals(bindingFault.getName())) {
1515                 return true;
1516             }
1517         }
1518         return false;
1519     }
1520 
1521     //get MessagePart(s) referenced by parts attribute of soap:body element
1522     private List<MessagePart> getBodyParts(SOAPBody body, Message message) {
1523         String bodyParts = body.getParts();
1524         if (bodyParts != null) {
1525             List<MessagePart> partsList = new ArrayList<MessagePart>();
1526             StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
1527             while (in.hasMoreTokens()) {
1528                 String part = in.nextToken();
1529                 MessagePart mPart = message.getPart(part);
1530                 if (null == mPart) {
1531                     error(message, ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(part, message.getName()));
1532                 }
1533                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1534                 partsList.add(mPart);
1535             }
1536             return partsList;
1537         }
1538         return null;
1539     }
1540 
1541     List<MessagePart> getAdditionHeaderParts(BindingOperation bindingOperation,Message message, boolean isInput){
1542         List<MessagePart> headerParts = new ArrayList<MessagePart>();
1543         List<MessagePart> parts = message.getParts();
1544         List<MessagePart> headers = getHeaderParts(bindingOperation, isInput);
1545 
1546         for(MessagePart part: headers){
1547             if (parts.contains(part)) {
1548                 continue;
1549             }
1550             headerParts.add(part);
1551         }
1552         return headerParts;
1553     }
1554 
1555     private List<MessagePart> getHeaderPartsFromMessage(Message message, boolean isInput) {
1556         List<MessagePart> headerParts = new ArrayList<MessagePart>();
1557         Iterator<MessagePart> parts = message.parts();
1558         List<MessagePart> headers = getHeaderParts(info.bindingOperation, isInput);
1559         while (parts.hasNext()) {
1560             MessagePart part = parts.next();
1561             if (headers.contains(part)) {
1562                 headerParts.add(part);
1563             }
1564         }
1565         return headerParts;
1566     }
1567 
1568     private Message getHeaderMessage(MessagePart part, TWSDLExtensible ext) {
1569         Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1570         while (headers.hasNext()) {
1571             SOAPHeader header = headers.next();
1572             if (!header.isLiteral()) {
1573                 continue;
1574             }
1575             com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(), document);
1576             if (headerMessage == null) {
1577                 continue;
1578             }
1579 
1580             MessagePart headerPart = headerMessage.getPart(header.getPart());
1581             if (headerPart == part) {
1582                 return headerMessage;
1583             }
1584         }
1585         return null;
1586     }
1587 
1588     private List<MessagePart> getHeaderParts(BindingOperation bindingOperation, boolean isInput) {
1589         TWSDLExtensible ext;
1590         if (isInput) {
1591             ext = bindingOperation.getInput();
1592         } else {
1593             ext = bindingOperation.getOutput();
1594         }
1595 
1596         List<MessagePart> parts = new ArrayList<MessagePart>();
1597         Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1598         while (headers.hasNext()) {
1599             SOAPHeader header = headers.next();
1600             if (!header.isLiteral()) {
1601                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_LITERAL(header.getPart(), bindingOperation.getName()));
1602             }
1603 
1604             if (header.getNamespace() != null) {
1605                 warning(header, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:header", bindingOperation.getName()));
1606             }
1607             com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(),document);
1608             if (headerMessage == null) {
1609                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_CANT_RESOLVE_MESSAGE(header.getMessage(), bindingOperation.getName()));
1610             }
1611 
1612             MessagePart part = headerMessage.getPart(header.getPart());
1613             if (part == null) {
1614                 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_FOUND(header.getPart(), bindingOperation.getName()));
1615             }
1616             if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1617                 if (options.isExtensionMode()) {
1618                     warning(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
1619                 } else {
1620                     error(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
1621                 }
1622             }
1623             part.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1624             parts.add(part);
1625         }
1626         return parts;
1627     }
1628 
1629     private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
1630         return StyleAndUse.DOC_LITERAL == styleAndUse;
1631     }
1632 
1633     private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
1634         return StyleAndUse.RPC_LITERAL == styleAndUse;
1635     }
1636 
1637     /**
1638      * @param part
1639      * @return Returns a JAXBType object
1640      */
1641     private JAXBType getJAXBType(MessagePart part) {
1642         JAXBType type;
1643         QName name = part.getDescriptor();
1644         if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
1645             type = getJAXBModelBuilder().getJAXBType(name);
1646             if(type == null){
1647                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1648             }
1649         } else {
1650             S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
1651             TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
1652             if (typeAnno == null) {
1653                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1654             }
1655             JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno));
1656             type = new JAXBType(new QName("", part.getName()), javaType);
1657         }
1658         return type;
1659     }
1660 
1661     private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
1662         if (parameterList.isEmpty()) {
1663             return new ArrayList<Parameter>();
1664         }
1665         List<Parameter> params = new ArrayList<Parameter>();
1666         Message inMsg = getInputMessage();
1667         Message outMsg = getOutputMessage();
1668         boolean unwrappable = isUnwrappable();
1669         List<Parameter> outParams = null;
1670         int pIndex = 0;
1671         for (MessagePart part : parameterList) {
1672             QName reqBodyName = part.getDescriptor();
1673             JAXBType jaxbType = getJAXBType(part);
1674             Block block = new Block(reqBodyName, jaxbType, part);
1675             if (unwrappable) {
1676                 //So build body and header blocks and set to request and response
1677                 JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
1678                 block = new Block(reqBodyName, jaxbStructType, part);
1679                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1680                     if (part.isIN()) {
1681                         req.addBodyBlock(block);
1682                     } else if (part.isOUT()) {
1683                         res.addBodyBlock(block);
1684                     } else if (part.isINOUT()) {
1685                         req.addBodyBlock(block);
1686                         res.addBodyBlock(block);
1687                     }
1688                 } else if (ModelerUtils.isUnbound(part)) {
1689                     if (part.isIN()) {
1690                         req.addUnboundBlock(block);
1691                     } else if (part.isOUT()) {
1692                         res.addUnboundBlock(block);
1693                     } else if (part.isINOUT()) {
1694                         req.addUnboundBlock(block);
1695                         res.addUnboundBlock(block);
1696                     }

1697                 }
1698                 if (part.isIN() || part.isINOUT()) {
1699                     params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1700                     int index = 0;
1701                     Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
1702                     for (Parameter param : params) {
1703                         param.setParameterIndex(index++);
1704                         param.setMode(mode);
1705                         setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
1706                     }
1707                 } else if (part.isOUT()) {
1708                     outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1709                     for (Parameter param : outParams) {
1710                         param.setMode(Mode.OUT);
1711                         setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
1712                     }
1713                 }
1714             } else {
1715                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1716                     if (part.isIN()) {


1773                         }
1774                     }
1775                 } else if (ModelerUtils.isUnbound(part)) {
1776                     if (part.isIN()) {
1777                         req.addUnboundBlock(block);
1778                     } else if (part.isOUT()) {
1779                         res.addUnboundBlock(block);
1780                     } else if (part.isINOUT()) {
1781                         req.addUnboundBlock(block);
1782                         res.addUnboundBlock(block);
1783                     }
1784                 }
1785                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
1786                 param.setMode(part.getMode());
1787                 if (part.isReturn()) {
1788                     param.setParameterIndex(-1);
1789                 } else {
1790                     param.setParameterIndex(pIndex++);
1791                 }
1792 
1793                 if (part.isIN()) {
1794                     setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, false);
1795                 } else if (outMsg != null) {
1796                     setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, false);
1797                 }
1798 
1799                 params.add(param);
1800             }
1801         }
1802         if (unwrappable && (outParams != null)) {
1803             int index = params.size();
1804             for (Parameter param : outParams) {
1805                 if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
1806                     param.setParameterIndex(-1);
1807                 } else {
1808                     Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
1809                     if ((inParam != null) && inParam.isIN()) {
1810                         QName inElementName = inParam.getType().getName();
1811                         QName outElementName = param.getType().getName();
1812                         String inJavaType = inParam.getTypeName();
1813                         String outJavaType = param.getTypeName();
1814                         TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
1815                         TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
1816                         QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
1817                         QName outRawTypeName = ModelerUtils.getRawTypeName(param);


1825                     }
1826                     if (outParams.size() == 1) {
1827                         param.setParameterIndex(-1);
1828                     } else {
1829                         param.setParameterIndex(index++);
1830                     }
1831                 }
1832                 params.add(param);
1833             }
1834         }
1835         return params;
1836     }
1837 
1838     private List<Parameter> getRpcLitParameters(Request req, Response res, Block reqBlock, Block resBlock, List<MessagePart> paramList) {
1839         List<Parameter> params = new ArrayList<Parameter>();
1840         Message inMsg = getInputMessage();
1841         Message outMsg = getOutputMessage();
1842         S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType()).getJaxbModel().getS2JJAXBModel();
1843         List<Parameter> inParams = ModelerUtils.createRpcLitParameters(inMsg, reqBlock, jaxbModel, errReceiver);
1844         List<Parameter> outParams = null;
1845         if (outMsg != null) {
1846             outParams = ModelerUtils.createRpcLitParameters(outMsg, resBlock, jaxbModel, errReceiver);
1847         }
1848 
1849         //create parameters for header and mime parts
1850         int index = 0;
1851         for (MessagePart part : paramList) {
1852             Parameter param = null;
1853             if (ModelerUtils.isBoundToSOAPBody(part)) {
1854                 if (part.isIN()) {
1855                     param = ModelerUtils.getParameter(part.getName(), inParams);
1856                 } else if (outParams != null) {
1857                     param = ModelerUtils.getParameter(part.getName(), outParams);
1858                 }
1859             } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1860                 QName headerName = part.getDescriptor();
1861                 JAXBType jaxbType = getJAXBType(part);
1862                 Block headerBlock = new Block(headerName, jaxbType, part);
1863                 param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1864                 if (part.isIN()) {
1865                     req.addHeaderBlock(headerBlock);
1866                 } else if (part.isOUT()) {
1867                     res.addHeaderBlock(headerBlock);
1868                 } else if (part.isINOUT()) {
1869                     req.addHeaderBlock(headerBlock);
1870                     res.addHeaderBlock(headerBlock);
1871                 }
1872             } else if (ModelerUtils.isBoundToMimeContent(part)) {
1873                 List<MIMEContent> mimeContents;
1874                 if (part.isIN() || part.isINOUT()) {
1875                     mimeContents = getMimeContents(info.bindingOperation.getInput(),
1876                             getInputMessage(), part.getName());
1877                 } else {
1878                     mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1879                             getOutputMessage(), part.getName());
1880                 }
1881 
1882                 JAXBType type = getAttachmentType(mimeContents, part);
1883                 //create Parameters in request or response
1884                 //Block mimeBlock = new Block(new QName(part.getName()), type);
1885                 Block mimeBlock = new Block(type.getName(), type, part);
1886                 param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
1887                 if (part.isIN()) {
1888                     req.addAttachmentBlock(mimeBlock);
1889                 } else if (part.isOUT()) {
1890                     res.addAttachmentBlock(mimeBlock);
1891                 } else if (part.isINOUT()) {
1892                     mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1893                             getOutputMessage(), part.getName());
1894                     JAXBType outJaxbType = getAttachmentType(mimeContents, part);
1895 
1896                     String inType = type.getJavaType().getType().getName();
1897                     String outType = outJaxbType.getJavaType().getType().getName();
1898                     if (!inType.equals(outType)) {
1899                         String javaType = "javax.activation.DataHandler";
1900                         JType jt = options.getCodeModel().ref(javaType);


1912                     req.addUnboundBlock(unboundBlock);
1913                 } else if (part.isOUT()) {
1914                     res.addUnboundBlock(unboundBlock);
1915                 } else if (part.isINOUT()) {
1916                     req.addUnboundBlock(unboundBlock);
1917                     res.addUnboundBlock(unboundBlock);
1918                 }
1919                 param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
1920             }
1921             if (param != null) {
1922                 if (part.isReturn()) {
1923                     param.setParameterIndex(-1);
1924                 } else {
1925                     param.setParameterIndex(index++);
1926                 }
1927                 param.setMode(part.getMode());
1928                 params.add(param);
1929             }
1930         }
1931         for (Parameter param : params) {
1932             if (param.isIN()) {
1933                 setCustomizedParameterName(info.portTypeOperation, inMsg, inMsg.getPart(param.getName()), param, false);
1934             } else if (outMsg != null) {
1935                 setCustomizedParameterName(info.portTypeOperation, outMsg, outMsg.getPart(param.getName()), param, false);
1936             }
1937         }
1938         return params;
1939     }
1940 
1941     private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
1942         Message inputMessage = getInputMessage();
1943         //there is no input message, return zero parameters
1944         if (inputMessage != null && !inputMessage.parts().hasNext()) {
1945             return new ArrayList<Parameter>();
1946         }
1947 
1948         List<Parameter> inParameters = null;
1949         QName reqBodyName;
1950         Block reqBlock;
1951         JAXBType jaxbReqType;
1952         boolean unwrappable = isUnwrappable();
1953         boolean doneSOAPBody = false;
1954         //setup request parameters
1955         for (String inParamName : parameterList) {
1956             MessagePart part = inputMessage.getPart(inParamName);
1957             if (part == null) {
1958                 continue;
1959             }
1960             reqBodyName = part.getDescriptor();
1961             jaxbReqType = getJAXBType(part);
1962             if (unwrappable) {
1963                 //So build body and header blocks and set to request and response
1964                 JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
1965                 reqBlock = new Block(reqBodyName, jaxbRequestType, part);
1966                 if (ModelerUtils.isBoundToSOAPBody(part)) {
1967                     request.addBodyBlock(reqBlock);
1968                 } else if (ModelerUtils.isUnbound(part)) {
1969                     request.addUnboundBlock(reqBlock);
1970                 }
1971                 inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
1972                 for (Parameter param : inParameters) {
1973                     setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
1974                 }
1975             } else {
1976                 reqBlock = new Block(reqBodyName, jaxbReqType, part);
1977                 if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
1978                     doneSOAPBody = true;
1979                     request.addBodyBlock(reqBlock);
1980                 } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1981                     request.addHeaderBlock(reqBlock);
1982                 } else if (ModelerUtils.isBoundToMimeContent(part)) {
1983                     List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
1984                             getInputMessage(), part.getName());
1985                     jaxbReqType = getAttachmentType(mimeContents, part);
1986                     //reqBlock = new Block(new QName(part.getName()), jaxbReqType);
1987                     reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
1988                     request.addAttachmentBlock(reqBlock);
1989                 } else if (ModelerUtils.isUnbound(part)) {
1990                     request.addUnboundBlock(reqBlock);
1991                 }
1992                 if (inParameters == null) {
1993                     inParameters = new ArrayList<Parameter>();
1994                 }
1995                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
1996                 setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
1997                 inParameters.add(param);
1998             }
1999         }
2000         return inParameters;
2001     }
2002 
2003     /**
2004      * @param part
2005      * @param param
2006      * @param wrapperStyle TODO
2007      */
2008     private void setCustomizedParameterName(TWSDLExtensible extension, Message msg, MessagePart part, Parameter param, boolean wrapperStyle) {
2009         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(extension, JAXWSBinding.class);
2010         if (jaxwsBinding == null) {
2011             return;
2012         }
2013         String paramName = part.getName();
2014         QName elementName = part.getDescriptor();
2015         if (wrapperStyle) {
2016             elementName = param.getType().getName();
2017         }
2018         String customName = jaxwsBinding.getParameterName(msg.getName(), paramName, elementName, wrapperStyle);
2019         if (customName != null && !customName.equals("")) {
2020             param.setCustomName(customName);
2021         }
2022     }
2023 
2024     @Override
2025     protected boolean isConflictingPortClassName(String name) {
2026         return false;
2027     }
2028 
2029     protected boolean isUnwrappable() {
2030         if (!getWrapperStyleCustomization()) {
2031             return false;
2032         }
2033 
2034         com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2035         com.sun.tools.internal.ws.wsdl.document.Message outputMessage = getOutputMessage();
2036 
2037         // Wrapper style if the operation's input and output messages each contain
2038         // only a single part
2039         if ((inputMessage != null && inputMessage.numParts() != 1)
2040                 || (outputMessage != null && outputMessage.numParts() != 1)) {
2041             return false;
2042         }
2043 
2044         MessagePart inputPart = inputMessage != null
2045                 ? inputMessage.parts().next() : null;
2046         MessagePart outputPart = outputMessage != null
2047                 ? outputMessage.parts().next() : null;
2048         String operationName = info.portTypeOperation.getName();
2049 
2050         // Wrapper style if the input message part refers to a global element declaration whose localname
2051         // is equal to the operation name
2052         // Wrapper style if the output message part refers to a global element declaration
2053         if ((inputPart != null && !inputPart.getDescriptor().getLocalPart().equals(operationName)) ||
2054                 (outputPart != null && outputPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT)) {
2055             return false;
2056         }
2057 
2058         //check to see if either input or output message part not bound to soapbing:body
2059         //in that case the operation is not wrapper style
2060         if (((inputPart != null) && (inputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)) ||
2061                 ((outputPart != null) && (outputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING))) {
2062             return false;
2063         }
2064 
2065         // Wrapper style if the elements referred to by the input and output message parts
2066         // (henceforth referred to as wrapper elements) are both complex types defined
2067         // using the xsd:sequence compositor
2068         // Wrapper style if the wrapper elements only contain child elements, they must not
2069         // contain other structures such as xsd:choice, substitution groups1 or attributes
2070         //These checkins are done by jaxb, we just check if jaxb has wrapper children. If there
2071         // are then its wrapper style
2072         //if(inputPart != null && outputPart != null){
2073         if (inputPart != null) {
2074             boolean inputWrappable = false;
2075             JAXBType inputType = getJAXBType(inputPart);
2076             if (inputType != null) {
2077                 inputWrappable = inputType.isUnwrappable();
2078             }
2079             //if there are no output part (oneway), the operation can still be wrapper style
2080             if (outputPart == null) {
2081                 return inputWrappable;
2082             }
2083             JAXBType outputType = getJAXBType(outputPart);
2084             if ((inputType != null) && (outputType != null)) {
2085                 return inputType.isUnwrappable() && outputType.isUnwrappable();
2086             }
2087         }
2088 
2089         return false;
2090     }
2091 
2092     private boolean getWrapperStyleCustomization() {
2093         //first we look into wsdl:portType/wsdl:operation
2094         com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
2095         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeOperation, JAXWSBinding.class);
2096         if (jaxwsBinding != null) {
2097             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2098             if (isWrappable != null) {
2099                 return isWrappable;
2100             }
2101         }
2102 
2103         //then into wsdl:portType
2104         PortType portType = info.port.resolveBinding(document).resolvePortType(document);
2105         jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2106         if (jaxwsBinding != null) {
2107             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2108             if (isWrappable != null) {
2109                 return isWrappable;
2110             }
2111         }
2112 
2113         //then wsdl:definitions
2114         jaxwsBinding = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2115         if (jaxwsBinding != null) {
2116             Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2117             if (isWrappable != null) {
2118                 return isWrappable;
2119             }
2120         }
2121         return true;
2122     }
2123 
2124     /* (non-Javadoc)
2125      * @see WSDLModelerBase#isSingleInOutPart(Set, MessagePart)
2126      */
2127     protected boolean isSingleInOutPart(Set inputParameterNames,
2128                                         MessagePart outputPart) {
2129         // As of now, we dont have support for in/out in doc-lit. So return false.
2130         SOAPOperation soapOperation =
2131                 (SOAPOperation) getExtensionOfType(info.bindingOperation,
2132                         SOAPOperation.class);
2133         if ((soapOperation != null) && (soapOperation.isDocument() || info.soapBinding.isDocument())) {
2134             Iterator iter = getInputMessage().parts();
2135             while (iter.hasNext()) {
2136                 MessagePart part = (MessagePart) iter.next();
2137                 if (outputPart.getName().equals(part.getName()) && outputPart.getDescriptor().equals(part.getDescriptor())) {
2138                     return true;
2139                 }
2140             }
2141         } else if (soapOperation != null && soapOperation.isRPC() || info.soapBinding.isRPC()) {
2142             com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2143             if (inputParameterNames.contains(outputPart.getName())) {
2144                 if (inputMessage.getPart(outputPart.getName()).getDescriptor().equals(outputPart.getDescriptor())) {
2145                     return true;
2146                 }
2147             }
2148         }
2149         return false;
2150     }
2151 
2152     private List<Parameter> createRpcLitRequestParameters(Request request, List<String> parameterList, Block block) {
2153         Message message = getInputMessage();
2154         S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType()).getJaxbModel().getS2JJAXBModel();
2155         List<Parameter> parameters = ModelerUtils.createRpcLitParameters(message, block, jaxbModel, errReceiver);
2156 
2157         //create parameters for header and mime parts
2158         for (String paramName : parameterList) {
2159             MessagePart part = message.getPart(paramName);
2160             if (part == null) {
2161                 continue;
2162             }
2163             if (ModelerUtils.isBoundToSOAPHeader(part)) {
2164                 if (parameters == null) {
2165                     parameters = new ArrayList<Parameter>();
2166                 }
2167                 QName headerName = part.getDescriptor();
2168                 JAXBType jaxbType = getJAXBType(part);
2169                 Block headerBlock = new Block(headerName, jaxbType, part);
2170                 request.addHeaderBlock(headerBlock);
2171                 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
2172                 if (param != null) {
2173                     parameters.add(param);
2174                 }
2175             } else if (ModelerUtils.isBoundToMimeContent(part)) {
2176                 if (parameters == null) {
2177                     parameters = new ArrayList<Parameter>();
2178                 }
2179                 List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
2180                         getInputMessage(), paramName);
2181 
2182                 JAXBType type = getAttachmentType(mimeContents, part);
2183                 //create Parameters in request or response
2184                 //Block mimeBlock = new Block(new QName(part.getName()), type);
2185                 Block mimeBlock = new Block(type.getName(), type, part);
2186                 request.addAttachmentBlock(mimeBlock);
2187                 Parameter param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
2188                 if (param != null) {
2189                     parameters.add(param);
2190                 }
2191             } else if (ModelerUtils.isUnbound(part)) {
2192                 if (parameters == null) {
2193                     parameters = new ArrayList<Parameter>();
2194                 }
2195                 QName name = part.getDescriptor();
2196                 JAXBType type = getJAXBType(part);
2197                 Block unboundBlock = new Block(name, type, part);
2198                 request.addUnboundBlock(unboundBlock);
2199                 Parameter param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
2200                 if (param != null) {
2201                     parameters.add(param);
2202                 }
2203             }
2204         }
2205         for (Parameter param : parameters) {
2206             setCustomizedParameterName(info.portTypeOperation, message, message.getPart(param.getName()), param, false);
2207         }
2208         return parameters;
2209     }
2210 
2211     private String getJavaTypeForMimeType(String mimeType) {
2212         if (mimeType.equals("image/jpeg") || mimeType.equals("image/gif")) {
2213             return "java.awt.Image";
2214         } else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) {


2225         List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
2226         if (mimeTypes.size() > 1) {
2227             javaType = "javax.activation.DataHandler";
2228         } else {
2229             javaType = getJavaTypeForMimeType(mimeTypes.get(0));
2230         }
2231 
2232         S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
2233         JType jt = options.getCodeModel().ref(javaType);
2234         QName desc = part.getDescriptor();
2235         TypeAndAnnotation typeAnno = null;
2236 
2237         if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
2238             typeAnno = jaxbModel.getJavaType(desc);
2239             desc = new QName("", part.getName());
2240         } else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
2241             typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
2242             if(typeAnno == null){
2243                 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part.getDescriptor(), part.getName()));
2244             }
2245             for (String mimeType : mimeTypes) {
2246                 if ((!mimeType.equals("text/xml") && !mimeType.equals("application/xml"))) {


2247                     //According to AP 1.0,
2248                     //RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
2249                     //global element declaration (via the element attribute of the wsdl:part
2250                     //element) then the value of the type attribute of a mime:content element
2251                     //that binds that part MUST be a content type suitable for carrying an
2252                     //XML serialization.
2253                     //should we throw warning?
2254                     //type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
2255                     warning(part, ModelerMessages.MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(part.getName(), mimeType));
2256                 }
2257             }
2258         }
2259         if (typeAnno == null) {
2260             error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part.getName()));
2261         }
2262         return new JAXBType(desc, new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno, jt)),
2263                 null, getJAXBModelBuilder().getJAXBModel());
2264     }
2265 
2266     protected void buildJAXBModel(WSDLDocument wsdlDocument) {
2267         JAXBModelBuilder tempJaxbModelBuilder = new JAXBModelBuilder(options, classNameCollector, forest, errReceiver);
2268         //set the java package where wsdl artifacts will be generated
2269         //if user provided package name  using -p switch (or package property on wsimport ant task)
2270         //ignore the package customization in the wsdl and schema bidnings
2271         //formce the -p option only in the first pass
2272         if (explicitDefaultPackage != null) {
2273             tempJaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(options.defaultPackage);
2274         } else {
2275             options.defaultPackage = getJavaPackage();
2276         }
2277 
2278         //create pseudo schema for async operations(if any) response bean
2279         List<InputSource> schemas = PseudoSchemaBuilder.build(this, options, errReceiver);
2280         for (InputSource schema : schemas) {
2281             tempJaxbModelBuilder.getJAXBSchemaCompiler().parseSchema(schema);
2282         }
2283         tempJaxbModelBuilder.bind();
2284         this.jaxbModelBuilder = tempJaxbModelBuilder;
2285     }
2286 
2287     protected String getJavaPackage() {
2288         String jaxwsPackage = null;
2289         JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2290         if (jaxwsCustomization != null && jaxwsCustomization.getJaxwsPackage() != null) {
2291             jaxwsPackage = jaxwsCustomization.getJaxwsPackage().getName();
2292         }
2293         if (jaxwsPackage != null) {
2294             return jaxwsPackage;
2295         }
2296         String wsdlUri = document.getDefinitions().getTargetNamespaceURI();
2297         return XJC.getDefaultPackageName(wsdlUri);
2298 
2299     }
2300 
2301     protected void createJavaInterfaceForProviderPort(Port port) {
2302         String interfaceName = "javax.xml.ws.Provider";
2303         JavaInterface intf = new JavaInterface(interfaceName);
2304         port.setJavaInterface(intf);


2307     protected void createJavaInterfaceForPort(Port port, boolean isProvider) {
2308         if (isProvider) {
2309             createJavaInterfaceForProviderPort(port);
2310             return;
2311         }
2312         String interfaceName = getJavaNameOfSEI(port);
2313 
2314         if (isConflictingPortClassName(interfaceName)) {
2315             interfaceName += "_PortType";
2316         }
2317 
2318         JavaInterface intf = new JavaInterface(interfaceName);
2319         for (Operation operation : port.getOperations()) {
2320             createJavaMethodForOperation(
2321                     port,
2322                     operation,
2323                     intf);
2324 
2325             for (JavaParameter jParam : operation.getJavaMethod().getParametersList()) {
2326                 Parameter param = jParam.getParameter();
2327                 if (param.getCustomName() != null) {
2328                     jParam.setName(param.getCustomName());
2329                 }
2330             }
2331         }
2332 
2333         port.setJavaInterface(intf);
2334     }
2335 
2336     protected String getServiceInterfaceName(QName serviceQName, com.sun.tools.internal.ws.wsdl.document.Service wsdlService) {
2337         String serviceName = wsdlService.getName();
2338         JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(wsdlService, JAXWSBinding.class);
2339         if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2340             CustomName name = jaxwsCust.getClassName();
2341             if (name != null && !name.getName().equals("")) {
2342                 return makePackageQualified(name.getName());
2343             }
2344         }
2345         return makePackageQualified(BindingHelper.mangleNameToClassName(serviceName));
2346     }
2347 
2348     protected String getJavaNameOfSEI(Port port) {
2349         QName portTypeName =
2350                 (QName) port.getProperty(
2351                         ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
2352         PortType pt = (PortType) document.find(Kinds.PORT_TYPE, portTypeName);
2353         //populate the portType map here. We should get rid of all these properties
2354         // lets not do it as it may break NB
2355         //TODO: clean all these stuff part of NB RFE
2356         port.portTypes.put(portTypeName, pt);
2357         JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt, JAXWSBinding.class);
2358         if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2359             CustomName name = jaxwsCust.getClassName();
2360             if (name != null && !name.getName().equals("")) {
2361                 return makePackageQualified(name.getName());
2362             }
2363         }
2364 
2365         String interfaceName;
2366         if (portTypeName != null) {
2367             // got portType information from WSDL, use it to name the interface
2368             interfaceName =
2369                     makePackageQualified(BindingHelper.mangleNameToClassName(portTypeName.getLocalPart()));
2370         } else {
2371             // somehow we only got the port name, so we use that
2372             interfaceName =
2373                     makePackageQualified(BindingHelper.mangleNameToClassName(port.getName().getLocalPart()));
2374         }
2375         return interfaceName;
2376     }
2377 
2378     private void createJavaMethodForAsyncOperation(Port port, Operation operation,
2379                                                    JavaInterface intf) {
2380         String candidateName = getJavaNameForOperation(operation);
2381         JavaMethod method = new JavaMethod(candidateName, options, errReceiver);






2382 
2383         assert (operation.getRequest() != null);
2384         Response response = operation.getResponse();









2385 
2386         // build a signature of the form "opName%arg1type%arg2type%...%argntype so that we
2387         // detect overloading conflicts in the generated java interface/classes
2388         for (Iterator iter = operation.getRequest().getParameters(); iter.hasNext();) {

2389             Parameter parameter = (Parameter) iter.next();
2390 
2391             if (parameter.getJavaParameter() != null) {
2392                 error(operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION(operation.getName().getLocalPart()));
2393             }
2394 
2395             JavaType parameterType = parameter.getType().getJavaType();
2396             JavaParameter javaParameter =
2397                     new JavaParameter(
2398                                 BindingHelper.mangleNameToVariableName(parameter.getName()),
2399                             parameterType,
2400                             parameter,
2401                             parameter.getLinkedParameter() != null);
2402             if (javaParameter.isHolder()) {
2403                 javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
2404             }
2405             method.addParameter(javaParameter);
2406             parameter.setJavaParameter(javaParameter);
2407 

2408         }
2409 
2410         if (response != null) {
2411             String resultParameterName =
2412                     (String) operation.getProperty(WSDL_RESULT_PARAMETER);
2413             Parameter resultParameter =
2414                     response.getParameterByName(resultParameterName);
2415             JavaType returnType = resultParameter.getType().getJavaType();
2416             method.setReturnType(returnType);
2417 
2418         }
2419         operation.setJavaMethod(method);
2420         intf.addMethod(method);
2421     }
2422 
2423     /* (non-Javadoc)
2424      * @see WSDLModelerBase#createJavaMethodForOperation(WSDLPort, WSDLOperation, JavaInterface, Set, Set)
2425      */
2426     protected void createJavaMethodForOperation(Port port, Operation operation, JavaInterface intf) {
2427         if ((operation instanceof AsyncOperation)) {
2428             createJavaMethodForAsyncOperation(port, operation, intf);
2429             return;
2430         }
2431         String candidateName = getJavaNameForOperation(operation);
2432         JavaMethod method = new JavaMethod(candidateName, options, errReceiver);

2433         Parameter returnParam = (Parameter) operation.getProperty(WSDL_RESULT_PARAMETER);
2434         if (returnParam != null) {
2435             JavaType parameterType = returnParam.getType().getJavaType();
2436             method.setReturnType(parameterType);
2437         } else {
2438             method.setReturnType(JavaSimpleTypeCreator.VOID_JAVATYPE);
2439         }
2440         List<Parameter> parameterOrder = (List<Parameter>) operation.getProperty(WSDL_PARAMETER_ORDER);
2441         for (Parameter param : parameterOrder) {
2442             JavaType parameterType = param.getType().getJavaType();
2443             String name = (param.getCustomName() != null) ? param.getCustomName() : param.getName();
2444             name = BindingHelper.mangleNameToVariableName(name);
2445             //if its a java keyword after name mangling, then we simply put underscore as there is no
2446             //need to ask user to customize the parameter name if its java keyword
2447             if(Names.isJavaReservedWord(name)){
2448                 name = "_"+name;
2449             }
2450             JavaParameter javaParameter =
2451                     new JavaParameter(
2452                             name,


2536 
2537     protected boolean isRequestResponse() {
2538         return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
2539     }
2540 
2541     protected java.util.List<String> getAsynParameterOrder() {
2542         //for async operation ignore the parameterOrder
2543         java.util.List<String> parameterList = new ArrayList<String>();
2544         Message inputMessage = getInputMessage();
2545         List<MessagePart> inputParts = inputMessage.getParts();
2546         for (MessagePart part : inputParts) {
2547             parameterList.add(part.getName());
2548         }
2549         return parameterList;
2550     }
2551 
2552 
2553     protected List<MessagePart> getParameterOrder() {
2554         List<MessagePart> params = new ArrayList<MessagePart>();
2555         String parameterOrder = info.portTypeOperation.getParameterOrder();
2556         java.util.List<String> parameterList;
2557         boolean parameterOrderPresent = false;
2558         if ((parameterOrder != null) && !(parameterOrder.trim().equals(""))) {
2559             parameterList = XmlUtil.parseTokenList(parameterOrder);
2560             parameterOrderPresent = true;
2561         } else {
2562             parameterList = new ArrayList<String>();
2563         }
2564         Message inputMessage = getInputMessage();
2565         Message outputMessage = getOutputMessage();
2566         List<MessagePart> outputParts = null;
2567         List<MessagePart> inputParts = inputMessage.getParts();
2568         //reset the mode and ret flag, as MEssagePArts aer shared across ports
2569         for (MessagePart part : inputParts) {
2570             part.setMode(Mode.IN);
2571             part.setReturn(false);
2572         }
2573         if (isRequestResponse()) {
2574             outputParts = outputMessage.getParts();
2575             for (MessagePart part : outputParts) {
2576                 part.setMode(Mode.OUT);


2658                         MessagePart resultPart = outputUnlistedParts.get(0);
2659                         resultPart.setReturn(true);
2660                         params.add(resultPart);
2661                         outputUnlistedParts.clear();
2662                     }
2663                 }
2664 
2665                 //add the input and output unlisted parts
2666                 for (MessagePart part : inputUnlistedParts) {
2667                     params.add(part);
2668                 }
2669 
2670                 for (MessagePart part : outputUnlistedParts) {
2671                     params.add(part);
2672                 }
2673                 return params;
2674 
2675             }
2676             //parameterOrder attribute is not valid, we ignore it
2677             warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETER_ORDER_INVALID_PARAMETER_ORDER(info.operation.getName().getLocalPart()));

2678             parameterList.clear();
2679         }
2680 
2681         List<MessagePart> outParts = new ArrayList<MessagePart>();
2682 
2683         //construct input parameter list with the same order as in input message
2684         for (MessagePart part : inputParts) {
2685             params.add(part);
2686         }
2687 
2688         if (isRequestResponse()) {
2689             for (MessagePart part : outputParts) {
2690                 MessagePart inPart = inputMessage.getPart(part.getName());
2691                 if (inPart != null && part.getDescriptorKind() == inPart.getDescriptorKind() &&
2692                         part.getDescriptor().equals(inPart.getDescriptor())) {
2693                     inPart.setMode(Mode.INOUT);
2694                     continue;
2695                 }
2696                 outParts.add(part);
2697             }
2698 
2699             //append the out parts to the parameterList
2700             for (MessagePart part : outParts) {
2701                 if (outParts.size() == 1) {
2702                     part.setReturn(true);
2703                 }
2704                 params.add(part);
2705             }
2706         }
2707         return params;
2708     }
2709 
2710     /**
2711      * @param port
2712      * @param suffix
2713      * @return the Java ClassName for a port
2714      */
2715     protected String getClassName(Port port, String suffix) {
2716         String prefix = BindingHelper.mangleNameToClassName((port.getName().getLocalPart()));
2717         return options.defaultPackage + "." + prefix + suffix;
2718     }
2719 
2720     @Override
2721     protected boolean isConflictingServiceClassName(String name) {
2722         return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name) || conflictsWithExceptionClass(name);
2723     }
2724 
2725     private boolean conflictsWithSEIClass(String name) {
2726         Set<String> seiNames = classNameCollector.getSeiClassNames();
2727         return seiNames != null && seiNames.contains(name);
2728     }
2729 
2730     private boolean conflictsWithJAXBClass(String name) {
2731         Set<String> jaxbNames = classNameCollector.getJaxbGeneratedClassNames();
2732         return jaxbNames != null && jaxbNames.contains(name);
2733     }
2734 
2735     private boolean conflictsWithExceptionClass(String name) {
2736         Set<String> exceptionNames = classNameCollector.getExceptionClassNames();
2737         return exceptionNames != null && exceptionNames.contains(name);
2738     }
2739 
2740     @Override
2741     protected boolean isConflictingExceptionClassName(String name) {
2742         return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name);
2743     }
2744 
2745     protected JAXBModelBuilder getJAXBModelBuilder() {
2746         return jaxbModelBuilder;
2747     }
2748 
2749     protected boolean validateWSDLBindingStyle(Binding binding) {
2750         SOAPBinding soapBinding =
2751                 (SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
2752 
2753         //dont process the binding
2754         if (soapBinding == null) {
2755             soapBinding = (SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
2756         }
2757         if (soapBinding == null) {
2758             return false;
2759         }
2760 
2761         //if soapbind:binding has no style attribute, the default is DOCUMENT
2762         if (soapBinding.getStyle() == null) {
2763             soapBinding.setStyle(SOAPStyle.DOCUMENT);
2764         }
2765 
2766         SOAPStyle opStyle = soapBinding.getStyle();
2767         for (Iterator iter = binding.operations(); iter.hasNext();) {
2768             BindingOperation bindingOperation =
2769                     (BindingOperation) iter.next();
2770             SOAPOperation soapOperation =
2771                     (SOAPOperation) getExtensionOfType(bindingOperation,
2772                             SOAPOperation.class);
2773             if (soapOperation != null) {
2774                 SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation.getStyle() : soapBinding.getStyle();
2775                 //dont check for the first operation
2776                 if (!currOpStyle.equals(opStyle)) {
2777                     return false;
2778                 }
2779             }
2780         }
2781         return true;
2782     }
2783 
2784     /**
2785      * @param port
2786      */
2787     private void applyWrapperStyleCustomization(Port port, PortType portType) {
2788         JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2789         Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding.isEnableWrapperStyle() : null;
2790         if (wrapperStyle != null) {
2791             port.setWrapped(wrapperStyle);
2792         }
2793     }
2794 
2795     protected static void setDocumentationIfPresent(
2796             ModelObject obj,
2797             Documentation documentation) {
2798         if (documentation != null && documentation.getContent() != null) {