0001: /*
0002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004: *
0005: * This code is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU General Public License version 2 only, as
0007: * published by the Free Software Foundation. Sun designates this
0008: * particular file as subject to the "Classpath" exception as provided
0009: * by Sun in the LICENSE file that accompanied this code.
0010: *
0011: * This code is distributed in the hope that it will be useful, but WITHOUT
0012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014: * version 2 for more details (a copy is included in the LICENSE file that
0015: * accompanied this code).
0016: *
0017: * You should have received a copy of the GNU General Public License version
0018: * 2 along with this work; if not, write to the Free Software Foundation,
0019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020: *
0021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022: * CA 95054 USA or visit www.sun.com if you need additional information or
0023: * have any questions.
0024: */
0025:
0026: package com.sun.tools.internal.ws.processor.modeler.wsdl;
0027:
0028: import com.sun.tools.internal.ws.processor.config.WSDLModelInfo;
0029: import com.sun.tools.internal.ws.processor.generator.Names;
0030: import com.sun.tools.internal.ws.processor.model.AbstractType;
0031: import com.sun.tools.internal.ws.processor.model.Block;
0032: import com.sun.tools.internal.ws.processor.model.Fault;
0033: import com.sun.tools.internal.ws.processor.model.Model;
0034: import com.sun.tools.internal.ws.processor.model.ModelObject;
0035: import com.sun.tools.internal.ws.processor.model.ModelProperties;
0036: import com.sun.tools.internal.ws.processor.model.Operation;
0037: import com.sun.tools.internal.ws.processor.model.Parameter;
0038: import com.sun.tools.internal.ws.processor.model.Port;
0039: import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
0040: import com.sun.tools.internal.ws.processor.modeler.Modeler;
0041: import com.sun.tools.internal.ws.processor.modeler.ModelerException;
0042: import com.sun.tools.internal.ws.processor.util.ProcessorEnvironment;
0043: import com.sun.tools.internal.ws.wsdl.document.Binding;
0044: import com.sun.tools.internal.ws.wsdl.document.BindingFault;
0045: import com.sun.tools.internal.ws.wsdl.document.BindingOperation;
0046: import com.sun.tools.internal.ws.wsdl.document.Documentation;
0047: import com.sun.tools.internal.ws.wsdl.document.Kinds;
0048: import com.sun.tools.internal.ws.wsdl.document.Message;
0049: import com.sun.tools.internal.ws.wsdl.document.MessagePart;
0050: import com.sun.tools.internal.ws.wsdl.document.OperationStyle;
0051: import com.sun.tools.internal.ws.wsdl.document.WSDLDocument;
0052: import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
0053: import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
0054: import com.sun.tools.internal.ws.wsdl.document.mime.MIMEMultipartRelated;
0055: import com.sun.tools.internal.ws.wsdl.document.mime.MIMEPart;
0056: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
0057: import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
0058: import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBody;
0059: import com.sun.tools.internal.ws.wsdl.document.soap.SOAPFault;
0060: import com.sun.tools.internal.ws.wsdl.document.soap.SOAPHeader;
0061: import com.sun.tools.internal.ws.wsdl.document.soap.SOAPOperation;
0062: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
0063: import com.sun.tools.internal.ws.wsdl.framework.Extension;
0064: import com.sun.tools.internal.ws.wsdl.framework.GloballyKnown;
0065: import com.sun.tools.internal.ws.wsdl.framework.NoSuchEntityException;
0066: import com.sun.tools.internal.ws.wsdl.parser.Constants;
0067: import com.sun.tools.internal.ws.wsdl.parser.Util;
0068: import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
0069: import com.sun.xml.internal.ws.util.localization.Localizable;
0070: import com.sun.xml.internal.ws.util.localization.LocalizableMessageFactory;
0071: import com.sun.xml.internal.ws.util.xml.XmlUtil;
0072: import org.w3c.dom.Element;
0073:
0074: import javax.xml.namespace.QName;
0075: import java.util.ArrayList;
0076: import java.util.HashMap;
0077: import java.util.HashSet;
0078: import java.util.Iterator;
0079: import java.util.List;
0080: import java.util.Map;
0081: import java.util.Properties;
0082: import java.util.Set;
0083: import java.util.StringTokenizer;
0084:
0085: /**
0086: *
0087: * @author WS Development Team
0088: *
0089: * Base class for WSDL->Model classes.
0090: */
0091: public abstract class WSDLModelerBase implements Modeler {
0092: public WSDLModelerBase(WSDLModelInfo modelInfo, Properties options) {
0093: //init();
0094: _modelInfo = modelInfo;
0095: _options = options;
0096: _messageFactory = new LocalizableMessageFactory(
0097: "com.sun.tools.internal.ws.resources.modeler");
0098: _conflictingClassNames = null;
0099: _env = (ProcessorEnvironment) modelInfo.getParent()
0100: .getEnvironment();
0101: hSet = null;
0102: reqResNames = new HashSet();
0103: }
0104:
0105: protected WSDLParser createWSDLParser() {
0106: return new WSDLParser(_modelInfo);
0107: }
0108:
0109: /**
0110: * Builds model from WSDL document. Model contains abstraction which is used by the
0111: * generators to generate the stub/tie/serializers etc. code.
0112: *
0113: * @see Modeler#buildModel()
0114: */
0115: public Model buildModel() {
0116: return null;
0117: }
0118:
0119: protected WSDLModelInfo getWSDLModelInfo() {
0120: return _modelInfo;
0121: }
0122:
0123: protected Documentation getDocumentationFor(Element e) {
0124: String s = XmlUtil.getTextForNode(e);
0125: if (s == null) {
0126: return null;
0127: } else {
0128: return new Documentation(s);
0129: }
0130: }
0131:
0132: protected void checkNotWsdlElement(Element e) {
0133: // possible extensibility element -- must live outside the WSDL namespace
0134: if (e.getNamespaceURI().equals(Constants.NS_WSDL))
0135: Util.fail("parsing.invalidWsdlElement", e.getTagName());
0136: }
0137:
0138: /**
0139: * @param port
0140: * @param wsdlPort
0141: */
0142: protected void applyPortMethodCustomization(Port port,
0143: com.sun.tools.internal.ws.wsdl.document.Port wsdlPort) {
0144: if (isProvider(wsdlPort))
0145: return;
0146: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
0147: wsdlPort, JAXWSBinding.class);
0148:
0149: String portMethodName = (jaxwsBinding != null) ? ((jaxwsBinding
0150: .getMethodName() != null) ? jaxwsBinding
0151: .getMethodName().getName() : null) : null;
0152: if (portMethodName != null) {
0153: port.setPortGetter(portMethodName);
0154: } else {
0155: portMethodName = Names.getPortName(port);
0156: portMethodName = getEnvironment().getNames()
0157: .validJavaClassName(portMethodName);
0158: port.setPortGetter("get" + portMethodName);
0159: }
0160:
0161: }
0162:
0163: protected boolean isProvider(
0164: com.sun.tools.internal.ws.wsdl.document.Port wsdlPort) {
0165: JAXWSBinding portCustomization = (JAXWSBinding) getExtensionOfType(
0166: wsdlPort, JAXWSBinding.class);
0167: Boolean isProvider = (portCustomization != null) ? portCustomization
0168: .isProvider()
0169: : null;
0170: if (isProvider != null) {
0171: return isProvider;
0172: }
0173:
0174: JAXWSBinding jaxwsGlobalCustomization = (JAXWSBinding) getExtensionOfType(
0175: document.getDefinitions(), JAXWSBinding.class);
0176: isProvider = (jaxwsGlobalCustomization != null) ? jaxwsGlobalCustomization
0177: .isProvider()
0178: : null;
0179: if (isProvider != null)
0180: return isProvider;
0181: return false;
0182: }
0183:
0184: protected void createParentFault(Fault fault) {
0185: AbstractType faultType = fault.getBlock().getType();
0186: AbstractType parentType = null;
0187:
0188: if (parentType == null) {
0189: return;
0190: }
0191:
0192: if (fault.getParentFault() != null) {
0193: return;
0194: }
0195: Fault parentFault = new Fault(((AbstractType) parentType)
0196: .getName().getLocalPart());
0197: /* this is what it really should be but for interop with JAXRPC 1.0.1 we are not doing
0198: * this at this time.
0199: *
0200: * TODO - we should double-check this; the above statement might not be true anymore.
0201: */
0202: QName faultQName = new QName(fault.getBlock().getName()
0203: .getNamespaceURI(), parentFault.getName());
0204: Block block = new Block(faultQName);
0205: block.setType((AbstractType) parentType);
0206: parentFault.setBlock(block);
0207: parentFault.addSubfault(fault);
0208: createParentFault(parentFault);
0209: }
0210:
0211: protected void createSubfaults(Fault fault) {
0212: AbstractType faultType = fault.getBlock().getType();
0213: Iterator subtypes = null;
0214: if (subtypes != null) {
0215: AbstractType subtype;
0216: while (subtypes.hasNext()) {
0217: subtype = (AbstractType) subtypes.next();
0218: Fault subFault = new Fault(subtype.getName()
0219: .getLocalPart());
0220: /* this is what it really is but for interop with JAXRPC 1.0.1 we are not doing
0221: * this at this time
0222: *
0223: * TODO - we should double-check this; the above statement might not be true anymore.
0224: */
0225: QName faultQName = new QName(fault.getBlock().getName()
0226: .getNamespaceURI(), subFault.getName());
0227: Block block = new Block(faultQName);
0228: block.setType(subtype);
0229: subFault.setBlock(block);
0230: fault.addSubfault(subFault);
0231: createSubfaults(subFault);
0232: }
0233: }
0234: }
0235:
0236: protected SOAPBody getSOAPRequestBody() {
0237: SOAPBody requestBody = (SOAPBody) getAnyExtensionOfType(
0238: info.bindingOperation.getInput(), SOAPBody.class);
0239: if (requestBody == null) {
0240: // the WSDL document is invalid
0241: throw new ModelerException(
0242: "wsdlmodeler.invalid.bindingOperation.inputMissingSoapBody",
0243: new Object[] { info.bindingOperation.getName() });
0244: }
0245: return requestBody;
0246: }
0247:
0248: protected boolean isRequestMimeMultipart() {
0249: for (Iterator iter = info.bindingOperation.getInput()
0250: .extensions(); iter.hasNext();) {
0251: Extension extension = (Extension) iter.next();
0252: if (extension.getClass().equals(MIMEMultipartRelated.class)) {
0253: return true;
0254: }
0255: }
0256: return false;
0257: }
0258:
0259: protected boolean isResponseMimeMultipart() {
0260: for (Iterator iter = info.bindingOperation.getOutput()
0261: .extensions(); iter.hasNext();) {
0262: Extension extension = (Extension) iter.next();
0263: if (extension.getClass().equals(MIMEMultipartRelated.class)) {
0264: return true;
0265: }
0266: }
0267: return false;
0268: }
0269:
0270: protected SOAPBody getSOAPResponseBody() {
0271: SOAPBody responseBody = (SOAPBody) getAnyExtensionOfType(
0272: info.bindingOperation.getOutput(), SOAPBody.class);
0273: if (responseBody == null) {
0274: // the WSDL document is invalid
0275: throw new ModelerException(
0276: "wsdlmodeler.invalid.bindingOperation.outputMissingSoapBody",
0277: new Object[] { info.bindingOperation.getName() });
0278: }
0279: return responseBody;
0280: }
0281:
0282: protected com.sun.tools.internal.ws.wsdl.document.Message getOutputMessage() {
0283: if (info.portTypeOperation.getOutput() == null)
0284: return null;
0285: return info.portTypeOperation.getOutput().resolveMessage(
0286: info.document);
0287: }
0288:
0289: protected com.sun.tools.internal.ws.wsdl.document.Message getInputMessage() {
0290: return info.portTypeOperation.getInput().resolveMessage(
0291: info.document);
0292: }
0293:
0294: /**
0295: * @param body request or response body, represents soap:body
0296: * @param message Input or output message, equivalent to wsdl:message
0297: * @return iterator over MessagePart
0298: */
0299: protected List getMessageParts(SOAPBody body,
0300: com.sun.tools.internal.ws.wsdl.document.Message message,
0301: boolean isInput) {
0302: String bodyParts = body.getParts();
0303: ArrayList partsList = new ArrayList();
0304: List parts = new ArrayList();
0305:
0306: //get Mime parts
0307: List mimeParts = null;
0308: if (isInput)
0309: mimeParts = getMimeContentParts(message,
0310: info.bindingOperation.getInput());
0311: else
0312: mimeParts = getMimeContentParts(message,
0313: info.bindingOperation.getOutput());
0314:
0315: if (bodyParts != null) {
0316: StringTokenizer in = new StringTokenizer(bodyParts.trim(),
0317: " ");
0318: while (in.hasMoreTokens()) {
0319: String part = in.nextToken();
0320: MessagePart mPart = (MessagePart) message.getPart(part);
0321: if (null == mPart) {
0322: throw new ModelerException(
0323: "wsdlmodeler.error.partsNotFound",
0324: new Object[] { part, message.getName() });
0325: }
0326: mPart
0327: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
0328: partsList.add(mPart);
0329: }
0330: } else {
0331: for (Iterator iter = message.parts(); iter.hasNext();) {
0332: MessagePart mPart = (MessagePart) iter.next();
0333: if (!mimeParts.contains(mPart))
0334: mPart
0335: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
0336: partsList.add(mPart);
0337: }
0338: }
0339:
0340: for (Iterator iter = message.parts(); iter.hasNext();) {
0341: MessagePart mPart = (MessagePart) iter.next();
0342: if (mimeParts.contains(mPart)) {
0343: mPart
0344: .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
0345: parts.add(mPart);
0346: } else if (partsList.contains(mPart)) {
0347: mPart
0348: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
0349: parts.add(mPart);
0350: }
0351: }
0352:
0353: return parts;
0354: }
0355:
0356: /**
0357: * @param message
0358: * @return MessageParts referenced by the mime:content
0359: */
0360: protected List getMimeContentParts(Message message, Extensible ext) {
0361: ArrayList mimeContentParts = new ArrayList();
0362: String mimeContentPartName = null;
0363: Iterator mimeParts = getMimeParts(ext);
0364:
0365: while (mimeParts.hasNext()) {
0366: MessagePart part = getMimeContentPart(message,
0367: (MIMEPart) mimeParts.next());
0368: if (part != null)
0369: mimeContentParts.add(part);
0370: }
0371: return mimeContentParts;
0372: }
0373:
0374: /**
0375: * @param mimeParts
0376: */
0377: protected boolean validateMimeParts(Iterator mimeParts) {
0378: boolean gotRootPart = false;
0379: List mimeContents = new ArrayList();
0380: while (mimeParts.hasNext()) {
0381: MIMEPart mPart = (MIMEPart) mimeParts.next();
0382: Iterator extns = mPart.extensions();
0383: while (extns.hasNext()) {
0384: Object obj = extns.next();
0385: if (obj instanceof SOAPBody) {
0386: if (gotRootPart) {
0387: //bug fix: 5024020
0388: warn(
0389: "mimemodeler.invalidMimePart.moreThanOneSOAPBody",
0390: new Object[] { info.operation.getName()
0391: .getLocalPart() });
0392: return false;
0393: }
0394: gotRootPart = true;
0395: } else if (obj instanceof MIMEContent) {
0396: mimeContents.add((MIMEContent) obj);
0397: }
0398: }
0399: if (!validateMimeContentPartNames(mimeContents.iterator()))
0400: return false;
0401: if (mPart.getName() != null) {
0402: //bug fix: 5024018
0403: warn("mimemodeler.invalidMimePart.nameNotAllowed",
0404: info.portTypeOperation.getName());
0405: }
0406: }
0407: return true;
0408:
0409: }
0410:
0411: private MessagePart getMimeContentPart(Message message,
0412: MIMEPart part) {
0413: String mimeContentPartName = null;
0414: Iterator mimeContents = getMimeContents(part).iterator();
0415: if (mimeContents.hasNext()) {
0416: mimeContentPartName = ((MIMEContent) mimeContents.next())
0417: .getPart();
0418: MessagePart mPart = (MessagePart) message
0419: .getPart(mimeContentPartName);
0420: //RXXXX mime:content MUST have part attribute
0421: if (null == mPart) {
0422: throw new ModelerException(
0423: "wsdlmodeler.error.partsNotFound",
0424: new Object[] { mimeContentPartName,
0425: message.getName() });
0426: }
0427: mPart
0428: .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
0429: return mPart;
0430: }
0431: return null;
0432: }
0433:
0434: //List of mimeTypes
0435: protected List<String> getAlternateMimeTypes(
0436: List<MIMEContent> mimeContents) {
0437: List<String> mimeTypes = new ArrayList<String>();
0438: //validateMimeContentPartNames(mimeContents.iterator());
0439: // String mimeType = null;
0440: for (MIMEContent mimeContent : mimeContents) {
0441: String mimeType = getMimeContentType(mimeContent);
0442: if (!mimeTypes.contains(mimeType))
0443: mimeTypes.add(mimeType);
0444: }
0445: return mimeTypes;
0446: }
0447:
0448: /**
0449: * @param iterator
0450: */
0451: private boolean validateMimeContentPartNames(Iterator mimeContents) {
0452: //validate mime:content(s) in the mime:part as per R2909
0453: while (mimeContents.hasNext()) {
0454: String mimeContnetPart = null;
0455: if (mimeContnetPart == null) {
0456: mimeContnetPart = getMimeContentPartName((MIMEContent) mimeContents
0457: .next());
0458: if (mimeContnetPart == null) {
0459: warn(
0460: "mimemodeler.invalidMimeContent.missingPartAttribute",
0461: new Object[] { info.operation.getName()
0462: .getLocalPart() });
0463: return false;
0464: }
0465: } else {
0466: String newMimeContnetPart = getMimeContentPartName((MIMEContent) mimeContents
0467: .next());
0468: if (newMimeContnetPart == null) {
0469: warn(
0470: "mimemodeler.invalidMimeContent.missingPartAttribute",
0471: new Object[] { info.operation.getName()
0472: .getLocalPart() });
0473: return false;
0474: } else if (!newMimeContnetPart.equals(mimeContnetPart)) {
0475: //throw new ModelerException("mimemodeler.invalidMimeContent.differentPart");
0476: warn("mimemodeler.invalidMimeContent.differentPart");
0477: return false;
0478: }
0479: }
0480: }
0481: return true;
0482: }
0483:
0484: protected Iterator<MIMEPart> getMimeParts(Extensible ext) {
0485: MIMEMultipartRelated multiPartRelated = (MIMEMultipartRelated) getAnyExtensionOfType(
0486: ext, MIMEMultipartRelated.class);
0487: if (multiPartRelated == null) {
0488: List<MIMEPart> parts = new ArrayList<MIMEPart>();
0489: return parts.iterator();
0490: }
0491: return multiPartRelated.getParts();
0492: }
0493:
0494: //returns MIMEContents
0495: protected List<MIMEContent> getMimeContents(MIMEPart part) {
0496: List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
0497: Iterator parts = part.extensions();
0498: while (parts.hasNext()) {
0499: Extension mimeContent = (Extension) parts.next();
0500: if (mimeContent instanceof MIMEContent) {
0501: mimeContents.add((MIMEContent) mimeContent);
0502: }
0503: }
0504: //validateMimeContentPartNames(mimeContents.iterator());
0505: return mimeContents;
0506: }
0507:
0508: private String getMimeContentPartName(MIMEContent mimeContent) {
0509: /*String partName = mimeContent.getPart();
0510: if(partName == null){
0511: throw new ModelerException("mimemodeler.invalidMimeContent.missingPartAttribute",
0512: new Object[] {info.operation.getName().getLocalPart()});
0513: }
0514: return partName;*/
0515: return mimeContent.getPart();
0516: }
0517:
0518: private String getMimeContentType(MIMEContent mimeContent) {
0519: String mimeType = mimeContent.getType();
0520: if (mimeType == null) {
0521: throw new ModelerException(
0522: "mimemodeler.invalidMimeContent.missingTypeAttribute",
0523: new Object[] { info.operation.getName()
0524: .getLocalPart() });
0525: }
0526: return mimeType;
0527: }
0528:
0529: /**
0530: * For Document/Lit the wsdl:part should only have element attribute and
0531: * for RPC/Lit or RPC/Encoded the wsdl:part should only have type attribute
0532: * inside wsdl:message.
0533: */
0534: protected boolean isStyleAndPartMatch(SOAPOperation soapOperation,
0535: MessagePart part) {
0536:
0537: // style attribute on soap:operation takes precedence over the
0538: // style attribute on soap:binding
0539:
0540: if ((soapOperation != null)
0541: && (soapOperation.getStyle() != null)) {
0542: if ((soapOperation.isDocument() && (part
0543: .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
0544: || (soapOperation.isRPC() && (part
0545: .getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
0546: return false;
0547: }
0548: } else {
0549: if ((info.soapBinding.isDocument() && (part
0550: .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
0551: || (info.soapBinding.isRPC() && (part
0552: .getDescriptorKind() != SchemaKinds.XSD_TYPE))) {
0553: return false;
0554: }
0555: }
0556:
0557: return true;
0558: }
0559:
0560: protected String getRequestNamespaceURI(SOAPBody body) {
0561: String namespaceURI = body.getNamespace();
0562: if (namespaceURI == null) {
0563: // the WSDL document is invalid
0564: // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
0565: throw new ModelerException(
0566: "wsdlmodeler.invalid.bindingOperation.inputSoapBody.missingNamespace",
0567: new Object[] { info.bindingOperation.getName() });
0568: }
0569: return namespaceURI;
0570: }
0571:
0572: protected String getResponseNamespaceURI(SOAPBody body) {
0573: String namespaceURI = body.getNamespace();
0574: if (namespaceURI == null) {
0575: // the WSDL document is invalid
0576: // at least, that's my interpretation of section 3.5 of the WSDL 1.1 spec!
0577: throw new ModelerException(
0578: "wsdlmodeler.invalid.bindingOperation.outputSoapBody.missingNamespace",
0579: new Object[] { info.bindingOperation.getName() });
0580: }
0581: return namespaceURI;
0582: }
0583:
0584: /**
0585: * @return List of SOAPHeader extensions
0586: */
0587: protected List<SOAPHeader> getHeaderExtensions(Extensible extensible) {
0588: List<SOAPHeader> headerList = new ArrayList<SOAPHeader>();
0589: Iterator bindingIter = extensible.extensions();
0590: while (bindingIter.hasNext()) {
0591: Extension extension = (Extension) bindingIter.next();
0592: if (extension.getClass().equals(MIMEMultipartRelated.class)) {
0593: for (Iterator parts = ((MIMEMultipartRelated) extension)
0594: .getParts(); parts.hasNext();) {
0595: Extension part = (Extension) parts.next();
0596: if (part.getClass().equals(MIMEPart.class)) {
0597: boolean isRootPart = isRootPart((MIMEPart) part);
0598: Iterator iter = ((MIMEPart) part).extensions();
0599: while (iter.hasNext()) {
0600: Object obj = iter.next();
0601: if (obj instanceof SOAPHeader) {
0602: //bug fix: 5024015
0603: if (!isRootPart) {
0604: warn(
0605: "mimemodeler.warning.IgnoringinvalidHeaderPart.notDeclaredInRootPart",
0606: new Object[] { info.bindingOperation
0607: .getName() });
0608: return new ArrayList<SOAPHeader>();
0609: }
0610: headerList.add((SOAPHeader) obj);
0611: }
0612: }
0613: }
0614:
0615: }
0616: } else if (extension instanceof SOAPHeader) {
0617: headerList.add((SOAPHeader) extension);
0618: }
0619: }
0620: return headerList;
0621: }
0622:
0623: /**
0624: * @param part
0625: * @return true if part is the Root part
0626: */
0627: private boolean isRootPart(MIMEPart part) {
0628: Iterator iter = part.extensions();
0629: while (iter.hasNext()) {
0630: if (iter.next() instanceof SOAPBody)
0631: return true;
0632: }
0633: return false;
0634: }
0635:
0636: protected Set getDuplicateFaultNames() {
0637: // look for fault messages with the same soap:fault name
0638: Set faultNames = new HashSet();
0639: Set duplicateNames = new HashSet();
0640: for (Iterator iter = info.bindingOperation.faults(); iter
0641: .hasNext();) {
0642: BindingFault bindingFault = (BindingFault) iter.next();
0643: com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
0644: for (Iterator iter2 = info.portTypeOperation.faults(); iter2
0645: .hasNext();) {
0646: com.sun.tools.internal.ws.wsdl.document.Fault aFault = (com.sun.tools.internal.ws.wsdl.document.Fault) iter2
0647: .next();
0648:
0649: if (aFault.getName().equals(bindingFault.getName())) {
0650: if (portTypeFault != null) {
0651: // the WSDL document is invalid
0652: throw new ModelerException(
0653: "wsdlmodeler.invalid.bindingFault.notUnique",
0654: new Object[] { bindingFault.getName(),
0655: info.bindingOperation.getName() });
0656: } else {
0657: portTypeFault = aFault;
0658: }
0659: }
0660: }
0661: if (portTypeFault == null) {
0662: // the WSDL document is invalid
0663: throw new ModelerException(
0664: "wsdlmodeler.invalid.bindingFault.notFound",
0665: new Object[] { bindingFault.getName(),
0666: info.bindingOperation.getName() });
0667:
0668: }
0669: SOAPFault soapFault = (SOAPFault) getExtensionOfType(
0670: bindingFault, SOAPFault.class);
0671: if (soapFault == null) {
0672: // the WSDL document is invalid
0673: throw new ModelerException(
0674: "wsdlmodeler.invalid.bindingFault.outputMissingSoapFault",
0675: new Object[] { bindingFault.getName(),
0676: info.bindingOperation.getName() });
0677: }
0678:
0679: com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault
0680: .resolveMessage(info.document);
0681: Iterator iter2 = faultMessage.parts();
0682: if (!iter2.hasNext()) {
0683: // the WSDL document is invalid
0684: throw new ModelerException(
0685: "wsdlmodeler.invalid.bindingFault.emptyMessage",
0686: new Object[] { bindingFault.getName(),
0687: faultMessage.getName() });
0688: }
0689: // bug fix: 4852729
0690: if (useWSIBasicProfile
0691: && (soapFault.getNamespace() != null)) {
0692: warn("wsdlmodeler.warning.r2716r2726", new Object[] {
0693: "soapbind:fault", soapFault.getName() });
0694: }
0695: String faultNamespaceURI = soapFault.getNamespace();
0696: if (faultNamespaceURI == null) {
0697: faultNamespaceURI = portTypeFault.getMessage()
0698: .getNamespaceURI();
0699: }
0700: String faultName = faultMessage.getName();
0701: QName faultQName = new QName(faultNamespaceURI, faultName);
0702: if (faultNames.contains(faultQName)) {
0703: duplicateNames.add(faultQName);
0704: } else {
0705: faultNames.add(faultQName);
0706: }
0707: }
0708: return duplicateNames;
0709: }
0710:
0711: /**
0712: * @param operation
0713: * @return true if operation has valid body parts
0714: */
0715: protected boolean validateBodyParts(BindingOperation operation) {
0716: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
0717: List inputParts = getMessageParts(getSOAPRequestBody(),
0718: getInputMessage(), true);
0719: if (!validateStyleAndPart(operation, inputParts))
0720: return false;
0721:
0722: if (isRequestResponse) {
0723: List outputParts = getMessageParts(getSOAPResponseBody(),
0724: getOutputMessage(), false);
0725: if (!validateStyleAndPart(operation, outputParts))
0726: return false;
0727: }
0728: return true;
0729: }
0730:
0731: /**
0732: * @param operation
0733: * @return true if operation has valid style and part
0734: */
0735: private boolean validateStyleAndPart(BindingOperation operation,
0736: List parts) {
0737: SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
0738: operation, SOAPOperation.class);
0739: for (Iterator iter = parts.iterator(); iter.hasNext();) {
0740: MessagePart part = (MessagePart) iter.next();
0741: if (part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING) {
0742: if (!isStyleAndPartMatch(soapOperation, part))
0743: return false;
0744: }
0745: }
0746: return true;
0747: }
0748:
0749: protected String getLiteralJavaMemberName(Fault fault) {
0750: String javaMemberName;
0751:
0752: QName memberName = fault.getElementName();
0753: javaMemberName = fault.getJavaMemberName();
0754: if (javaMemberName == null)
0755: javaMemberName = memberName.getLocalPart();
0756: return javaMemberName;
0757: }
0758:
0759: /**
0760: * @param ext
0761: * @param message
0762: * @param name
0763: * @return List of MimeContents from ext
0764: */
0765: protected List<MIMEContent> getMimeContents(Extensible ext,
0766: Message message, String name) {
0767: Iterator mimeParts = getMimeParts(ext);
0768: while (mimeParts.hasNext()) {
0769: MIMEPart mimePart = (MIMEPart) mimeParts.next();
0770: List<MIMEContent> mimeContents = getMimeContents(mimePart);
0771: for (MIMEContent mimeContent : mimeContents) {
0772: if (mimeContent.getPart().equals(name))
0773: return mimeContents;
0774: }
0775: }
0776: return null;
0777: }
0778:
0779: protected ProcessorEnvironment getEnvironment() {
0780: return _env;
0781: }
0782:
0783: protected void warn(Localizable msg) {
0784: getEnvironment().warn(msg);
0785: }
0786:
0787: protected void warn(String key) {
0788: getEnvironment().warn(_messageFactory.getMessage(key));
0789: }
0790:
0791: protected void warn(String key, String arg) {
0792: getEnvironment().warn(_messageFactory.getMessage(key, arg));
0793: }
0794:
0795: protected void error(String key, String arg) {
0796: getEnvironment().error(_messageFactory.getMessage(key, arg));
0797: }
0798:
0799: protected void warn(String key, Object[] args) {
0800: getEnvironment().warn(_messageFactory.getMessage(key, args));
0801: }
0802:
0803: protected void info(String key) {
0804: getEnvironment().info(_messageFactory.getMessage(key));
0805: }
0806:
0807: protected void info(String key, String arg) {
0808: getEnvironment().info(_messageFactory.getMessage(key, arg));
0809: }
0810:
0811: protected String makePackageQualified(String s, QName name) {
0812: return makePackageQualified(s, name, true);
0813: }
0814:
0815: protected String makePackageQualified(String s, QName name,
0816: boolean useNamespaceMapping) {
0817: String javaPackageName = null;
0818: if (useNamespaceMapping) {
0819: javaPackageName = getJavaPackageName(name);
0820: }
0821: if (javaPackageName != null) {
0822: return javaPackageName + "." + s;
0823: } else if (_modelInfo.getJavaPackageName() != null
0824: && !_modelInfo.getJavaPackageName().equals("")) {
0825: return _modelInfo.getJavaPackageName() + "." + s;
0826: } else {
0827: return s;
0828: }
0829: }
0830:
0831: protected QName makePackageQualified(QName name) {
0832: return makePackageQualified(name, true);
0833: }
0834:
0835: protected QName makePackageQualified(QName name,
0836: boolean useNamespaceMapping) {
0837: return new QName(name.getNamespaceURI(), makePackageQualified(
0838: name.getLocalPart(), name));
0839: }
0840:
0841: protected String makeNameUniqueInSet(String candidateName, Set names) {
0842: String baseName = candidateName;
0843: String name = baseName;
0844: for (int i = 2; names.contains(name); ++i) {
0845: name = baseName + Integer.toString(i);
0846: }
0847: return name;
0848: }
0849:
0850: protected String getUniqueName(
0851: com.sun.tools.internal.ws.wsdl.document.Operation operation,
0852: boolean hasOverloadedOperations) {
0853: if (hasOverloadedOperations) {
0854: return operation.getUniqueKey().replace(' ', '_');
0855: } else {
0856: return operation.getName();
0857: }
0858: }
0859:
0860: protected String getUniqueParameterName(Operation operation,
0861: String baseName) {
0862: Set names = new HashSet();
0863: for (Iterator iter = operation.getRequest().getParameters(); iter
0864: .hasNext();) {
0865: Parameter p = (Parameter) iter.next();
0866: names.add(p.getName());
0867: }
0868: for (Iterator iter = operation.getResponse().getParameters(); iter
0869: .hasNext();) {
0870: Parameter p = (Parameter) iter.next();
0871: names.add(p.getName());
0872: }
0873: String candidateName = baseName;
0874: while (names.contains(candidateName)) {
0875: candidateName += "_prime";
0876: }
0877: return candidateName;
0878: }
0879:
0880: protected String getNonQualifiedNameFor(QName name) {
0881: return _env.getNames().validJavaClassName(name.getLocalPart());
0882: }
0883:
0884: protected static void setDocumentationIfPresent(ModelObject obj,
0885: Documentation documentation) {
0886: if (documentation != null && documentation.getContent() != null) {
0887: obj.setProperty(WSDL_DOCUMENTATION, documentation
0888: .getContent());
0889: }
0890: }
0891:
0892: protected static QName getQNameOf(GloballyKnown entity) {
0893: return new QName(entity.getDefining().getTargetNamespaceURI(),
0894: entity.getName());
0895: }
0896:
0897: protected static Extension getExtensionOfType(
0898: Extensible extensible, Class type) {
0899: for (Iterator iter = extensible.extensions(); iter.hasNext();) {
0900: Extension extension = (Extension) iter.next();
0901: if (extension.getClass().equals(type)) {
0902: return extension;
0903: }
0904: }
0905:
0906: return null;
0907: }
0908:
0909: protected Extension getAnyExtensionOfType(Extensible extensible,
0910: Class type) {
0911: if (extensible == null)
0912: return null;
0913: for (Iterator iter = extensible.extensions(); iter.hasNext();) {
0914: Extension extension = (Extension) iter.next();
0915: if (extension.getClass().equals(type)) {
0916: return extension;
0917: } else if (extension.getClass().equals(
0918: MIMEMultipartRelated.class)
0919: && (type.equals(SOAPBody.class)
0920: || type.equals(MIMEContent.class) || type
0921: .equals(MIMEPart.class))) {
0922: for (Iterator parts = ((MIMEMultipartRelated) extension)
0923: .getParts(); parts.hasNext();) {
0924: Extension part = (Extension) parts.next();
0925: if (part.getClass().equals(MIMEPart.class)) {
0926: MIMEPart mPart = (MIMEPart) part;
0927: //bug fix: 5024001
0928: Extension extn = getExtensionOfType(
0929: (Extensible) part, type);
0930: if (extn != null)
0931: return extn;
0932: }
0933: }
0934: }
0935: }
0936:
0937: return null;
0938: }
0939:
0940: // bug fix: 4857100
0941: protected static com.sun.tools.internal.ws.wsdl.document.Message findMessage(
0942: QName messageName, ProcessSOAPOperationInfo info) {
0943: com.sun.tools.internal.ws.wsdl.document.Message message = null;
0944: try {
0945: message = (com.sun.tools.internal.ws.wsdl.document.Message) info.document
0946: .find(Kinds.MESSAGE, messageName);
0947: } catch (NoSuchEntityException e) {
0948: }
0949: return message;
0950: }
0951:
0952: protected static boolean tokenListContains(String tokenList,
0953: String target) {
0954: if (tokenList == null) {
0955: return false;
0956: }
0957:
0958: StringTokenizer tokenizer = new StringTokenizer(tokenList, " ");
0959: while (tokenizer.hasMoreTokens()) {
0960: String s = tokenizer.nextToken();
0961: if (target.equals(s)) {
0962: return true;
0963: }
0964: }
0965: return false;
0966: }
0967:
0968: protected String getUniqueClassName(String className) {
0969: int cnt = 2;
0970: String uniqueName = className;
0971: while (reqResNames.contains(uniqueName.toLowerCase())) {
0972: uniqueName = className + cnt;
0973: cnt++;
0974: }
0975: reqResNames.add(uniqueName.toLowerCase());
0976: return uniqueName;
0977: }
0978:
0979: private String getJavaPackageName(QName name) {
0980: String packageName = null;
0981: /* if (_modelInfo.getNamespaceMappingRegistry() != null) {
0982: NamespaceMappingInfo i =
0983: _modelInfo
0984: .getNamespaceMappingRegistry()
0985: .getNamespaceMappingInfo(
0986: name);
0987: if (i != null)
0988: return i.getJavaPackageName();
0989: }*/
0990: return packageName;
0991: }
0992:
0993: protected boolean isConflictingClassName(String name) {
0994: if (_conflictingClassNames == null) {
0995: return false;
0996: }
0997:
0998: return _conflictingClassNames.contains(name);
0999: }
1000:
1001: protected boolean isConflictingServiceClassName(String name) {
1002: return isConflictingClassName(name);
1003: }
1004:
1005: protected boolean isConflictingStubClassName(String name) {
1006: return isConflictingClassName(name);
1007: }
1008:
1009: protected boolean isConflictingTieClassName(String name) {
1010: return isConflictingClassName(name);
1011: }
1012:
1013: protected boolean isConflictingPortClassName(String name) {
1014: return isConflictingClassName(name);
1015: }
1016:
1017: protected boolean isConflictingExceptionClassName(String name) {
1018: return isConflictingClassName(name);
1019: }
1020:
1021: protected static final String OPERATION_HAS_VOID_RETURN_TYPE = "com.sun.xml.internal.ws.processor.modeler.wsdl.operationHasVoidReturnType";
1022: private static final String WSDL_DOCUMENTATION = "com.sun.xml.internal.ws.processor.modeler.wsdl.documentation";
1023: protected static final String WSDL_PARAMETER_ORDER = "com.sun.xml.internal.ws.processor.modeler.wsdl.parameterOrder";
1024: public static final String WSDL_RESULT_PARAMETER = "com.sun.xml.internal.ws.processor.modeler.wsdl.resultParameter";
1025: public static final String MESSAGE_HAS_MIME_MULTIPART_RELATED_BINDING = "com.sun.xml.internal.ws.processor.modeler.wsdl.mimeMultipartRelatedBinding";
1026:
1027: public ProcessorEnvironment getProcessorEnvironment() {
1028: return _env;
1029: }
1030:
1031: protected ProcessSOAPOperationInfo info;
1032:
1033: protected WSDLModelInfo _modelInfo;
1034: protected Properties _options;
1035: protected LocalizableMessageFactory _messageFactory;
1036: private Set _conflictingClassNames;
1037: protected Map _javaExceptions;
1038: protected Map _faultTypeToStructureMap;
1039: private ProcessorEnvironment _env;
1040: protected JavaSimpleTypeCreator _javaTypes;
1041: protected Map<QName, Port> _bindingNameToPortMap;
1042: protected boolean useWSIBasicProfile = true;
1043:
1044: private Set reqResNames;
1045:
1046: public class ProcessSOAPOperationInfo {
1047:
1048: public ProcessSOAPOperationInfo(
1049: Port modelPort,
1050: com.sun.tools.internal.ws.wsdl.document.Port port,
1051: com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation,
1052: BindingOperation bindingOperation,
1053: SOAPBinding soapBinding, WSDLDocument document,
1054: boolean hasOverloadedOperations, Map headers) {
1055: this .modelPort = modelPort;
1056: this .port = port;
1057: this .portTypeOperation = portTypeOperation;
1058: this .bindingOperation = bindingOperation;
1059: this .soapBinding = soapBinding;
1060: this .document = document;
1061: this .hasOverloadedOperations = hasOverloadedOperations;
1062: this .headers = headers;
1063: }
1064:
1065: public Port modelPort;
1066: public com.sun.tools.internal.ws.wsdl.document.Port port;
1067: public com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation;
1068: public BindingOperation bindingOperation;
1069: public SOAPBinding soapBinding;
1070: public WSDLDocument document;
1071: public boolean hasOverloadedOperations;
1072: public Map headers;
1073:
1074: // additional data
1075: public Operation operation;
1076: public String uniqueOperationName;
1077: }
1078:
1079: public static class WSDLExceptionInfo {
1080: public String exceptionType;
1081: public QName wsdlMessage;
1082: public String wsdlMessagePartName;
1083: public HashMap constructorOrder; // mapping of element name to
1084: // constructor order (of type Integer)
1085: };
1086:
1087: protected WSDLParser parser;
1088: protected WSDLDocument document;
1089: protected HashSet hSet;
1090: }
|