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.tools.internal.ws.api.wsdl.TWSDLExtensible;
  29 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
  30 import com.sun.tools.internal.ws.processor.generator.Names;
  31 import com.sun.tools.internal.ws.processor.model.Fault;
  32 import com.sun.tools.internal.ws.processor.model.Operation;
  33 import com.sun.tools.internal.ws.processor.model.Port;
  34 import com.sun.tools.internal.ws.processor.model.java.JavaException;
  35 import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
  36 import com.sun.tools.internal.ws.processor.modeler.Modeler;
  37 import com.sun.tools.internal.ws.resources.ModelerMessages;
  38 import com.sun.tools.internal.ws.wscompile.AbortException;
  39 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
  40 import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter;
  41 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
  42 import com.sun.tools.internal.ws.wsdl.document.*;
  43 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
  44 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
  45 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEMultipartRelated;
  46 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEPart;
  47 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
  48 import com.sun.tools.internal.ws.wsdl.document.soap.*;
  49 import com.sun.tools.internal.ws.wsdl.framework.Entity;
  50 import com.sun.tools.internal.ws.wsdl.framework.GloballyKnown;
  51 import com.sun.tools.internal.ws.wsdl.framework.NoSuchEntityException;
  52 import com.sun.tools.internal.ws.wsdl.parser.DOMForest;
  53 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
  54 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
  55 import com.sun.xml.internal.ws.spi.db.BindingContext;
  56 import com.sun.xml.internal.ws.spi.db.BindingHelper;
  57 
  58 import org.xml.sax.helpers.LocatorImpl;
  59 
  60 import javax.xml.namespace.QName;
  61 import java.util.*;
  62 
  63 /**
  64  *
  65  * @author WS Development Team
  66  *
  67  * Base class for WSDL->Model classes.
  68  */
  69 public abstract class WSDLModelerBase implements Modeler {
  70     protected final ErrorReceiverFilter errReceiver;
  71     protected final WsimportOptions options;
  72     protected MetadataFinder forest;
  73 
  74 
  75     public WSDLModelerBase(WsimportOptions options, ErrorReceiver receiver, MetadataFinder forest) {
  76         this.options = options;
  77         this.errReceiver = new ErrorReceiverFilter(receiver);
  78         this.forest = forest;
  79     }
  80 
  81     /**
  82      *
  83      * @param port
  84      * @param wsdlPort
  85      */
  86     protected void applyPortMethodCustomization(Port port, com.sun.tools.internal.ws.wsdl.document.Port wsdlPort) {
  87         if(isProvider(wsdlPort))
  88             return;
  89         JAXWSBinding jaxwsBinding = (JAXWSBinding)getExtensionOfType(wsdlPort, JAXWSBinding.class);
  90 
  91         String portMethodName = (jaxwsBinding != null)?((jaxwsBinding.getMethodName() != null)?jaxwsBinding.getMethodName().getName():null):null;
  92         if(portMethodName != null){
  93             port.setPortGetter(portMethodName);
  94         }else{
  95             portMethodName = Names.getPortName(port);
  96             portMethodName = BindingHelper.mangleNameToClassName(portMethodName);
  97             port.setPortGetter("get"+portMethodName);
  98         }
  99 
 100     }
 101 
 102     protected boolean isProvider(com.sun.tools.internal.ws.wsdl.document.Port wsdlPort){
 103         JAXWSBinding portCustomization = (JAXWSBinding)getExtensionOfType(wsdlPort, JAXWSBinding.class);
 104         Boolean isProvider = (portCustomization != null)?portCustomization.isProvider():null;
 105         if(isProvider != null){
 106             return isProvider;
 107         }
 108 
 109         JAXWSBinding jaxwsGlobalCustomization = (JAXWSBinding)getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
 110         isProvider = (jaxwsGlobalCustomization != null)?jaxwsGlobalCustomization.isProvider():null;
 111         if(isProvider != null)
 112             return isProvider;
 113         return false;
 114     }
 115 
 116     protected SOAPBody getSOAPRequestBody() {
 117         SOAPBody requestBody =
 118             (SOAPBody)getAnyExtensionOfType(info.bindingOperation.getInput(),
 119                 SOAPBody.class);
 120         if (requestBody == null) {
 121             // the WSDL document is invalid
 122             error(info.bindingOperation.getInput(), ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
 123         }
 124         return requestBody;
 125     }
 126 
 127     protected boolean isRequestMimeMultipart() {
 128         for (TWSDLExtension extension: info.bindingOperation.getInput().extensions()) {
 129             if (extension.getClass().equals(MIMEMultipartRelated.class)) {
 130                 return true;
 131             }
 132         }
 133         return false;
 134     }
 135 
 136     protected boolean isResponseMimeMultipart() {
 137         for (TWSDLExtension extension: info.bindingOperation.getOutput().extensions()) {
 138             if (extension.getClass().equals(MIMEMultipartRelated.class)) {
 139                 return true;
 140             }
 141         }
 142         return false;
 143     }
 144 
 145 
 146 
 147 
 148     protected SOAPBody getSOAPResponseBody() {
 149         SOAPBody responseBody =
 150             (SOAPBody)getAnyExtensionOfType(info.bindingOperation.getOutput(),
 151                 SOAPBody.class);
 152         if (responseBody == null) {
 153             // the WSDL document is invalid
 154             error(info.bindingOperation.getOutput(),  ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_OUTPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
 155         }
 156         return responseBody;
 157     }
 158 
 159     protected com.sun.tools.internal.ws.wsdl.document.Message getOutputMessage() {
 160         if (info.portTypeOperation.getOutput() == null)
 161             return null;
 162         return info.portTypeOperation.getOutput().resolveMessage(info.document);
 163     }
 164 
 165     protected com.sun.tools.internal.ws.wsdl.document.Message getInputMessage() {
 166         return info.portTypeOperation.getInput().resolveMessage(info.document);
 167     }
 168 
 169     /**
 170      * @param body request or response body, represents soap:body
 171      * @param message Input or output message, equivalent to wsdl:message
 172      * @return iterator over MessagePart
 173      */
 174     protected List<MessagePart> getMessageParts(
 175         SOAPBody body,
 176         com.sun.tools.internal.ws.wsdl.document.Message message, boolean isInput) {
 177         String bodyParts = body.getParts();
 178         ArrayList<MessagePart> partsList = new ArrayList<MessagePart>();
 179         List<MessagePart> parts = new ArrayList<MessagePart>();
 180 
 181         //get Mime parts
 182         List mimeParts;
 183         if(isInput)
 184             mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
 185         else
 186             mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
 187 
 188         if (bodyParts != null) {
 189             StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
 190             while (in.hasMoreTokens()) {
 191                 String part = in.nextToken();
 192                 MessagePart mPart = message.getPart(part);
 193                 if (null == mPart) {
 194                     error(message,  ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(part, message.getName()));
 195                 }
 196                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
 197                 partsList.add(mPart);
 198             }
 199         } else {
 200             for (MessagePart mPart : message.getParts()) {
 201                 if (!mimeParts.contains(mPart))
 202                     mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
 203                 partsList.add(mPart);
 204             }
 205         }
 206 
 207         for (MessagePart mPart : message.getParts()) {
 208             if(mimeParts.contains(mPart)) {
 209                 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
 210                 parts.add(mPart);
 211             }else if(partsList.contains(mPart)) {
 212                 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
 213                 parts.add(mPart);
 214             }
 215         }
 216 
 217         return parts;
 218     }
 219 
 220     /**
 221      * @param message
 222      * @return MessageParts referenced by the mime:content
 223      */
 224     protected List<MessagePart> getMimeContentParts(Message message, TWSDLExtensible ext) {
 225         ArrayList<MessagePart> mimeContentParts = new ArrayList<MessagePart>();
 226 
 227         for (MIMEPart mimePart : getMimeParts(ext)) {
 228             MessagePart part = getMimeContentPart(message, mimePart);
 229             if (part != null)
 230                 mimeContentParts.add(part);
 231         }
 232         return mimeContentParts;
 233     }
 234 
 235     /**
 236      * @param mimeParts
 237      */
 238     protected boolean validateMimeParts(Iterable<MIMEPart> mimeParts) {
 239         boolean gotRootPart = false;
 240         List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
 241         for (MIMEPart mPart : mimeParts) {
 242             for (TWSDLExtension obj : mPart.extensions()) {
 243                 if (obj instanceof SOAPBody) {
 244                     if (gotRootPart) {
 245                         warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_MORE_THAN_ONE_SOAP_BODY(info.operation.getName().getLocalPart()));
 246                         return false;
 247                     }
 248                     gotRootPart = true;
 249                 } else if (obj instanceof MIMEContent) {
 250                     mimeContents.add((MIMEContent) obj);
 251                 }
 252             }
 253             if(!validateMimeContentPartNames(mimeContents))
 254                 return false;
 255             if(mPart.getName() != null) {
 256                 warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_NAME_NOT_ALLOWED(info.portTypeOperation.getName()));
 257             }
 258         }
 259         return true;
 260 
 261     }
 262 
 263     private MessagePart getMimeContentPart(Message message, MIMEPart part) {
 264         for( MIMEContent mimeContent : getMimeContents(part) ) {
 265             String mimeContentPartName = mimeContent.getPart();
 266             MessagePart mPart = message.getPart(mimeContentPartName);
 267             //RXXXX mime:content MUST have part attribute
 268             if(null == mPart) {
 269                 error(mimeContent,  ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(mimeContentPartName, message.getName()));
 270             }
 271             mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
 272             return mPart;
 273         }
 274         return null;
 275     }
 276 
 277     //List of mimeTypes
 278     protected List<String> getAlternateMimeTypes(List<MIMEContent> mimeContents) {
 279         List<String> mimeTypes = new ArrayList<String>();
 280         //validateMimeContentPartNames(mimeContents.iterator());
 281 //        String mimeType = null;
 282         for(MIMEContent mimeContent:mimeContents){
 283             String mimeType = getMimeContentType(mimeContent);
 284             if(!mimeTypes.contains(mimeType))
 285                 mimeTypes.add(mimeType);
 286         }
 287         return mimeTypes;
 288     }
 289 
 290     private boolean validateMimeContentPartNames(List<MIMEContent> mimeContents) {
 291         //validate mime:content(s) in the mime:part as per R2909
 292         for (MIMEContent mimeContent : mimeContents) {
 293             String mimeContnetPart;
 294             mimeContnetPart = getMimeContentPartName(mimeContent);
 295             if(mimeContnetPart == null) {
 296                 warning(mimeContent, ModelerMessages.MIMEMODELER_INVALID_MIME_CONTENT_MISSING_PART_ATTRIBUTE(info.operation.getName().getLocalPart()));
 297                 return false;
 298             }
 299         }
 300         return true;
 301     }
 302 
 303     protected Iterable<MIMEPart> getMimeParts(TWSDLExtensible ext) {
 304         MIMEMultipartRelated multiPartRelated =
 305             (MIMEMultipartRelated) getAnyExtensionOfType(ext,
 306                     MIMEMultipartRelated.class);
 307         if(multiPartRelated == null) {
 308             return Collections.emptyList();
 309         }
 310         return multiPartRelated.getParts();
 311     }
 312 
 313     //returns MIMEContents
 314     protected List<MIMEContent> getMimeContents(MIMEPart part) {
 315         List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
 316         for (TWSDLExtension mimeContent : part.extensions()) {
 317             if (mimeContent instanceof MIMEContent) {
 318                 mimeContents.add((MIMEContent) mimeContent);
 319             }
 320         }
 321         //validateMimeContentPartNames(mimeContents.iterator());
 322         return mimeContents;
 323     }
 324 
 325     private String getMimeContentPartName(MIMEContent mimeContent){
 326         /*String partName = mimeContent.getPart();
 327         if(partName == null){
 328             throw new ModelerException("mimemodeler.invalidMimeContent.missingPartAttribute",
 329                     new Object[] {info.operation.getName().getLocalPart()});
 330         }
 331         return partName;*/
 332         return mimeContent.getPart();
 333     }
 334 
 335     private String getMimeContentType(MIMEContent mimeContent){
 336         String mimeType = mimeContent.getType();
 337         if(mimeType == null){
 338             error(mimeContent, ModelerMessages.MIMEMODELER_INVALID_MIME_CONTENT_MISSING_TYPE_ATTRIBUTE(info.operation.getName().getLocalPart()));
 339         }
 340         return mimeType;
 341     }
 342 
 343     /**
 344      * For Document/Lit the wsdl:part should only have element attribute and
 345      * for RPC/Lit or RPC/Encoded the wsdl:part should only have type attribute
 346      * inside wsdl:message.
 347      */
 348     protected boolean isStyleAndPartMatch(
 349         SOAPOperation soapOperation,
 350         MessagePart part) {
 351 
 352         // style attribute on soap:operation takes precedence over the
 353         // style attribute on soap:binding
 354 
 355         if ((soapOperation != null) && (soapOperation.getStyle() != null)) {
 356             if ((soapOperation.isDocument()
 357                 && (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
 358                 || (soapOperation.isRPC()
 359                     && (part.getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
 360                 return false;
 361             }
 362         } else {
 363             if ((info.soapBinding.isDocument()
 364                 && (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
 365                 || (info.soapBinding.isRPC()
 366                     && (part.getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
 367                 return false;
 368             }
 369         }
 370 
 371         return true;
 372     }
 373 
 374 
 375 
 376     protected String getRequestNamespaceURI(SOAPBody body) {
 377         String namespaceURI = body.getNamespace();
 378         if (namespaceURI == null) {
 379             if(options.isExtensionMode()){
 380                 return info.modelPort.getName().getNamespaceURI();
 381             }
 382             // the WSDL document is invalid
 383             // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
 384             error(body, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_SOAP_BODY_MISSING_NAMESPACE(info.bindingOperation.getName()));
 385         }
 386         return namespaceURI;
 387     }
 388 
 389     protected String getResponseNamespaceURI(SOAPBody body) {
 390         String namespaceURI = body.getNamespace();
 391         if (namespaceURI == null) {
 392             if(options.isExtensionMode()){
 393                 return info.modelPort.getName().getNamespaceURI();
 394             }
 395             // the WSDL document is invalid
 396             // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
 397             error(body, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_OUTPUT_SOAP_BODY_MISSING_NAMESPACE(info.bindingOperation.getName()));
 398         }
 399         return namespaceURI;
 400     }
 401 
 402     /**
 403      * @return List of SOAPHeader extensions
 404      */
 405     protected List<SOAPHeader> getHeaderExtensions(TWSDLExtensible extensible) {
 406         List<SOAPHeader> headerList = new ArrayList<SOAPHeader>();
 407         for (TWSDLExtension extension : extensible.extensions()) {
 408             if (extension.getClass()==MIMEMultipartRelated.class) {
 409                 for( MIMEPart part : ((MIMEMultipartRelated) extension).getParts() ) {
 410                     boolean isRootPart = isRootPart(part);
 411                     for (TWSDLExtension obj : part.extensions()) {
 412                         if (obj instanceof SOAPHeader) {
 413                             //bug fix: 5024015
 414                             if (!isRootPart) {
 415                                 warning((Entity) obj, ModelerMessages.MIMEMODELER_WARNING_IGNORINGINVALID_HEADER_PART_NOT_DECLARED_IN_ROOT_PART(info.bindingOperation.getName()));
 416                                 return new ArrayList<SOAPHeader>();
 417                             }
 418                             headerList.add((SOAPHeader) obj);
 419                         }
 420                     }
 421                 }
 422             } else if (extension instanceof SOAPHeader) {
 423                 headerList.add((SOAPHeader) extension);
 424             }
 425         }
 426          return headerList;
 427     }
 428 
 429     /**
 430      * @param part
 431      * @return true if part is the Root part
 432      */
 433     private boolean isRootPart(MIMEPart part) {
 434         for (TWSDLExtension twsdlExtension : part.extensions()) {
 435             if (twsdlExtension instanceof SOAPBody)
 436                 return true;
 437         }
 438         return false;
 439     }
 440 
 441     protected Set getDuplicateFaultNames() {
 442         // look for fault messages with the same soap:fault name
 443         Set<QName> faultNames = new HashSet<QName>();
 444         Set<QName> duplicateNames = new HashSet<QName>();
 445         for( BindingFault bindingFault : info.bindingOperation.faults() ) {
 446             com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
 447             for (com.sun.tools.internal.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
 448                 if (aFault.getName().equals(bindingFault.getName())) {
 449                     if (portTypeFault != null) {
 450                         // the WSDL document is invalid
 451                         error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(),
 452                             info.bindingOperation.getName()));
 453                     } else {
 454                         portTypeFault = aFault;
 455                     }
 456                 }
 457             }
 458             if (portTypeFault == null) {
 459                 // the WSDL document is invalid
 460                 error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(bindingFault.getName(),
 461                     info.bindingOperation.getName()));
 462             }
 463             SOAPFault soapFault =
 464                 (SOAPFault)getExtensionOfType(bindingFault, SOAPFault.class);
 465             if (soapFault == null) {
 466                 // the WSDL document is invalid
 467                 if(options.isExtensionMode()){
 468                     warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(),
 469                     info.bindingOperation.getName()));
 470                 }else {
 471                     error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(),
 472                         info.bindingOperation.getName()));
 473                 }
 474             }
 475 
 476             com.sun.tools.internal.ws.wsdl.document.Message faultMessage =
 477                 portTypeFault.resolveMessage(info.document);
 478             if(faultMessage.getParts().isEmpty()) {
 479                 // the WSDL document is invalid
 480                 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(bindingFault.getName(),
 481                     faultMessage.getName()));
 482             }
 483             //  bug fix: 4852729
 484             if (!options.isExtensionMode() && (soapFault != null && soapFault.getNamespace() != null)) {
 485                 warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
 486             }
 487             String faultNamespaceURI = (soapFault != null && soapFault.getNamespace() != null)?soapFault.getNamespace():portTypeFault.getMessage().getNamespaceURI();
 488             String faultName = faultMessage.getName();
 489             QName faultQName = new QName(faultNamespaceURI, faultName);
 490             if (faultNames.contains(faultQName)) {
 491                 duplicateNames.add(faultQName);
 492             } else {
 493                 faultNames.add(faultQName);
 494             }
 495         }
 496         return duplicateNames;
 497     }
 498 
 499 
 500     /**
 501      * @param operation
 502      * @return true if operation has valid body parts
 503      */
 504     protected boolean validateBodyParts(BindingOperation operation) {
 505         boolean isRequestResponse =
 506             info.portTypeOperation.getStyle()
 507             == OperationStyle.REQUEST_RESPONSE;
 508         List<MessagePart> inputParts = getMessageParts(getSOAPRequestBody(), getInputMessage(), true);
 509         if(!validateStyleAndPart(operation, inputParts))
 510             return false;
 511 
 512         if(isRequestResponse){
 513             List<MessagePart> outputParts = getMessageParts(getSOAPResponseBody(), getOutputMessage(), false);
 514             if(!validateStyleAndPart(operation, outputParts))
 515                 return false;
 516         }
 517         return true;
 518     }
 519 
 520     /**
 521      * @param operation
 522      * @return true if operation has valid style and part
 523      */
 524     private boolean validateStyleAndPart(BindingOperation operation, List<MessagePart> parts) {
 525         SOAPOperation soapOperation =
 526             (SOAPOperation) getExtensionOfType(operation, SOAPOperation.class);
 527         for (MessagePart part : parts) {
 528             if (part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING) {
 529                 if (!isStyleAndPartMatch(soapOperation, part))
 530                     return false;
 531             }
 532         }
 533         return true;
 534     }
 535 
 536     protected String getLiteralJavaMemberName(Fault fault) {
 537         String javaMemberName;
 538 
 539         QName memberName = fault.getElementName();
 540         javaMemberName = fault.getJavaMemberName();
 541         if (javaMemberName == null)
 542             javaMemberName = memberName.getLocalPart();
 543         return javaMemberName;
 544     }
 545 
 546     /**
 547      * @param ext
 548      * @param message
 549      * @param name
 550      * @return List of MimeContents from ext
 551      */
 552     protected List<MIMEContent> getMimeContents(TWSDLExtensible ext, Message message, String name) {
 553         for (MIMEPart mimePart : getMimeParts(ext)) {
 554             List<MIMEContent> mimeContents = getMimeContents(mimePart);
 555             for (MIMEContent mimeContent : mimeContents) {
 556                 if (mimeContent.getPart().equals(name))
 557                     return mimeContents;
 558             }
 559         }
 560         return null;
 561     }
 562 
 563     protected String makePackageQualified(String s) {
 564         if (s.indexOf(".") != -1) {
 565             // s is already package qualified
 566             return s;
 567         } else if (options.defaultPackage != null
 568                 && !options.defaultPackage.equals("")) {
 569             return options.defaultPackage + "." + s;
 570         } else {//options.defaultPackage seems to be never null, and this is never executed
 571             return s;
 572         }
 573 
 574     }
 575 
 576 
 577     protected String getUniqueName(
 578         com.sun.tools.internal.ws.wsdl.document.Operation operation,
 579         boolean hasOverloadedOperations) {
 580         if (hasOverloadedOperations) {
 581             return operation.getUniqueKey().replace(' ', '_');
 582         } else {
 583             return operation.getName();
 584         }
 585     }
 586 
 587     protected static QName getQNameOf(GloballyKnown entity) {
 588         return new QName(
 589             entity.getDefining().getTargetNamespaceURI(),
 590             entity.getName());
 591     }
 592 
 593     protected static TWSDLExtension getExtensionOfType(
 594             TWSDLExtensible extensible,
 595             Class type) {
 596         for (TWSDLExtension extension:extensible.extensions()) {
 597             if (extension.getClass().equals(type)) {
 598                 return extension;
 599             }
 600         }
 601 
 602         return null;
 603     }
 604 
 605     protected TWSDLExtension getAnyExtensionOfType(
 606         TWSDLExtensible extensible,
 607         Class type) {
 608         if(extensible == null)
 609             return null;
 610         for (TWSDLExtension extension:extensible.extensions()) {
 611             if(extension.getClass().equals(type)) {
 612                 return extension;
 613             }else if (extension.getClass().equals(MIMEMultipartRelated.class) &&
 614                     (type.equals(SOAPBody.class) || type.equals(MIMEContent.class)
 615                             || type.equals(MIMEPart.class))) {
 616                 for (MIMEPart part : ((MIMEMultipartRelated)extension).getParts()) {
 617                     //bug fix: 5024001
 618                     TWSDLExtension extn = getExtensionOfType(part, type);
 619                     if (extn != null)
 620                         return extn;
 621                 }
 622             }
 623         }
 624 
 625         return null;
 626     }
 627 
 628     // bug fix: 4857100
 629     protected static com.sun.tools.internal.ws.wsdl.document.Message findMessage(
 630         QName messageName,
 631         WSDLDocument document) {
 632         com.sun.tools.internal.ws.wsdl.document.Message message = null;
 633         try {
 634             message =
 635                 (com.sun.tools.internal.ws.wsdl.document.Message)document.find(
 636                     Kinds.MESSAGE,
 637                     messageName);
 638         } catch (NoSuchEntityException e) {
 639         }
 640         return message;
 641     }
 642 
 643     protected static boolean tokenListContains(
 644         String tokenList,
 645         String target) {
 646         if (tokenList == null) {
 647             return false;
 648         }
 649 
 650         StringTokenizer tokenizer = new StringTokenizer(tokenList, " ");
 651         while (tokenizer.hasMoreTokens()) {
 652             String s = tokenizer.nextToken();
 653             if (target.equals(s)) {
 654                 return true;
 655             }
 656         }
 657         return false;
 658     }
 659 
 660     protected String getUniqueClassName(String className) {
 661         int cnt = 2;
 662         String uniqueName = className;
 663         while (reqResNames.contains(uniqueName.toLowerCase())) {
 664             uniqueName = className + cnt;
 665             cnt++;
 666         }
 667         reqResNames.add(uniqueName.toLowerCase());
 668         return uniqueName;
 669     }
 670 
 671     protected boolean isConflictingClassName(String name) {
 672         if (_conflictingClassNames == null) {
 673             return false;
 674         }
 675 
 676         return _conflictingClassNames.contains(name);
 677     }
 678 
 679     protected boolean isConflictingServiceClassName(String name) {
 680         return isConflictingClassName(name);
 681     }
 682 
 683     protected boolean isConflictingStubClassName(String name) {
 684         return isConflictingClassName(name);
 685     }
 686 
 687     protected boolean isConflictingTieClassName(String name) {
 688         return isConflictingClassName(name);
 689     }
 690 
 691     protected boolean isConflictingPortClassName(String name) {
 692         return isConflictingClassName(name);
 693     }
 694 
 695     protected boolean isConflictingExceptionClassName(String name) {
 696         return isConflictingClassName(name);
 697     }
 698 
 699     int numPasses = 0;
 700 
 701     protected void warning(Entity entity, String message){
 702         //avoid duplicate warning for the second pass
 703         if(numPasses > 1)
 704             return;
 705         if(entity == null)
 706             errReceiver.warning(null, message);
 707         else
 708             errReceiver.warning(entity.getLocator(), message);
 709     }
 710 
 711     protected void error(Entity entity, String message){
 712         if(entity == null)
 713             errReceiver.error(null, message);
 714         else
 715             errReceiver.error(entity.getLocator(), message);
 716         throw new AbortException();
 717     }
 718 
 719     protected static final String OPERATION_HAS_VOID_RETURN_TYPE =
 720         "com.sun.xml.internal.ws.processor.modeler.wsdl.operationHasVoidReturnType";
 721     protected static final String WSDL_PARAMETER_ORDER =
 722         "com.sun.xml.internal.ws.processor.modeler.wsdl.parameterOrder";
 723     public static final String WSDL_RESULT_PARAMETER =
 724         "com.sun.xml.internal.ws.processor.modeler.wsdl.resultParameter";
 725     public static final String MESSAGE_HAS_MIME_MULTIPART_RELATED_BINDING =
 726         "com.sun.xml.internal.ws.processor.modeler.wsdl.mimeMultipartRelatedBinding";
 727 
 728 
 729     protected ProcessSOAPOperationInfo info;
 730 
 731     private Set _conflictingClassNames;
 732     protected Map<String,JavaException> _javaExceptions;
 733     protected Map _faultTypeToStructureMap;
 734     protected Map<QName, Port> _bindingNameToPortMap;
 735     protected boolean useWSIBasicProfile = true;
 736 
 737     private final Set<String> reqResNames = new HashSet<String>();
 738 
 739     public class ProcessSOAPOperationInfo {
 740 
 741         public ProcessSOAPOperationInfo(
 742             Port modelPort,
 743             com.sun.tools.internal.ws.wsdl.document.Port port,
 744             com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation,
 745             BindingOperation bindingOperation,
 746             SOAPBinding soapBinding,
 747             WSDLDocument document,
 748             boolean hasOverloadedOperations,
 749             Map headers) {
 750             this.modelPort = modelPort;
 751             this.port = port;
 752             this.portTypeOperation = portTypeOperation;
 753             this.bindingOperation = bindingOperation;
 754             this.soapBinding = soapBinding;
 755             this.document = document;
 756             this.hasOverloadedOperations = hasOverloadedOperations;
 757             this.headers = headers;
 758         }
 759 
 760         public Port modelPort;
 761         public com.sun.tools.internal.ws.wsdl.document.Port port;
 762         public com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation;
 763         public BindingOperation bindingOperation;
 764         public SOAPBinding soapBinding;
 765         public WSDLDocument document;
 766         public boolean hasOverloadedOperations;
 767         public Map headers;
 768 
 769         // additional data
 770         public Operation operation;
 771         public String uniqueOperationName;
 772     }
 773 
 774     public static class WSDLExceptionInfo {
 775         public String exceptionType;
 776         public QName wsdlMessage;
 777         public String wsdlMessagePartName;
 778         public HashMap constructorOrder; // mapping of element name to
 779                                              // constructor order (of type Integer)
 780     }
 781 
 782 
 783     protected WSDLParser parser;
 784     protected WSDLDocument document;
 785     protected static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
 786 }