001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.processor.modeler.wsdl;
038:
039: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
040: import com.sun.tools.ws.api.wsdl.TWSDLExtension;
041: import com.sun.tools.ws.processor.generator.Names;
042: import com.sun.tools.ws.processor.model.Fault;
043: import com.sun.tools.ws.processor.model.Operation;
044: import com.sun.tools.ws.processor.model.Port;
045: import com.sun.tools.ws.processor.model.java.JavaException;
046: import com.sun.tools.ws.processor.modeler.JavaSimpleTypeCreator;
047: import com.sun.tools.ws.processor.modeler.Modeler;
048: import com.sun.tools.ws.resources.ModelerMessages;
049: import com.sun.tools.ws.wscompile.AbortException;
050: import com.sun.tools.ws.wscompile.ErrorReceiver;
051: import com.sun.tools.ws.wscompile.ErrorReceiverFilter;
052: import com.sun.tools.ws.wscompile.WsimportOptions;
053: import com.sun.tools.ws.wsdl.document.*;
054: import com.sun.tools.ws.wsdl.document.jaxws.JAXWSBinding;
055: import com.sun.tools.ws.wsdl.document.mime.MIMEContent;
056: import com.sun.tools.ws.wsdl.document.mime.MIMEMultipartRelated;
057: import com.sun.tools.ws.wsdl.document.mime.MIMEPart;
058: import com.sun.tools.ws.wsdl.document.schema.SchemaKinds;
059: import com.sun.tools.ws.wsdl.document.soap.*;
060: import com.sun.tools.ws.wsdl.framework.Entity;
061: import com.sun.tools.ws.wsdl.framework.GloballyKnown;
062: import com.sun.tools.ws.wsdl.framework.NoSuchEntityException;
063: import com.sun.tools.ws.wsdl.parser.DOMForest;
064: import com.sun.tools.ws.wsdl.parser.WSDLParser;
065: import com.sun.tools.ws.wsdl.parser.MetadataFinder;
066: import com.sun.xml.bind.api.JAXBRIContext;
067: import org.xml.sax.helpers.LocatorImpl;
068:
069: import javax.xml.namespace.QName;
070: import java.util.*;
071:
072: /**
073: *
074: * @author WS Development Team
075: *
076: * Base class for WSDL->Model classes.
077: */
078: public abstract class WSDLModelerBase implements Modeler {
079: protected final ErrorReceiverFilter errReceiver;
080: protected final WsimportOptions options;
081: protected MetadataFinder forest;
082:
083: public WSDLModelerBase(WsimportOptions options,
084: ErrorReceiver receiver) {
085: this .options = options;
086: this .errReceiver = new ErrorReceiverFilter(receiver);
087: ;
088: }
089:
090: /**
091: *
092: * @param port
093: * @param wsdlPort
094: */
095: protected void applyPortMethodCustomization(Port port,
096: com.sun.tools.ws.wsdl.document.Port wsdlPort) {
097: if (isProvider(wsdlPort))
098: return;
099: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
100: wsdlPort, JAXWSBinding.class);
101:
102: String portMethodName = (jaxwsBinding != null) ? ((jaxwsBinding
103: .getMethodName() != null) ? jaxwsBinding
104: .getMethodName().getName() : null) : null;
105: if (portMethodName != null) {
106: port.setPortGetter(portMethodName);
107: } else {
108: portMethodName = Names.getPortName(port);
109: portMethodName = JAXBRIContext
110: .mangleNameToClassName(portMethodName);
111: port.setPortGetter("get" + portMethodName);
112: }
113:
114: }
115:
116: protected boolean isProvider(
117: com.sun.tools.ws.wsdl.document.Port wsdlPort) {
118: JAXWSBinding portCustomization = (JAXWSBinding) getExtensionOfType(
119: wsdlPort, JAXWSBinding.class);
120: Boolean isProvider = (portCustomization != null) ? portCustomization
121: .isProvider()
122: : null;
123: if (isProvider != null) {
124: return isProvider;
125: }
126:
127: JAXWSBinding jaxwsGlobalCustomization = (JAXWSBinding) getExtensionOfType(
128: document.getDefinitions(), JAXWSBinding.class);
129: isProvider = (jaxwsGlobalCustomization != null) ? jaxwsGlobalCustomization
130: .isProvider()
131: : null;
132: if (isProvider != null)
133: return isProvider;
134: return false;
135: }
136:
137: protected SOAPBody getSOAPRequestBody() {
138: SOAPBody requestBody = (SOAPBody) getAnyExtensionOfType(
139: info.bindingOperation.getInput(), SOAPBody.class);
140: if (requestBody == null) {
141: // the WSDL document is invalid
142: error(
143: info.bindingOperation.getInput(),
144: ModelerMessages
145: .WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation
146: .getName()));
147: }
148: return requestBody;
149: }
150:
151: protected boolean isRequestMimeMultipart() {
152: for (TWSDLExtension extension : info.bindingOperation
153: .getInput().extensions()) {
154: if (extension.getClass().equals(MIMEMultipartRelated.class)) {
155: return true;
156: }
157: }
158: return false;
159: }
160:
161: protected boolean isResponseMimeMultipart() {
162: for (TWSDLExtension extension : info.bindingOperation
163: .getOutput().extensions()) {
164: if (extension.getClass().equals(MIMEMultipartRelated.class)) {
165: return true;
166: }
167: }
168: return false;
169: }
170:
171: protected SOAPBody getSOAPResponseBody() {
172: SOAPBody responseBody = (SOAPBody) getAnyExtensionOfType(
173: info.bindingOperation.getOutput(), SOAPBody.class);
174: if (responseBody == null) {
175: // the WSDL document is invalid
176: error(
177: info.bindingOperation.getOutput(),
178: ModelerMessages
179: .WSDLMODELER_INVALID_BINDING_OPERATION_OUTPUT_MISSING_SOAP_BODY(info.bindingOperation
180: .getName()));
181: }
182: return responseBody;
183: }
184:
185: protected com.sun.tools.ws.wsdl.document.Message getOutputMessage() {
186: if (info.portTypeOperation.getOutput() == null)
187: return null;
188: return info.portTypeOperation.getOutput().resolveMessage(
189: info.document);
190: }
191:
192: protected com.sun.tools.ws.wsdl.document.Message getInputMessage() {
193: return info.portTypeOperation.getInput().resolveMessage(
194: info.document);
195: }
196:
197: /**
198: * @param body request or response body, represents soap:body
199: * @param message Input or output message, equivalent to wsdl:message
200: * @return iterator over MessagePart
201: */
202: protected List<MessagePart> getMessageParts(SOAPBody body,
203: com.sun.tools.ws.wsdl.document.Message message,
204: boolean isInput) {
205: String bodyParts = body.getParts();
206: ArrayList<MessagePart> partsList = new ArrayList<MessagePart>();
207: List<MessagePart> parts = new ArrayList<MessagePart>();
208:
209: //get Mime parts
210: List mimeParts;
211: if (isInput)
212: mimeParts = getMimeContentParts(message,
213: info.bindingOperation.getInput());
214: else
215: mimeParts = getMimeContentParts(message,
216: info.bindingOperation.getOutput());
217:
218: if (bodyParts != null) {
219: StringTokenizer in = new StringTokenizer(bodyParts.trim(),
220: " ");
221: while (in.hasMoreTokens()) {
222: String part = in.nextToken();
223: MessagePart mPart = message.getPart(part);
224: if (null == mPart) {
225: error(message, ModelerMessages
226: .WSDLMODELER_ERROR_PARTS_NOT_FOUND(part,
227: message.getName()));
228: }
229: mPart
230: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
231: partsList.add(mPart);
232: }
233: } else {
234: for (MessagePart mPart : message.getParts()) {
235: if (!mimeParts.contains(mPart))
236: mPart
237: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
238: partsList.add(mPart);
239: }
240: }
241:
242: for (MessagePart mPart : message.getParts()) {
243: if (mimeParts.contains(mPart)) {
244: mPart
245: .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
246: parts.add(mPart);
247: } else if (partsList.contains(mPart)) {
248: mPart
249: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
250: parts.add(mPart);
251: }
252: }
253:
254: return parts;
255: }
256:
257: /**
258: * @param message
259: * @return MessageParts referenced by the mime:content
260: */
261: protected List<MessagePart> getMimeContentParts(Message message,
262: TWSDLExtensible ext) {
263: ArrayList<MessagePart> mimeContentParts = new ArrayList<MessagePart>();
264:
265: for (MIMEPart mimePart : getMimeParts(ext)) {
266: MessagePart part = getMimeContentPart(message, mimePart);
267: if (part != null)
268: mimeContentParts.add(part);
269: }
270: return mimeContentParts;
271: }
272:
273: /**
274: * @param mimeParts
275: */
276: protected boolean validateMimeParts(Iterable<MIMEPart> mimeParts) {
277: boolean gotRootPart = false;
278: List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
279: for (MIMEPart mPart : mimeParts) {
280: for (TWSDLExtension obj : mPart.extensions()) {
281: if (obj instanceof SOAPBody) {
282: if (gotRootPart) {
283: warning(
284: mPart,
285: ModelerMessages
286: .MIMEMODELER_INVALID_MIME_PART_MORE_THAN_ONE_SOAP_BODY(info.operation
287: .getName()
288: .getLocalPart()));
289: return false;
290: }
291: gotRootPart = true;
292: } else if (obj instanceof MIMEContent) {
293: mimeContents.add((MIMEContent) obj);
294: }
295: }
296: if (!validateMimeContentPartNames(mimeContents))
297: return false;
298: if (mPart.getName() != null) {
299: warning(
300: mPart,
301: ModelerMessages
302: .MIMEMODELER_INVALID_MIME_PART_NAME_NOT_ALLOWED(info.portTypeOperation
303: .getName()));
304: }
305: }
306: return true;
307:
308: }
309:
310: private MessagePart getMimeContentPart(Message message,
311: MIMEPart part) {
312: for (MIMEContent mimeContent : getMimeContents(part)) {
313: String mimeContentPartName = mimeContent.getPart();
314: MessagePart mPart = message.getPart(mimeContentPartName);
315: //RXXXX mime:content MUST have part attribute
316: if (null == mPart) {
317: error(mimeContent, ModelerMessages
318: .WSDLMODELER_ERROR_PARTS_NOT_FOUND(
319: mimeContentPartName, message.getName()));
320: }
321: mPart
322: .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
323: return mPart;
324: }
325: return null;
326: }
327:
328: //List of mimeTypes
329: protected List<String> getAlternateMimeTypes(
330: List<MIMEContent> mimeContents) {
331: List<String> mimeTypes = new ArrayList<String>();
332: //validateMimeContentPartNames(mimeContents.iterator());
333: // String mimeType = null;
334: for (MIMEContent mimeContent : mimeContents) {
335: String mimeType = getMimeContentType(mimeContent);
336: if (!mimeTypes.contains(mimeType))
337: mimeTypes.add(mimeType);
338: }
339: return mimeTypes;
340: }
341:
342: private boolean validateMimeContentPartNames(
343: List<MIMEContent> mimeContents) {
344: //validate mime:content(s) in the mime:part as per R2909
345: for (MIMEContent mimeContent : mimeContents) {
346: String mimeContnetPart = null;
347: if (mimeContnetPart == null) {
348: mimeContnetPart = getMimeContentPartName(mimeContent);
349: if (mimeContnetPart == null) {
350: warning(
351: mimeContent,
352: ModelerMessages
353: .MIMEMODELER_INVALID_MIME_CONTENT_MISSING_PART_ATTRIBUTE(info.operation
354: .getName().getLocalPart()));
355: return false;
356: }
357: } else {
358: String newMimeContnetPart = getMimeContentPartName(mimeContent);
359: if (newMimeContnetPart == null) {
360: warning(
361: mimeContent,
362: ModelerMessages
363: .MIMEMODELER_INVALID_MIME_CONTENT_MISSING_PART_ATTRIBUTE(info.operation
364: .getName().getLocalPart()));
365: return false;
366: } else if (!newMimeContnetPart.equals(mimeContnetPart)) {
367: //throw new ModelerException("mimemodeler.invalidMimeContent.differentPart");
368: warning(
369: mimeContent,
370: ModelerMessages
371: .MIMEMODELER_INVALID_MIME_CONTENT_DIFFERENT_PART());
372: return false;
373: }
374: }
375: }
376: return true;
377: }
378:
379: protected Iterable<MIMEPart> getMimeParts(TWSDLExtensible ext) {
380: MIMEMultipartRelated multiPartRelated = (MIMEMultipartRelated) getAnyExtensionOfType(
381: ext, MIMEMultipartRelated.class);
382: if (multiPartRelated == null) {
383: return Collections.emptyList();
384: }
385: return multiPartRelated.getParts();
386: }
387:
388: //returns MIMEContents
389: protected List<MIMEContent> getMimeContents(MIMEPart part) {
390: List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
391: for (TWSDLExtension mimeContent : part.extensions()) {
392: if (mimeContent instanceof MIMEContent) {
393: mimeContents.add((MIMEContent) mimeContent);
394: }
395: }
396: //validateMimeContentPartNames(mimeContents.iterator());
397: return mimeContents;
398: }
399:
400: private String getMimeContentPartName(MIMEContent mimeContent) {
401: /*String partName = mimeContent.getPart();
402: if(partName == null){
403: throw new ModelerException("mimemodeler.invalidMimeContent.missingPartAttribute",
404: new Object[] {info.operation.getName().getLocalPart()});
405: }
406: return partName;*/
407: return mimeContent.getPart();
408: }
409:
410: private String getMimeContentType(MIMEContent mimeContent) {
411: String mimeType = mimeContent.getType();
412: if (mimeType == null) {
413: error(
414: mimeContent,
415: ModelerMessages
416: .MIMEMODELER_INVALID_MIME_CONTENT_MISSING_TYPE_ATTRIBUTE(info.operation
417: .getName().getLocalPart()));
418: }
419: return mimeType;
420: }
421:
422: /**
423: * For Document/Lit the wsdl:part should only have element attribute and
424: * for RPC/Lit or RPC/Encoded the wsdl:part should only have type attribute
425: * inside wsdl:message.
426: */
427: protected boolean isStyleAndPartMatch(SOAPOperation soapOperation,
428: MessagePart part) {
429:
430: // style attribute on soap:operation takes precedence over the
431: // style attribute on soap:binding
432:
433: if ((soapOperation != null)
434: && (soapOperation.getStyle() != null)) {
435: if ((soapOperation.isDocument() && (part
436: .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
437: || (soapOperation.isRPC() && (part
438: .getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
439: return false;
440: }
441: } else {
442: if ((info.soapBinding.isDocument() && (part
443: .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
444: || (info.soapBinding.isRPC() && (part
445: .getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
446: return false;
447: }
448: }
449:
450: return true;
451: }
452:
453: protected String getRequestNamespaceURI(SOAPBody body) {
454: String namespaceURI = body.getNamespace();
455: if (namespaceURI == null) {
456: if (options.isExtensionMode()) {
457: return info.modelPort.getName().getNamespaceURI();
458: }
459: // the WSDL document is invalid
460: // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
461: error(
462: body,
463: ModelerMessages
464: .WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_SOAP_BODY_MISSING_NAMESPACE(info.bindingOperation
465: .getName()));
466: }
467: return namespaceURI;
468: }
469:
470: protected String getResponseNamespaceURI(SOAPBody body) {
471: String namespaceURI = body.getNamespace();
472: if (namespaceURI == null) {
473: if (options.isExtensionMode()) {
474: return info.modelPort.getName().getNamespaceURI();
475: }
476: // the WSDL document is invalid
477: // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
478: error(
479: body,
480: ModelerMessages
481: .WSDLMODELER_INVALID_BINDING_OPERATION_OUTPUT_SOAP_BODY_MISSING_NAMESPACE(info.bindingOperation
482: .getName()));
483: }
484: return namespaceURI;
485: }
486:
487: /**
488: * @return List of SOAPHeader extensions
489: */
490: protected List<SOAPHeader> getHeaderExtensions(
491: TWSDLExtensible extensible) {
492: List<SOAPHeader> headerList = new ArrayList<SOAPHeader>();
493: for (TWSDLExtension extension : extensible.extensions()) {
494: if (extension.getClass() == MIMEMultipartRelated.class) {
495: for (MIMEPart part : ((MIMEMultipartRelated) extension)
496: .getParts()) {
497: boolean isRootPart = isRootPart(part);
498: for (TWSDLExtension obj : part.extensions()) {
499: if (obj instanceof SOAPHeader) {
500: //bug fix: 5024015
501: if (!isRootPart) {
502: warning(
503: (Entity) obj,
504: ModelerMessages
505: .MIMEMODELER_WARNING_IGNORINGINVALID_HEADER_PART_NOT_DECLARED_IN_ROOT_PART(info.bindingOperation
506: .getName()));
507: return new ArrayList<SOAPHeader>();
508: }
509: headerList.add((SOAPHeader) obj);
510: }
511: }
512: }
513: } else if (extension instanceof SOAPHeader) {
514: headerList.add((SOAPHeader) extension);
515: }
516: }
517: return headerList;
518: }
519:
520: /**
521: * @param part
522: * @return true if part is the Root part
523: */
524: private boolean isRootPart(MIMEPart part) {
525: for (TWSDLExtension twsdlExtension : part.extensions()) {
526: if (twsdlExtension instanceof SOAPBody)
527: return true;
528: }
529: return false;
530: }
531:
532: protected Set getDuplicateFaultNames() {
533: // look for fault messages with the same soap:fault name
534: Set<QName> faultNames = new HashSet<QName>();
535: Set<QName> duplicateNames = new HashSet<QName>();
536: for (BindingFault bindingFault : info.bindingOperation.faults()) {
537: com.sun.tools.ws.wsdl.document.Fault portTypeFault = null;
538: for (com.sun.tools.ws.wsdl.document.Fault aFault : info.portTypeOperation
539: .faults()) {
540: if (aFault.getName().equals(bindingFault.getName())) {
541: if (portTypeFault != null) {
542: // the WSDL document is invalid
543: error(
544: bindingFault,
545: ModelerMessages
546: .WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(
547: bindingFault.getName(),
548: info.bindingOperation
549: .getName()));
550: } else {
551: portTypeFault = aFault;
552: }
553: }
554: }
555: if (portTypeFault == null) {
556: // the WSDL document is invalid
557: error(bindingFault, ModelerMessages
558: .WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(
559: bindingFault.getName(),
560: info.bindingOperation.getName()));
561: }
562: SOAPFault soapFault = (SOAPFault) getExtensionOfType(
563: bindingFault, SOAPFault.class);
564: if (soapFault == null) {
565: // the WSDL document is invalid
566: if (options.isExtensionMode()) {
567: warning(
568: bindingFault,
569: ModelerMessages
570: .WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(
571: bindingFault.getName(),
572: info.bindingOperation
573: .getName()));
574: } else {
575: error(
576: bindingFault,
577: ModelerMessages
578: .WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(
579: bindingFault.getName(),
580: info.bindingOperation
581: .getName()));
582: }
583: }
584:
585: com.sun.tools.ws.wsdl.document.Message faultMessage = portTypeFault
586: .resolveMessage(info.document);
587: if (faultMessage.getParts().isEmpty()) {
588: // the WSDL document is invalid
589: error(
590: faultMessage,
591: ModelerMessages
592: .WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(
593: bindingFault.getName(),
594: faultMessage.getName()));
595: }
596: // bug fix: 4852729
597: if (!options.isExtensionMode()
598: && (soapFault != null && soapFault.getNamespace() != null)) {
599: warning(soapFault, ModelerMessages
600: .WSDLMODELER_WARNING_R_2716_R_2726(
601: "soapbind:fault", soapFault.getName()));
602: }
603: String faultNamespaceURI = (soapFault != null && soapFault
604: .getNamespace() != null) ? soapFault.getNamespace()
605: : portTypeFault.getMessage().getNamespaceURI();
606: String faultName = faultMessage.getName();
607: QName faultQName = new QName(faultNamespaceURI, faultName);
608: if (faultNames.contains(faultQName)) {
609: duplicateNames.add(faultQName);
610: } else {
611: faultNames.add(faultQName);
612: }
613: }
614: return duplicateNames;
615: }
616:
617: /**
618: * @param operation
619: * @return true if operation has valid body parts
620: */
621: protected boolean validateBodyParts(BindingOperation operation) {
622: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
623: List<MessagePart> inputParts = getMessageParts(
624: getSOAPRequestBody(), getInputMessage(), true);
625: if (!validateStyleAndPart(operation, inputParts))
626: return false;
627:
628: if (isRequestResponse) {
629: List<MessagePart> outputParts = getMessageParts(
630: getSOAPResponseBody(), getOutputMessage(), false);
631: if (!validateStyleAndPart(operation, outputParts))
632: return false;
633: }
634: return true;
635: }
636:
637: /**
638: * @param operation
639: * @return true if operation has valid style and part
640: */
641: private boolean validateStyleAndPart(BindingOperation operation,
642: List<MessagePart> parts) {
643: SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
644: operation, SOAPOperation.class);
645: for (MessagePart part : parts) {
646: if (part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING) {
647: if (!isStyleAndPartMatch(soapOperation, part))
648: return false;
649: }
650: }
651: return true;
652: }
653:
654: protected String getLiteralJavaMemberName(Fault fault) {
655: String javaMemberName;
656:
657: QName memberName = fault.getElementName();
658: javaMemberName = fault.getJavaMemberName();
659: if (javaMemberName == null)
660: javaMemberName = memberName.getLocalPart();
661: return javaMemberName;
662: }
663:
664: /**
665: * @param ext
666: * @param message
667: * @param name
668: * @return List of MimeContents from ext
669: */
670: protected List<MIMEContent> getMimeContents(TWSDLExtensible ext,
671: Message message, String name) {
672: for (MIMEPart mimePart : getMimeParts(ext)) {
673: List<MIMEContent> mimeContents = getMimeContents(mimePart);
674: for (MIMEContent mimeContent : mimeContents) {
675: if (mimeContent.getPart().equals(name))
676: return mimeContents;
677: }
678: }
679: return null;
680: }
681:
682: protected String makePackageQualified(String s) {
683: if (options.defaultPackage != null
684: && !options.defaultPackage.equals("")) {
685: return options.defaultPackage + "." + s;
686: } else {
687: return s;
688: }
689: }
690:
691: protected String getUniqueName(
692: com.sun.tools.ws.wsdl.document.Operation operation,
693: boolean hasOverloadedOperations) {
694: if (hasOverloadedOperations) {
695: return operation.getUniqueKey().replace(' ', '_');
696: } else {
697: return operation.getName();
698: }
699: }
700:
701: protected static QName getQNameOf(GloballyKnown entity) {
702: return new QName(entity.getDefining().getTargetNamespaceURI(),
703: entity.getName());
704: }
705:
706: protected static TWSDLExtension getExtensionOfType(
707: TWSDLExtensible extensible, Class type) {
708: for (TWSDLExtension extension : extensible.extensions()) {
709: if (extension.getClass().equals(type)) {
710: return extension;
711: }
712: }
713:
714: return null;
715: }
716:
717: protected TWSDLExtension getAnyExtensionOfType(
718: TWSDLExtensible extensible, Class type) {
719: if (extensible == null)
720: return null;
721: for (TWSDLExtension extension : extensible.extensions()) {
722: if (extension.getClass().equals(type)) {
723: return extension;
724: } else if (extension.getClass().equals(
725: MIMEMultipartRelated.class)
726: && (type.equals(SOAPBody.class)
727: || type.equals(MIMEContent.class) || type
728: .equals(MIMEPart.class))) {
729: for (MIMEPart part : ((MIMEMultipartRelated) extension)
730: .getParts()) {
731: //bug fix: 5024001
732: TWSDLExtension extn = getExtensionOfType(part, type);
733: if (extn != null)
734: return extn;
735: }
736: }
737: }
738:
739: return null;
740: }
741:
742: // bug fix: 4857100
743: protected static com.sun.tools.ws.wsdl.document.Message findMessage(
744: QName messageName, ProcessSOAPOperationInfo info) {
745: com.sun.tools.ws.wsdl.document.Message message = null;
746: try {
747: message = (com.sun.tools.ws.wsdl.document.Message) info.document
748: .find(Kinds.MESSAGE, messageName);
749: } catch (NoSuchEntityException e) {
750: }
751: return message;
752: }
753:
754: protected static boolean tokenListContains(String tokenList,
755: String target) {
756: if (tokenList == null) {
757: return false;
758: }
759:
760: StringTokenizer tokenizer = new StringTokenizer(tokenList, " ");
761: while (tokenizer.hasMoreTokens()) {
762: String s = tokenizer.nextToken();
763: if (target.equals(s)) {
764: return true;
765: }
766: }
767: return false;
768: }
769:
770: protected String getUniqueClassName(String className) {
771: int cnt = 2;
772: String uniqueName = className;
773: while (reqResNames.contains(uniqueName.toLowerCase())) {
774: uniqueName = className + cnt;
775: cnt++;
776: }
777: reqResNames.add(uniqueName.toLowerCase());
778: return uniqueName;
779: }
780:
781: protected boolean isConflictingClassName(String name) {
782: if (_conflictingClassNames == null) {
783: return false;
784: }
785:
786: return _conflictingClassNames.contains(name);
787: }
788:
789: protected boolean isConflictingServiceClassName(String name) {
790: return isConflictingClassName(name);
791: }
792:
793: protected boolean isConflictingStubClassName(String name) {
794: return isConflictingClassName(name);
795: }
796:
797: protected boolean isConflictingTieClassName(String name) {
798: return isConflictingClassName(name);
799: }
800:
801: protected boolean isConflictingPortClassName(String name) {
802: return isConflictingClassName(name);
803: }
804:
805: protected boolean isConflictingExceptionClassName(String name) {
806: return isConflictingClassName(name);
807: }
808:
809: int numPasses = 0;
810:
811: protected void warning(Entity entity, String message) {
812: //avoid duplicate warning for the second pass
813: if (numPasses > 1)
814: return;
815: if (entity == null)
816: errReceiver.warning(null, message);
817: else
818: errReceiver.warning(entity.getLocator(), message);
819: }
820:
821: protected void error(Entity entity, String message) {
822: if (entity == null)
823: errReceiver.error(null, message);
824: else
825: errReceiver.error(entity.getLocator(), message);
826: throw new AbortException();
827: }
828:
829: protected static final String OPERATION_HAS_VOID_RETURN_TYPE = "com.sun.xml.ws.processor.modeler.wsdl.operationHasVoidReturnType";
830: protected static final String WSDL_PARAMETER_ORDER = "com.sun.xml.ws.processor.modeler.wsdl.parameterOrder";
831: public static final String WSDL_RESULT_PARAMETER = "com.sun.xml.ws.processor.modeler.wsdl.resultParameter";
832: public static final String MESSAGE_HAS_MIME_MULTIPART_RELATED_BINDING = "com.sun.xml.ws.processor.modeler.wsdl.mimeMultipartRelatedBinding";
833:
834: protected ProcessSOAPOperationInfo info;
835:
836: private Set _conflictingClassNames;
837: protected Map<String, JavaException> _javaExceptions;
838: protected Map _faultTypeToStructureMap;
839: protected JavaSimpleTypeCreator _javaTypes;
840: protected Map<QName, Port> _bindingNameToPortMap;
841: protected boolean useWSIBasicProfile = true;
842:
843: private final Set<String> reqResNames = new HashSet<String>();
844:
845: public class ProcessSOAPOperationInfo {
846:
847: public ProcessSOAPOperationInfo(
848: Port modelPort,
849: com.sun.tools.ws.wsdl.document.Port port,
850: com.sun.tools.ws.wsdl.document.Operation portTypeOperation,
851: BindingOperation bindingOperation,
852: SOAPBinding soapBinding, WSDLDocument document,
853: boolean hasOverloadedOperations, Map headers) {
854: this .modelPort = modelPort;
855: this .port = port;
856: this .portTypeOperation = portTypeOperation;
857: this .bindingOperation = bindingOperation;
858: this .soapBinding = soapBinding;
859: this .document = document;
860: this .hasOverloadedOperations = hasOverloadedOperations;
861: this .headers = headers;
862: }
863:
864: public Port modelPort;
865: public com.sun.tools.ws.wsdl.document.Port port;
866: public com.sun.tools.ws.wsdl.document.Operation portTypeOperation;
867: public BindingOperation bindingOperation;
868: public SOAPBinding soapBinding;
869: public WSDLDocument document;
870: public boolean hasOverloadedOperations;
871: public Map headers;
872:
873: // additional data
874: public Operation operation;
875: public String uniqueOperationName;
876: }
877:
878: public static class WSDLExceptionInfo {
879: public String exceptionType;
880: public QName wsdlMessage;
881: public String wsdlMessagePartName;
882: public HashMap constructorOrder; // mapping of element name to
883: // constructor order (of type Integer)
884: }
885:
886: protected WSDLParser parser;
887: protected WSDLDocument document;
888: protected static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
889: }
|