0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common Development
0008: * and Distribution License("CDDL") (collectively, the "License"). You
0009: * may not use this file except in compliance with the License. You can obtain
0010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
0012: * language governing permissions and limitations under the License.
0013: *
0014: * When distributing the software, include this License Header Notice in each
0015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0016: * Sun designates this particular file as subject to the "Classpath" exception
0017: * as provided by Sun in the GPL Version 2 section of the License file that
0018: * accompanied this code. If applicable, add the following below the License
0019: * Header, with the fields enclosed by brackets [] replaced by your own
0020: * identifying information: "Portions Copyrighted [year]
0021: * [name of copyright owner]"
0022: *
0023: * Contributor(s):
0024: *
0025: * If you wish your version of this file to be governed by only the CDDL or
0026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
0027: * elects to include this software in this distribution under the [CDDL or GPL
0028: * Version 2] license." If you don't indicate a single choice of license, a
0029: * recipient has the option to distribute your version of this file under
0030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
0031: * its licensees as provided above. However, if you add GPL Version 2 code
0032: * and therefore, elected the GPL Version 2 license, then the option applies
0033: * only if the new code is made subject to such option by the copyright
0034: * holder.
0035: */
0036: package com.sun.tools.ws.processor.modeler.wsdl;
0037:
0038: import com.sun.codemodel.JType;
0039: import com.sun.istack.SAXParseException2;
0040: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
0041: import com.sun.tools.ws.processor.generator.Names;
0042: import com.sun.tools.ws.processor.model.*;
0043: import com.sun.tools.ws.processor.model.Fault;
0044: import com.sun.tools.ws.processor.model.Operation;
0045: import com.sun.tools.ws.processor.model.Port;
0046: import com.sun.tools.ws.processor.model.Service;
0047: import com.sun.tools.ws.processor.model.java.*;
0048: import com.sun.tools.ws.processor.model.jaxb.*;
0049: import com.sun.tools.ws.processor.modeler.JavaSimpleTypeCreator;
0050: import com.sun.tools.ws.processor.util.ClassNameCollector;
0051: import com.sun.tools.ws.resources.ModelerMessages;
0052: import com.sun.tools.ws.wscompile.ErrorReceiver;
0053: import com.sun.tools.ws.wscompile.WsimportOptions;
0054: import com.sun.tools.ws.wsdl.document.*;
0055: import com.sun.tools.ws.wsdl.document.Message;
0056: import com.sun.tools.ws.wsdl.document.jaxws.CustomName;
0057: import com.sun.tools.ws.wsdl.document.jaxws.JAXWSBinding;
0058: import com.sun.tools.ws.wsdl.document.mime.MIMEContent;
0059: import com.sun.tools.ws.wsdl.document.schema.SchemaKinds;
0060: import com.sun.tools.ws.wsdl.document.soap.*;
0061: import com.sun.tools.ws.wsdl.framework.*;
0062: import com.sun.tools.ws.wsdl.parser.WSDLParser;
0063: import com.sun.tools.xjc.api.S2JJAXBModel;
0064: import com.sun.tools.xjc.api.TypeAndAnnotation;
0065: import com.sun.tools.xjc.api.XJC;
0066: import com.sun.xml.bind.api.JAXBRIContext;
0067: import com.sun.xml.ws.util.xml.XmlUtil;
0068: import org.xml.sax.InputSource;
0069: import org.xml.sax.Locator;
0070: import org.xml.sax.SAXException;
0071: import org.xml.sax.SAXParseException;
0072: import org.xml.sax.helpers.LocatorImpl;
0073:
0074: import javax.jws.WebParam.Mode;
0075: import javax.xml.namespace.QName;
0076: import java.util.*;
0077: import java.io.IOException;
0078:
0079: /**
0080: * The WSDLModeler processes a WSDL to create a Model.
0081: *
0082: * @author WS Development Team
0083: */
0084: public class WSDLModeler extends WSDLModelerBase {
0085:
0086: //map of wsdl:operation QName to <soapenv:Body> child, as per BP it must be unique in a port
0087: private final Map<QName, Operation> uniqueBodyBlocks = new HashMap<QName, Operation>();
0088: private final QName VOID_BODYBLOCK = new QName("");
0089: private ClassNameCollector classNameCollector;
0090: private final String explicitDefaultPackage;
0091:
0092: public WSDLModeler(WsimportOptions options, ErrorReceiver receiver) {
0093: super (options, receiver);
0094: this .classNameCollector = new ClassNameCollector();
0095: this .explicitDefaultPackage = options.defaultPackage;
0096: }
0097:
0098: protected enum StyleAndUse {
0099: RPC_LITERAL, DOC_LITERAL
0100: }
0101:
0102: private JAXBModelBuilder jaxbModelBuilder;
0103:
0104: public Model buildModel() {
0105: try {
0106:
0107: parser = new WSDLParser(options, errReceiver);
0108: parser.addParserListener(new ParserListener() {
0109: public void ignoringExtension(Entity entity,
0110: QName name, QName parent) {
0111: if (parent.equals(WSDLConstants.QNAME_TYPES)) {
0112: // check for a schema element with the wrong namespace URI
0113: if (name.getLocalPart().equals("schema")
0114: && !name.getNamespaceURI().equals("")) {
0115: warning(
0116: entity,
0117: ModelerMessages
0118: .WSDLMODELER_WARNING_IGNORING_UNRECOGNIZED_SCHEMA_EXTENSION(name
0119: .getNamespaceURI()));
0120: }
0121: }
0122:
0123: }
0124:
0125: public void doneParsingEntity(QName element,
0126: Entity entity) {
0127: }
0128: });
0129:
0130: document = parser.parse();
0131: if (document == null || document.getDefinitions() == null)
0132: return null;
0133:
0134: document.validateLocally();
0135: forest = parser.getDOMForest();
0136:
0137: Model model = internalBuildModel(document);
0138: if (model == null || errReceiver.hadError())
0139: return null;
0140: //ClassNameCollector classNameCollector = new ClassNameCollector();
0141: classNameCollector.process(model);
0142: if (classNameCollector.getConflictingClassNames().isEmpty()) {
0143: if (errReceiver.hadError())
0144: return null;
0145: return model;
0146: }
0147: // do another pass, this time with conflict resolution enabled
0148: model = internalBuildModel(document);
0149:
0150: classNameCollector.process(model);
0151: if (classNameCollector.getConflictingClassNames().isEmpty()) {
0152: // we're done
0153: if (errReceiver.hadError())
0154: return null;
0155: return model;
0156: }
0157: // give up
0158: StringBuffer conflictList = new StringBuffer();
0159: boolean first = true;
0160: for (Iterator iter = classNameCollector
0161: .getConflictingClassNames().iterator(); iter
0162: .hasNext();) {
0163: if (!first) {
0164: conflictList.append(", ");
0165: } else {
0166: first = false;
0167: }
0168: conflictList.append((String) iter.next());
0169: }
0170: error(
0171: document.getDefinitions(),
0172: ModelerMessages
0173: .WSDLMODELER_UNSOLVABLE_NAMING_CONFLICTS(conflictList
0174: .toString()));
0175: } catch (ModelException e) {
0176: reportError(document.getDefinitions(), e.getMessage(), e);
0177: } catch (ParseException e) {
0178: errReceiver.error(e);
0179: } catch (ValidationException e) {
0180: errReceiver.error(e.getMessage(), e);
0181: } catch (SAXException e) {
0182: errReceiver.error(e);
0183: } catch (IOException e) {
0184: errReceiver.error(e);
0185: }
0186: //should never reach here
0187: return null;
0188: }
0189:
0190: private Model internalBuildModel(WSDLDocument document) {
0191: numPasses++;
0192:
0193: //build the jaxbModel to be used latter
0194: buildJAXBModel(document);
0195:
0196: QName modelName = new QName(document.getDefinitions()
0197: .getTargetNamespaceURI(), document.getDefinitions()
0198: .getName() == null ? "model" : document
0199: .getDefinitions().getName());
0200: Model model = new Model(modelName, document.getDefinitions());
0201: model.setJAXBModel(getJAXBModelBuilder().getJAXBModel());
0202:
0203: // This fails with the changed classname (WSDLModeler to WSDLModeler11 etc.)
0204: // with this source comaptibility change the WSDL Modeler class name is changed. Right now hardcoding the
0205: // modeler class name to the same one being checked in WSDLGenerator.
0206:
0207: model.setProperty(ModelProperties.PROPERTY_MODELER_NAME,
0208: ModelProperties.WSDL_MODELER_NAME);
0209:
0210: _javaTypes = new JavaSimpleTypeCreator();
0211: _javaExceptions = new HashMap<String, JavaException>();
0212: _bindingNameToPortMap = new HashMap<QName, Port>();
0213:
0214: // grab target namespace
0215: model.setTargetNamespaceURI(document.getDefinitions()
0216: .getTargetNamespaceURI());
0217:
0218: setDocumentationIfPresent(model, document.getDefinitions()
0219: .getDocumentation());
0220:
0221: boolean hasServices = document.getDefinitions().services()
0222: .hasNext();
0223: if (hasServices) {
0224: for (Iterator iter = document.getDefinitions().services(); iter
0225: .hasNext();) {
0226: processService(
0227: (com.sun.tools.ws.wsdl.document.Service) iter
0228: .next(), model, document);
0229: hasServices = true;
0230: }
0231: } else {
0232: // emit a warning if there are no service definitions
0233: warning(model.getEntity(), ModelerMessages
0234: .WSDLMODELER_WARNING_NO_SERVICE_DEFINITIONS_FOUND());
0235: }
0236:
0237: return model;
0238: }
0239:
0240: /* (non-Javadoc)
0241: * @see WSDLModelerBase#processService(Service, Model, WSDLDocument)
0242: */
0243: protected void processService(
0244: com.sun.tools.ws.wsdl.document.Service wsdlService,
0245: Model model, WSDLDocument document) {
0246: String serviceInterface = "";
0247: QName serviceQName = getQNameOf(wsdlService);
0248: serviceInterface = getServiceInterfaceName(serviceQName,
0249: wsdlService);
0250: if (isConflictingServiceClassName(serviceInterface)) {
0251: serviceInterface += "_Service";
0252: }
0253: Service service = new Service(serviceQName, new JavaInterface(
0254: serviceInterface, serviceInterface + "Impl"),
0255: wsdlService);
0256:
0257: setDocumentationIfPresent(service, wsdlService
0258: .getDocumentation());
0259: boolean hasPorts = false;
0260: for (Iterator iter = wsdlService.ports(); iter.hasNext();) {
0261: boolean processed = processPort(
0262: (com.sun.tools.ws.wsdl.document.Port) iter.next(),
0263: service, document);
0264: hasPorts = hasPorts || processed;
0265: }
0266: if (!hasPorts) {
0267: // emit a warning if there are no ports
0268: warning(
0269: wsdlService,
0270: ModelerMessages
0271: .WSDLMODELER_WARNING_NO_PORTS_IN_SERVICE(wsdlService
0272: .getName()));
0273: } else {
0274: model.addService(service);
0275: }
0276: }
0277:
0278: /* (non-Javadoc)
0279: * @see WSDLModelerBase#processPort(WSDLPort, Service, WSDLDocument)
0280: */
0281: protected boolean processPort(
0282: com.sun.tools.ws.wsdl.document.Port wsdlPort,
0283: Service service, WSDLDocument document) {
0284: try {
0285:
0286: //clear the unique block map
0287: uniqueBodyBlocks.clear();
0288:
0289: QName portQName = getQNameOf(wsdlPort);
0290: Port port = new Port(portQName, wsdlPort);
0291:
0292: setDocumentationIfPresent(port, wsdlPort.getDocumentation());
0293:
0294: SOAPAddress soapAddress = (SOAPAddress) getExtensionOfType(
0295: wsdlPort, SOAPAddress.class);
0296: if (soapAddress == null) {
0297: if (options.isExtensionMode()) {
0298: warning(
0299: wsdlPort,
0300: ModelerMessages
0301: .WSDLMODELER_WARNING_NO_SOAP_ADDRESS(wsdlPort
0302: .getName()));
0303: } else {
0304: // not a SOAP port, ignore it
0305: warning(
0306: wsdlPort,
0307: ModelerMessages
0308: .WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT_NO_ADDRESS(wsdlPort
0309: .getName()));
0310: return false;
0311: }
0312: }
0313: if (soapAddress != null)
0314: port.setAddress(soapAddress.getLocation());
0315: Binding binding = wsdlPort.resolveBinding(document);
0316: QName bindingName = getQNameOf(binding);
0317: PortType portType = binding.resolvePortType(document);
0318:
0319: port.setProperty(ModelProperties.PROPERTY_WSDL_PORT_NAME,
0320: getQNameOf(wsdlPort));
0321: port.setProperty(
0322: ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
0323: getQNameOf(portType));
0324: port.setProperty(
0325: ModelProperties.PROPERTY_WSDL_BINDING_NAME,
0326: bindingName);
0327:
0328: boolean isProvider = isProvider(wsdlPort);
0329: if (_bindingNameToPortMap.containsKey(bindingName)
0330: && !isProvider) {
0331: // this binding has been processed before
0332: Port existingPort = _bindingNameToPortMap
0333: .get(bindingName);
0334: port.setOperations(existingPort.getOperations());
0335: port.setJavaInterface(existingPort.getJavaInterface());
0336: port.setStyle(existingPort.getStyle());
0337: port.setWrapped(existingPort.isWrapped());
0338: } else {
0339: // find out the SOAP binding extension, if any
0340: SOAPBinding soapBinding = (SOAPBinding) getExtensionOfType(
0341: binding, SOAPBinding.class);
0342:
0343: if (soapBinding == null) {
0344: soapBinding = (SOAPBinding) getExtensionOfType(
0345: binding, SOAP12Binding.class);
0346: if (soapBinding == null) {
0347: if (!options.isExtensionMode()) {
0348: // cannot deal with non-SOAP ports
0349: warning(
0350: wsdlPort,
0351: ModelerMessages
0352: .WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT(wsdlPort
0353: .getName()));
0354: return false;
0355: } else {
0356: warning(
0357: wsdlPort,
0358: ModelerMessages
0359: .WSDLMODELER_WARNING_NON_SOAP_PORT(wsdlPort
0360: .getName()));
0361: }
0362: } else {
0363: // we can only do soap1.2 if extensions are on
0364: if (options.isExtensionMode()) {
0365: warning(
0366: wsdlPort,
0367: ModelerMessages
0368: .WSDLMODELER_WARNING_PORT_SOAP_BINDING_12(wsdlPort
0369: .getName()));
0370: } else {
0371: warning(
0372: wsdlPort,
0373: ModelerMessages
0374: .WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_12(wsdlPort
0375: .getName()));
0376: return false;
0377: }
0378: }
0379: }
0380:
0381: if (soapBinding != null
0382: && (soapBinding.getTransport() == null || (!soapBinding
0383: .getTransport()
0384: .equals(
0385: SOAPConstants.URI_SOAP_TRANSPORT_HTTP) && !soapBinding
0386: .getTransport()
0387: .equals(
0388: SOAP12Constants.URI_SOAP_TRANSPORT_HTTP)))) {
0389: warning(
0390: wsdlPort,
0391: ModelerMessages
0392: .WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_NON_HTTP_TRANSPORT(wsdlPort
0393: .getName()));
0394: if (!options.isExtensionMode()) {
0395: // cannot deal with non-HTTP ports
0396: return false;
0397: }
0398: }
0399:
0400: /**
0401: * validate wsdl:binding uniqueness in style, e.g. rpclit or doclit
0402: * ref: WSI BP 1.1 R 2705
0403: */
0404: if (soapBinding != null
0405: && !validateWSDLBindingStyle(binding)) {
0406: if (options.isExtensionMode()) {
0407: warning(
0408: wsdlPort,
0409: ModelerMessages
0410: .WSDLMODELER_WARNING_PORT_SOAP_BINDING_MIXED_STYLE(wsdlPort
0411: .getName()));
0412: } else {
0413: error(
0414: wsdlPort,
0415: ModelerMessages
0416: .WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_MIXED_STYLE(wsdlPort
0417: .getName()));
0418: }
0419: }
0420:
0421: if (soapBinding != null) {
0422: port.setStyle(soapBinding.getStyle());
0423: }
0424:
0425: boolean hasOverloadedOperations = false;
0426: Set<String> operationNames = new HashSet<String>();
0427: for (Iterator iter = portType.operations(); iter
0428: .hasNext();) {
0429: com.sun.tools.ws.wsdl.document.Operation operation = (com.sun.tools.ws.wsdl.document.Operation) iter
0430: .next();
0431:
0432: if (operationNames.contains(operation.getName())) {
0433: hasOverloadedOperations = true;
0434: break;
0435: }
0436: operationNames.add(operation.getName());
0437:
0438: for (Iterator itr = binding.operations(); iter
0439: .hasNext();) {
0440: BindingOperation bindingOperation = (BindingOperation) itr
0441: .next();
0442: if (operation.getName().equals(
0443: bindingOperation.getName())) {
0444: break;
0445: } else if (!itr.hasNext()) {
0446: error(
0447: bindingOperation,
0448: ModelerMessages
0449: .WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(
0450: operation.getName(),
0451: bindingOperation
0452: .getName()));
0453: }
0454: }
0455: }
0456:
0457: Map headers = new HashMap();
0458: boolean hasOperations = false;
0459: for (Iterator iter = binding.operations(); iter
0460: .hasNext();) {
0461: BindingOperation bindingOperation = (BindingOperation) iter
0462: .next();
0463:
0464: com.sun.tools.ws.wsdl.document.Operation portTypeOperation = null;
0465: Set operations = portType
0466: .getOperationsNamed(bindingOperation
0467: .getName());
0468: if (operations.size() == 0) {
0469: // the WSDL document is invalid
0470: error(
0471: bindingOperation,
0472: ModelerMessages
0473: .WSDLMODELER_INVALID_BINDING_OPERATION_NOT_IN_PORT_TYPE(
0474: bindingOperation
0475: .getName(),
0476: binding.getName()));
0477: } else if (operations.size() == 1) {
0478: portTypeOperation = (com.sun.tools.ws.wsdl.document.Operation) operations
0479: .iterator().next();
0480: } else {
0481: boolean found = false;
0482: String expectedInputName = bindingOperation
0483: .getInput().getName();
0484: String expectedOutputName = bindingOperation
0485: .getOutput().getName();
0486:
0487: for (Iterator iter2 = operations.iterator(); iter2
0488: .hasNext();) {
0489: com.sun.tools.ws.wsdl.document.Operation candidateOperation = (com.sun.tools.ws.wsdl.document.Operation) iter2
0490: .next();
0491:
0492: if (expectedInputName == null) {
0493: // the WSDL document is invalid
0494: error(
0495: bindingOperation,
0496: ModelerMessages
0497: .WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_INPUT_NAME(bindingOperation
0498: .getName()));
0499: }
0500: if (expectedOutputName == null) {
0501: // the WSDL document is invalid
0502: error(
0503: bindingOperation,
0504: ModelerMessages
0505: .WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_OUTPUT_NAME(bindingOperation
0506: .getName()));
0507: }
0508: if (expectedInputName
0509: .equals(candidateOperation
0510: .getInput().getName())
0511: && expectedOutputName
0512: .equals(candidateOperation
0513: .getOutput()
0514: .getName())) {
0515: if (found) {
0516: // the WSDL document is invalid
0517: error(
0518: bindingOperation,
0519: ModelerMessages
0520: .WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_MATCHING_OPERATIONS(
0521: bindingOperation
0522: .getName(),
0523: bindingOperation
0524: .getName()));
0525: }
0526: // got it!
0527: found = true;
0528: portTypeOperation = candidateOperation;
0529: }
0530: }
0531: if (!found) {
0532: // the WSDL document is invalid
0533: error(
0534: bindingOperation,
0535: ModelerMessages
0536: .WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(
0537: bindingOperation
0538: .getName(),
0539: binding.getName()));
0540: }
0541: }
0542: if (!isProvider) {
0543: this .info = new ProcessSOAPOperationInfo(port,
0544: wsdlPort, portTypeOperation,
0545: bindingOperation, soapBinding,
0546: document, hasOverloadedOperations,
0547: headers);
0548:
0549: Operation operation;
0550: if (soapBinding != null)
0551: operation = processSOAPOperation();
0552: else {
0553: operation = processNonSOAPOperation();
0554: }
0555: if (operation != null) {
0556: port.addOperation(operation);
0557: hasOperations = true;
0558: }
0559: }
0560: }
0561: if (!isProvider && !hasOperations) {
0562: // emit a warning if there are no operations, except when its a provider port
0563: warning(
0564: wsdlPort,
0565: ModelerMessages
0566: .WSDLMODELER_WARNING_NO_OPERATIONS_IN_PORT(wsdlPort
0567: .getName()));
0568: return false;
0569: }
0570: createJavaInterfaceForPort(port, isProvider);
0571: PortType pt = binding.resolvePortType(document);
0572: String jd = (pt.getDocumentation() != null) ? pt
0573: .getDocumentation().getContent() : null;
0574: port.getJavaInterface().setJavaDoc(jd);
0575: _bindingNameToPortMap.put(bindingName, port);
0576: }
0577:
0578: service.addPort(port);
0579: applyPortMethodCustomization(port, wsdlPort);
0580: applyWrapperStyleCustomization(port, binding
0581: .resolvePortType(document));
0582:
0583: return true;
0584:
0585: } catch (NoSuchEntityException e) {
0586: warning(document.getDefinitions(), e.getMessage());
0587: // should not happen
0588: return false;
0589: }
0590: }
0591:
0592: /**
0593: * Returns an operation purely from abstract operation
0594: */
0595: private Operation processNonSOAPOperation() {
0596: Operation operation = new Operation(new QName(null,
0597: info.bindingOperation.getName()), info.bindingOperation);
0598:
0599: setDocumentationIfPresent(operation, info.portTypeOperation
0600: .getDocumentation());
0601:
0602: if (info.portTypeOperation.getStyle() != OperationStyle.REQUEST_RESPONSE
0603: && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
0604: if (options.isExtensionMode()) {
0605: warning(
0606: info.portTypeOperation,
0607: ModelerMessages
0608: .WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation
0609: .getName()));
0610: return null;
0611: } else {
0612: error(
0613: info.portTypeOperation,
0614: ModelerMessages
0615: .WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(
0616: info.portTypeOperation
0617: .getName(), info.port
0618: .resolveBinding(
0619: document)
0620: .resolvePortType(
0621: document)
0622: .getName()));
0623: }
0624: }
0625:
0626: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
0627: Message inputMessage = getInputMessage();
0628: Request request = new Request(inputMessage, errReceiver);
0629: request.setErrorReceiver(errReceiver);
0630: info.operation = operation;
0631: info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
0632:
0633: Response response = null;
0634:
0635: Message outputMessage = null;
0636: if (isRequestResponse) {
0637: outputMessage = getOutputMessage();
0638: response = new Response(outputMessage, errReceiver);
0639: } else {
0640: response = new Response(null, errReceiver);
0641: }
0642:
0643: //set the style based on heuristic that message has either all parts defined
0644: // using type(RPC) or element(DOCUMENT)
0645: setNonSoapStyle(inputMessage, outputMessage);
0646:
0647: // Process parameterOrder and get the parameterList
0648: List<MessagePart> parameterList = getParameterOrder();
0649:
0650: List<Parameter> params = null;
0651: boolean unwrappable = isUnwrappable();
0652: info.operation.setWrapped(unwrappable);
0653: params = getDoclitParameters(request, response, parameterList);
0654: if (!validateParameterName(params)) {
0655: return null;
0656: }
0657:
0658: // create a definitive list of parameters to match what we'd like to get
0659: // in the java interface (which is generated much later), parameterOrder
0660: List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
0661: for (Parameter param : params) {
0662: if (param.isReturn()) {
0663: info.operation
0664: .setProperty(WSDL_RESULT_PARAMETER, param);
0665: response.addParameter(param);
0666: continue;
0667: }
0668: if (param.isIN()) {
0669: request.addParameter(param);
0670: } else if (param.isOUT()) {
0671: response.addParameter(param);
0672: } else if (param.isINOUT()) {
0673: request.addParameter(param);
0674: response.addParameter(param);
0675: }
0676: definitiveParameterList.add(param);
0677: }
0678:
0679: info.operation.setRequest(request);
0680:
0681: if (isRequestResponse) {
0682: info.operation.setResponse(response);
0683: }
0684:
0685: // faults with duplicate names
0686: Set duplicateNames = getDuplicateFaultNames();
0687:
0688: // handle soap:fault
0689: handleLiteralSOAPFault(response, duplicateNames);
0690: info.operation.setProperty(WSDL_PARAMETER_ORDER,
0691: definitiveParameterList);
0692:
0693: Binding binding = info.port.resolveBinding(document);
0694: PortType portType = binding.resolvePortType(document);
0695: if (isAsync(portType, info.portTypeOperation)) {
0696: warning(portType,
0697: "Can not generate Async methods for non-soap binding!");
0698: }
0699: return info.operation;
0700: }
0701:
0702: /**
0703: * This method is added to fix one of the use case for j2ee se folks, so that we determine
0704: * for non_soap wsdl what could be the style - rpc or document based on parts in the message.
0705: *
0706: * We assume that the message parts could have either all of them with type attribute (RPC)
0707: * or element (DOCUMENT)
0708: *
0709: * Shall this check if parts are mixed and throw error message?
0710: */
0711: private void setNonSoapStyle(Message inputMessage,
0712: Message outputMessage) {
0713: SOAPStyle style = SOAPStyle.DOCUMENT;
0714: for (MessagePart part : inputMessage.getParts()) {
0715: if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
0716: style = SOAPStyle.RPC;
0717: else
0718: style = SOAPStyle.DOCUMENT;
0719: }
0720:
0721: //check the outputMessage parts
0722: if (outputMessage != null) {
0723: for (MessagePart part : outputMessage.getParts()) {
0724: if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
0725: style = SOAPStyle.RPC;
0726: else
0727: style = SOAPStyle.DOCUMENT;
0728: }
0729: }
0730: info.modelPort.setStyle(style);
0731: }
0732:
0733: /* (non-Javadoc)
0734: * @see WSDLModelerBase#processSOAPOperation()
0735: */
0736: protected Operation processSOAPOperation() {
0737: Operation operation = new Operation(new QName(null,
0738: info.bindingOperation.getName()), info.bindingOperation);
0739:
0740: setDocumentationIfPresent(operation, info.portTypeOperation
0741: .getDocumentation());
0742:
0743: if (info.portTypeOperation.getStyle() != OperationStyle.REQUEST_RESPONSE
0744: && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
0745: if (options.isExtensionMode()) {
0746: warning(
0747: info.portTypeOperation,
0748: ModelerMessages
0749: .WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation
0750: .getName()));
0751: return null;
0752: } else {
0753: error(
0754: info.portTypeOperation,
0755: ModelerMessages
0756: .WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(
0757: info.portTypeOperation
0758: .getName(), info.port
0759: .resolveBinding(
0760: document)
0761: .resolvePortType(
0762: document)
0763: .getName()));
0764: }
0765: }
0766:
0767: SOAPStyle soapStyle = info.soapBinding.getStyle();
0768:
0769: // find out the SOAP operation extension, if any
0770: SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
0771: info.bindingOperation, SOAPOperation.class);
0772:
0773: if (soapOperation != null) {
0774: if (soapOperation.getStyle() != null) {
0775: soapStyle = soapOperation.getStyle();
0776: }
0777: if (soapOperation.getSOAPAction() != null) {
0778: operation.setSOAPAction(soapOperation.getSOAPAction());
0779: }
0780: }
0781:
0782: operation.setStyle(soapStyle);
0783:
0784: String uniqueOperationName = getUniqueName(
0785: info.portTypeOperation, info.hasOverloadedOperations);
0786: if (info.hasOverloadedOperations) {
0787: operation.setUniqueName(uniqueOperationName);
0788: }
0789:
0790: info.operation = operation;
0791: info.uniqueOperationName = uniqueOperationName;
0792:
0793: //attachment
0794: SOAPBody soapRequestBody = getSOAPRequestBody();
0795: if (soapRequestBody == null) {
0796: // the WSDL document is invalid
0797: error(
0798: info.bindingOperation,
0799: ModelerMessages
0800: .WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation
0801: .getName()));
0802: }
0803:
0804: if (soapStyle == SOAPStyle.RPC) {
0805: if (soapRequestBody.isEncoded()) {
0806: error(soapRequestBody, ModelerMessages
0807: .WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
0808: }
0809: return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
0810: }
0811: // document style
0812: return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
0813: }
0814:
0815: protected Operation processLiteralSOAPOperation(
0816: StyleAndUse styleAndUse) {
0817: //returns false if the operation name is not acceptable
0818: if (!applyOperationNameCustomization())
0819: return null;
0820:
0821: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
0822: Message inputMessage = getInputMessage();
0823: Request request = new Request(inputMessage, errReceiver);
0824: request.setErrorReceiver(errReceiver);
0825: info.operation.setUse(SOAPUse.LITERAL);
0826: info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
0827: SOAPBody soapRequestBody = getSOAPRequestBody();
0828: if ((StyleAndUse.DOC_LITERAL == styleAndUse)
0829: && (soapRequestBody.getNamespace() != null)) {
0830: warning(soapRequestBody, ModelerMessages
0831: .WSDLMODELER_WARNING_R_2716("soapbind:body",
0832: info.bindingOperation.getName()));
0833: }
0834:
0835: Response response = null;
0836:
0837: SOAPBody soapResponseBody = null;
0838: Message outputMessage = null;
0839: if (isRequestResponse) {
0840: soapResponseBody = getSOAPResponseBody();
0841: if (isOperationDocumentLiteral(styleAndUse)
0842: && (soapResponseBody.getNamespace() != null)) {
0843: warning(soapResponseBody, ModelerMessages
0844: .WSDLMODELER_WARNING_R_2716("soapbind:body",
0845: info.bindingOperation.getName()));
0846: }
0847: outputMessage = getOutputMessage();
0848: response = new Response(outputMessage, errReceiver);
0849: } else {
0850: response = new Response(null, errReceiver);
0851: }
0852:
0853: //ignore operation if there are more than one root part
0854: if (!validateMimeParts(getMimeParts(info.bindingOperation
0855: .getInput()))
0856: || !validateMimeParts(getMimeParts(info.bindingOperation
0857: .getOutput())))
0858: return null;
0859:
0860: if (!validateBodyParts(info.bindingOperation)) {
0861: // BP 1.1
0862: // R2204 A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s),
0863: // only to wsdl:part element(s) that have been defined using the element attribute.
0864:
0865: // R2203 An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s),
0866: // only to wsdNl:part element(s) that have been defined using the type attribute.
0867: if (isOperationDocumentLiteral(styleAndUse))
0868: if (options.isExtensionMode())
0869: warning(
0870: info.portTypeOperation,
0871: ModelerMessages
0872: .WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_TYPE_MESSAGE_PART(info.portTypeOperation
0873: .getName()));
0874: else
0875: error(
0876: info.portTypeOperation,
0877: ModelerMessages
0878: .WSDLMODELER_INVALID_DOCLITOPERATION(info.portTypeOperation
0879: .getName()));
0880: else if (isOperationRpcLiteral(styleAndUse)) {
0881: if (options.isExtensionMode())
0882: warning(
0883: info.portTypeOperation,
0884: ModelerMessages
0885: .WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_ELEMENT_MESSAGE_PART(info.portTypeOperation
0886: .getName()));
0887: else
0888: error(
0889: info.portTypeOperation,
0890: ModelerMessages
0891: .WSDLMODELER_INVALID_RPCLITOPERATION(info.portTypeOperation
0892: .getName()));
0893: }
0894: return null;
0895: }
0896:
0897: // Process parameterOrder and get the parameterList
0898: List<MessagePart> parameterList = getParameterOrder();
0899:
0900: //binding is invalid in the wsdl, ignore the operation.
0901: if (!setMessagePartsBinding(styleAndUse))
0902: return null;
0903:
0904: List<Parameter> params = null;
0905: boolean unwrappable = isUnwrappable();
0906: info.operation.setWrapped(unwrappable);
0907: if (isOperationDocumentLiteral(styleAndUse)) {
0908: params = getDoclitParameters(request, response,
0909: parameterList);
0910: } else if (isOperationRpcLiteral(styleAndUse)) {
0911: String operationName = info.bindingOperation.getName();
0912: Block reqBlock = null;
0913: if (inputMessage != null) {
0914: QName name = new QName(
0915: getRequestNamespaceURI(soapRequestBody),
0916: operationName);
0917: RpcLitStructure rpcStruct = new RpcLitStructure(name,
0918: getJAXBModelBuilder().getJAXBModel());
0919: rpcStruct.setJavaType(new JavaSimpleType(
0920: "com.sun.xml.ws.encoding.jaxb.RpcLitPayload",
0921: null));
0922: reqBlock = new Block(name, rpcStruct, inputMessage);
0923: request.addBodyBlock(reqBlock);
0924: }
0925:
0926: Block resBlock = null;
0927: if (isRequestResponse && outputMessage != null) {
0928: QName name = new QName(
0929: getResponseNamespaceURI(soapResponseBody),
0930: operationName + "Response");
0931: RpcLitStructure rpcStruct = new RpcLitStructure(name,
0932: getJAXBModelBuilder().getJAXBModel());
0933: rpcStruct.setJavaType(new JavaSimpleType(
0934: "com.sun.xml.ws.encoding.jaxb.RpcLitPayload",
0935: null));
0936: resBlock = new Block(name, rpcStruct, outputMessage);
0937: response.addBodyBlock(resBlock);
0938: }
0939: params = getRpcLitParameters(request, response, reqBlock,
0940: resBlock, parameterList);
0941: }
0942:
0943: if (!validateParameterName(params)) {
0944: return null;
0945: }
0946:
0947: // create a definitive list of parameters to match what we'd like to get
0948: // in the java interface (which is generated much later), parameterOrder
0949: List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
0950: for (Parameter param : params) {
0951: if (param.isReturn()) {
0952: info.operation
0953: .setProperty(WSDL_RESULT_PARAMETER, param);
0954: response.addParameter(param);
0955: continue;
0956: }
0957: if (param.isIN()) {
0958: request.addParameter(param);
0959: } else if (param.isOUT()) {
0960: response.addParameter(param);
0961: } else if (param.isINOUT()) {
0962: request.addParameter(param);
0963: response.addParameter(param);
0964: }
0965: definitiveParameterList.add(param);
0966: }
0967:
0968: info.operation.setRequest(request);
0969:
0970: if (isRequestResponse) {
0971: info.operation.setResponse(response);
0972: }
0973:
0974: Iterator<Block> bb = request.getBodyBlocks();
0975: QName body = VOID_BODYBLOCK;
0976: QName opName = null;
0977:
0978: Operation thatOp;
0979: if (bb.hasNext()) {
0980: body = bb.next().getName();
0981: thatOp = uniqueBodyBlocks.get(body);
0982: } else {
0983: //there is no body block
0984: body = VOID_BODYBLOCK;
0985: thatOp = uniqueBodyBlocks.get(VOID_BODYBLOCK);
0986: }
0987:
0988: if (thatOp != null) {
0989: if (options.isExtensionMode()) {
0990: warning(info.port, ModelerMessages
0991: .WSDLMODELER_NON_UNIQUE_BODY_WARNING(info.port
0992: .getName(), info.operation.getName(),
0993: thatOp.getName(), body));
0994: } else {
0995: error(info.port, ModelerMessages
0996: .WSDLMODELER_NON_UNIQUE_BODY_ERROR(info.port
0997: .getName(), info.operation.getName(),
0998: thatOp.getName(), body));
0999: }
1000: } else {
1001: uniqueBodyBlocks.put(body, info.operation);
1002: }
1003:
1004: // faults with duplicate names
1005: Set duplicateNames = getDuplicateFaultNames();
1006:
1007: // handle soap:fault
1008: handleLiteralSOAPFault(response, duplicateNames);
1009: info.operation.setProperty(WSDL_PARAMETER_ORDER,
1010: definitiveParameterList);
1011:
1012: //set Async property
1013: Binding binding = info.port.resolveBinding(document);
1014: PortType portType = binding.resolvePortType(document);
1015: if (isAsync(portType, info.portTypeOperation)) {
1016: addAsyncOperations(info.operation, styleAndUse);
1017: }
1018:
1019: return info.operation;
1020: }
1021:
1022: private boolean validateParameterName(List<Parameter> params) {
1023: if (options.isExtensionMode())
1024: return true;
1025:
1026: Message msg = getInputMessage();
1027: for (Parameter param : params) {
1028: if (param.isOUT())
1029: continue;
1030: if (param.getCustomName() != null) {
1031: if (Names.isJavaReservedWord(param.getCustomName())) {
1032: error(
1033: param.getEntity(),
1034: ModelerMessages
1035: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(
1036: info.operation.getName(),
1037: param.getCustomName()));
1038: return false;
1039: }
1040: return true;
1041: }
1042: //process doclit wrapper style
1043: if (param.isEmbedded()
1044: && !(param.getBlock().getType() instanceof RpcLitStructure)) {
1045: if (Names.isJavaReservedWord(param.getName())) {
1046: error(
1047: param.getEntity(),
1048: ModelerMessages
1049: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(
1050: info.operation.getName(),
1051: param.getName(), param
1052: .getBlock()
1053: .getName()));
1054: return false;
1055: }
1056: } else {
1057: //non-wrapper style and rpclit
1058: if (Names.isJavaReservedWord(param.getName())) {
1059: error(
1060: param.getEntity(),
1061: ModelerMessages
1062: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(
1063: info.operation.getName(),
1064: msg.getName(), param
1065: .getName()));
1066: return false;
1067: }
1068: }
1069: }
1070:
1071: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1072: if (isRequestResponse) {
1073: msg = getOutputMessage();
1074: for (Parameter param : params) {
1075: if (param.isIN())
1076: continue;
1077: if (param.getCustomName() != null) {
1078: if (Names.isJavaReservedWord(param.getCustomName())) {
1079: error(
1080: param.getEntity(),
1081: ModelerMessages
1082: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(
1083: info.operation
1084: .getName(),
1085: param.getCustomName()));
1086: return false;
1087: }
1088: return true;
1089: }
1090: //process doclit wrapper style
1091: if (param.isEmbedded()
1092: && !(param.getBlock().getType() instanceof RpcLitStructure)) {
1093: if (param.isReturn())
1094: continue;
1095: if (!param.getName().equals("return")
1096: && Names
1097: .isJavaReservedWord(param.getName())) {
1098: error(
1099: param.getEntity(),
1100: ModelerMessages
1101: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(
1102: info.operation
1103: .getName(),
1104: param.getName(), param
1105: .getBlock()
1106: .getName()));
1107: return false;
1108: }
1109: } else {
1110: if (param.isReturn())
1111: continue;
1112:
1113: //non-wrapper style and rpclit
1114: if (Names.isJavaReservedWord(param.getName())) {
1115: error(
1116: param.getEntity(),
1117: ModelerMessages
1118: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(
1119: info.operation
1120: .getName(), msg
1121: .getName(),
1122: param.getName()));
1123: return false;
1124: }
1125: }
1126: }
1127: }
1128:
1129: return true;
1130: }
1131:
1132: private boolean enableMimeContent() {
1133: //first we look at binding operation
1134: JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1135: info.bindingOperation, JAXWSBinding.class);
1136: Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
1137: .isEnableMimeContentMapping()
1138: : null;
1139: if (mimeContentMapping != null)
1140: return mimeContentMapping;
1141:
1142: //then in wsdl:binding
1143: Binding binding = info.port.resolveBinding(info.document);
1144: jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding,
1145: JAXWSBinding.class);
1146: mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
1147: .isEnableMimeContentMapping()
1148: : null;
1149: if (mimeContentMapping != null)
1150: return mimeContentMapping;
1151:
1152: //at last look in wsdl:definitions
1153: jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1154: info.document.getDefinitions(), JAXWSBinding.class);
1155: mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
1156: .isEnableMimeContentMapping()
1157: : null;
1158: if (mimeContentMapping != null)
1159: return mimeContentMapping;
1160: return false;
1161: }
1162:
1163: private boolean applyOperationNameCustomization() {
1164: JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1165: info.portTypeOperation, JAXWSBinding.class);
1166: String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization
1167: .getMethodName() != null) ? jaxwsCustomization
1168: .getMethodName().getName() : null)
1169: : null;
1170: if (operationName != null) {
1171: if (Names.isJavaReservedWord(operationName)) {
1172: if (options.isExtensionMode())
1173: warning(
1174: info.portTypeOperation,
1175: ModelerMessages
1176: .WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(
1177: info.operation.getName(),
1178: operationName));
1179: else
1180: error(
1181: info.portTypeOperation,
1182: ModelerMessages
1183: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(
1184: info.operation.getName(),
1185: operationName));
1186: return false;
1187: }
1188:
1189: info.operation.setCustomizedName(operationName);
1190: }
1191:
1192: if (Names
1193: .isJavaReservedWord(info.operation.getJavaMethodName())) {
1194: if (options.isExtensionMode())
1195: warning(
1196: info.portTypeOperation,
1197: ModelerMessages
1198: .WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation
1199: .getName()));
1200: else
1201: error(
1202: info.portTypeOperation,
1203: ModelerMessages
1204: .WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation
1205: .getName()));
1206: return false;
1207: }
1208: return true;
1209: }
1210:
1211: protected String getAsyncOperationName(Operation operation) {
1212: String name = operation.getCustomizedName();
1213: if (name == null)
1214: name = operation.getUniqueName();
1215: return name;
1216: }
1217:
1218: /**
1219: * @param styleAndUse
1220: */
1221: private void addAsyncOperations(Operation syncOperation,
1222: StyleAndUse styleAndUse) {
1223: Operation operation = createAsyncOperation(syncOperation,
1224: styleAndUse, AsyncOperationType.POLLING);
1225: if (operation != null)
1226: info.modelPort.addOperation(operation);
1227:
1228: operation = createAsyncOperation(syncOperation, styleAndUse,
1229: AsyncOperationType.CALLBACK);
1230: if (operation != null)
1231: info.modelPort.addOperation(operation);
1232: }
1233:
1234: private Operation createAsyncOperation(Operation syncOperation,
1235: StyleAndUse styleAndUse, AsyncOperationType asyncType) {
1236: boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1237: if (!isRequestResponse)
1238: return null;
1239:
1240: //create async operations
1241: AsyncOperation operation = new AsyncOperation(info.operation,
1242: info.bindingOperation);
1243:
1244: //creation the async operation name: operationName+Async or customized name
1245: //operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
1246: if (asyncType.equals(AsyncOperationType.CALLBACK))
1247: operation.setUniqueName(info.operation.getUniqueName()
1248: + "_async_callback");
1249: else if (asyncType.equals(AsyncOperationType.POLLING))
1250: operation.setUniqueName(info.operation.getUniqueName()
1251: + "_async_polling");
1252:
1253: setDocumentationIfPresent(operation, info.portTypeOperation
1254: .getDocumentation());
1255:
1256: operation.setAsyncType(asyncType);
1257: operation.setSOAPAction(info.operation.getSOAPAction());
1258: boolean unwrappable = info.operation.isWrapped();
1259: operation.setWrapped(unwrappable);
1260: SOAPBody soapRequestBody = getSOAPRequestBody();
1261:
1262: Message inputMessage = getInputMessage();
1263: Request request = new Request(inputMessage, errReceiver);
1264: Response response = new Response(null, errReceiver);
1265:
1266: SOAPBody soapResponseBody = null;
1267: Message outputMessage = null;
1268: if (isRequestResponse) {
1269: soapResponseBody = getSOAPResponseBody();
1270: outputMessage = getOutputMessage();
1271: response = new Response(outputMessage, errReceiver);
1272: }
1273:
1274: // Process parameterOrder and get the parameterList
1275: java.util.List<String> parameterList = getAsynParameterOrder();
1276:
1277: List<Parameter> inParameters = null;
1278: if (isOperationDocumentLiteral(styleAndUse)) {
1279: inParameters = getRequestParameters(request, parameterList);
1280: // outParameters = getResponseParameters(response);
1281: // re-create parameterList with unwrapped parameters
1282: if (unwrappable) {
1283: List<String> unwrappedParameterList = new ArrayList<String>();
1284: if (inputMessage != null) {
1285: Iterator<MessagePart> parts = inputMessage.parts();
1286: if (parts.hasNext()) {
1287: MessagePart part = parts.next();
1288: JAXBType jaxbType = getJAXBType(part);
1289: List<JAXBProperty> memberList = jaxbType
1290: .getWrapperChildren();
1291: Iterator<JAXBProperty> props = memberList
1292: .iterator();
1293: while (props.hasNext()) {
1294: JAXBProperty prop = props.next();
1295: unwrappedParameterList.add(prop
1296: .getElementName().getLocalPart());
1297: }
1298: }
1299: }
1300:
1301: parameterList.clear();
1302: parameterList.addAll(unwrappedParameterList);
1303: }
1304: } else if (isOperationRpcLiteral(styleAndUse)) {
1305: String operationName = info.bindingOperation.getName();
1306: Block reqBlock = null;
1307: if (inputMessage != null) {
1308: QName name = new QName(
1309: getRequestNamespaceURI(soapRequestBody),
1310: operationName);
1311: RpcLitStructure rpcStruct = new RpcLitStructure(name,
1312: getJAXBModelBuilder().getJAXBModel());
1313: rpcStruct.setJavaType(new JavaSimpleType(
1314: "com.sun.xml.ws.encoding.jaxb.RpcLitPayload",
1315: null));
1316: reqBlock = new Block(name, rpcStruct, inputMessage);
1317: request.addBodyBlock(reqBlock);
1318: }
1319: inParameters = createRpcLitRequestParameters(request,
1320: parameterList, reqBlock);
1321: }
1322:
1323: // add response blocks, we dont need to create respnse parameters, just blocks will be fine, lets
1324: // copy them from sync optraions
1325: //copy the response blocks from the sync operation
1326: Iterator<Block> blocks = info.operation.getResponse()
1327: .getBodyBlocks();
1328:
1329: while (blocks.hasNext()) {
1330: response.addBodyBlock(blocks.next());
1331: }
1332:
1333: blocks = info.operation.getResponse().getHeaderBlocks();
1334: while (blocks.hasNext()) {
1335: response.addHeaderBlock(blocks.next());
1336: }
1337:
1338: blocks = info.operation.getResponse().getAttachmentBlocks();
1339: while (blocks.hasNext()) {
1340: response.addAttachmentBlock(blocks.next());
1341: }
1342:
1343: List<MessagePart> outputParts = outputMessage.getParts();
1344:
1345: // handle headers
1346: int numOfOutMsgParts = outputParts.size();
1347:
1348: if (isRequestResponse) {
1349: if (numOfOutMsgParts == 1) {
1350: MessagePart part = outputParts.get(0);
1351: if (isOperationDocumentLiteral(styleAndUse)) {
1352: JAXBType type = getJAXBType(part);
1353: operation.setResponseBean(type);
1354: } else if (isOperationRpcLiteral(styleAndUse)) {
1355: String operationName = info.bindingOperation
1356: .getName();
1357: Block resBlock = null;
1358: if (isRequestResponse && outputMessage != null) {
1359: resBlock = info.operation
1360: .getResponse()
1361: .getBodyBlocksMap()
1362: .get(
1363: new QName(
1364: getResponseNamespaceURI(soapResponseBody),
1365: operationName
1366: + "Response"));
1367: }
1368: RpcLitStructure resBean = (resBlock == null) ? null
1369: : (RpcLitStructure) resBlock.getType();
1370: List<RpcLitMember> members = resBean
1371: .getRpcLitMembers();
1372:
1373: operation.setResponseBean(members.get(0));
1374: }
1375: } else {
1376: //create response bean
1377: String nspace = "";
1378: QName responseBeanName = new QName(nspace,
1379: getAsyncOperationName(info.operation)
1380: + "Response");
1381: JAXBType responseBeanType = jaxbModelBuilder
1382: .getJAXBType(responseBeanName);
1383: if (responseBeanType == null) {
1384: error(
1385: info.operation.getEntity(),
1386: ModelerMessages
1387: .WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation
1388: .getName()));
1389: }
1390: operation.setResponseBean(responseBeanType);
1391: }
1392: }
1393: QName respBeanName = new QName(soapResponseBody.getNamespace(),
1394: getAsyncOperationName(info.operation) + "Response");
1395: Block block = new Block(respBeanName, operation
1396: .getResponseBeanType(), outputMessage);
1397: JavaType respJavaType = operation.getResponseBeanJavaType();
1398: JAXBType respType = new JAXBType(respBeanName, respJavaType);
1399: Parameter respParam = ModelerUtils.createParameter(
1400: info.operation.getName() + "Response", respType, block);
1401: respParam.setParameterIndex(-1);
1402: response.addParameter(respParam);
1403: operation.setProperty(WSDL_RESULT_PARAMETER, respParam
1404: .getName());
1405:
1406: List<String> definitiveParameterList = new ArrayList<String>();
1407: int parameterOrderPosition = 0;
1408: for (String name : parameterList) {
1409: Parameter inParameter = null;
1410:
1411: inParameter = ModelerUtils.getParameter(name, inParameters);
1412: if (inParameter == null) {
1413: if (options.isExtensionMode())
1414: warning(
1415: info.operation.getEntity(),
1416: ModelerMessages
1417: .WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(
1418: info.operation.getName()
1419: .getLocalPart(),
1420: name));
1421: else
1422: error(info.operation.getEntity(), ModelerMessages
1423: .WSDLMODELER_ERROR_PART_NOT_FOUND(
1424: info.operation.getName()
1425: .getLocalPart(), name));
1426: return null;
1427: }
1428: request.addParameter(inParameter);
1429: inParameter.setParameterIndex(parameterOrderPosition);
1430: definitiveParameterList.add(name);
1431: parameterOrderPosition++;
1432: }
1433:
1434: if (isRequestResponse) {
1435: operation.setResponse(response);
1436: }
1437:
1438: // add callback handlerb Parameter to request
1439: if (operation.getAsyncType()
1440: .equals(AsyncOperationType.CALLBACK)) {
1441: JavaType cbJavaType = operation.getCallBackType();
1442: JAXBType callbackType = new JAXBType(respBeanName,
1443: cbJavaType);
1444: Parameter cbParam = ModelerUtils.createParameter(
1445: "asyncHandler", callbackType, block);
1446: request.addParameter(cbParam);
1447: }
1448:
1449: operation.setRequest(request);
1450:
1451: return operation;
1452: }
1453:
1454: protected boolean isAsync(
1455: com.sun.tools.ws.wsdl.document.PortType portType,
1456: com.sun.tools.ws.wsdl.document.Operation wsdlOperation) {
1457: //First look into wsdl:operation
1458: JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1459: wsdlOperation, JAXWSBinding.class);
1460: Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1461: .isEnableAsyncMapping()
1462: : null;
1463:
1464: if (isAsync != null)
1465: return isAsync;
1466:
1467: // then into wsdl:portType
1468: QName portTypeName = new QName(portType.getDefining()
1469: .getTargetNamespaceURI(), portType.getName());
1470: if (portTypeName != null) {
1471: jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1472: portType, JAXWSBinding.class);
1473: isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1474: .isEnableAsyncMapping() : null;
1475: if (isAsync != null)
1476: return isAsync;
1477: }
1478:
1479: //then wsdl:definitions
1480: jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document
1481: .getDefinitions(), JAXWSBinding.class);
1482: isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1483: .isEnableAsyncMapping() : null;
1484: if (isAsync != null)
1485: return isAsync;
1486: return false;
1487: }
1488:
1489: protected void handleLiteralSOAPHeaders(Request request,
1490: Response response, Iterator headerParts,
1491: Set duplicateNames, List<String> definitiveParameterList,
1492: boolean processRequest) {
1493: QName headerName = null;
1494: Block headerBlock = null;
1495: JAXBType jaxbType = null;
1496: int parameterOrderPosition = definitiveParameterList.size();
1497: while (headerParts.hasNext()) {
1498: MessagePart part = (MessagePart) headerParts.next();
1499: headerName = part.getDescriptor();
1500: jaxbType = getJAXBType(part);
1501: headerBlock = new Block(headerName, jaxbType, part);
1502: TWSDLExtensible ext;
1503: if (processRequest) {
1504: ext = info.bindingOperation.getInput();
1505: } else {
1506: ext = info.bindingOperation.getOutput();
1507: }
1508: Message headerMessage = getHeaderMessage(part, ext);
1509:
1510: if (processRequest) {
1511: request.addHeaderBlock(headerBlock);
1512: } else {
1513: response.addHeaderBlock(headerBlock);
1514: }
1515:
1516: Parameter parameter = ModelerUtils.createParameter(part
1517: .getName(), jaxbType, headerBlock);
1518: parameter.setParameterIndex(parameterOrderPosition);
1519: setCustomizedParameterName(info.bindingOperation,
1520: headerMessage, part, parameter, false);
1521: if (processRequest && definitiveParameterList != null) {
1522: request.addParameter(parameter);
1523: definitiveParameterList.add(parameter.getName());
1524: } else {
1525: if (definitiveParameterList != null) {
1526: for (Iterator iterInParams = definitiveParameterList
1527: .iterator(); iterInParams.hasNext();) {
1528: String inParamName = (String) iterInParams
1529: .next();
1530: if (inParamName.equals(parameter.getName())) {
1531: Parameter inParam = request
1532: .getParameterByName(inParamName);
1533: parameter.setLinkedParameter(inParam);
1534: inParam.setLinkedParameter(parameter);
1535: //its in/out parameter, input and output parameter have the same order position.
1536: parameter.setParameterIndex(inParam
1537: .getParameterIndex());
1538: }
1539: }
1540: if (!definitiveParameterList.contains(parameter
1541: .getName())) {
1542: definitiveParameterList
1543: .add(parameter.getName());
1544: }
1545: }
1546: response.addParameter(parameter);
1547: }
1548: parameterOrderPosition++;
1549: }
1550:
1551: }
1552:
1553: protected void handleLiteralSOAPFault(Response response,
1554: Set duplicateNames) {
1555: for (BindingFault bindingFault : info.bindingOperation.faults()) {
1556: com.sun.tools.ws.wsdl.document.Fault portTypeFault = null;
1557: for (com.sun.tools.ws.wsdl.document.Fault aFault : info.portTypeOperation
1558: .faults()) {
1559: if (aFault.getName().equals(bindingFault.getName())) {
1560: if (portTypeFault != null) {
1561: // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
1562: error(
1563: portTypeFault,
1564: ModelerMessages
1565: .WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(
1566: bindingFault.getName(),
1567: info.bindingOperation
1568: .getName()));
1569: }
1570: portTypeFault = aFault;
1571: }
1572: }
1573:
1574: // The WSDL document is invalid, the wsdl:fault in abstract operation is does not have any binding
1575: if (portTypeFault == null) {
1576: error(bindingFault, ModelerMessages
1577: .WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(
1578: bindingFault.getName(),
1579: info.bindingOperation.getName()));
1580:
1581: }
1582:
1583: // wsdl:fault message name is used to create the java exception name later on
1584: String faultName = getFaultClassName(portTypeFault);
1585: Fault fault = new Fault(faultName, portTypeFault);
1586: fault.setWsdlFaultName(portTypeFault.getName());
1587: setDocumentationIfPresent(fault, portTypeFault
1588: .getDocumentation());
1589:
1590: //get the soapbind:fault from wsdl:fault in the binding
1591: SOAPFault soapFault = (SOAPFault) getExtensionOfType(
1592: bindingFault, SOAPFault.class);
1593:
1594: // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
1595: if (soapFault == null) {
1596: if (options.isExtensionMode()) {
1597: warning(
1598: bindingFault,
1599: ModelerMessages
1600: .WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(
1601: bindingFault.getName(),
1602: info.bindingOperation
1603: .getName()));
1604: soapFault = new SOAPFault(new LocatorImpl());
1605: } else {
1606: error(
1607: bindingFault,
1608: ModelerMessages
1609: .WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(
1610: bindingFault.getName(),
1611: info.bindingOperation
1612: .getName()));
1613: }
1614: }
1615:
1616: //the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
1617: if (!soapFault.isLiteral()) {
1618: if (options.isExtensionMode())
1619: warning(
1620: soapFault,
1621: ModelerMessages
1622: .WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(
1623: bindingFault.getName(),
1624: info.bindingOperation
1625: .getName()));
1626: else
1627: error(
1628: soapFault,
1629: ModelerMessages
1630: .WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(
1631: bindingFault.getName(),
1632: info.bindingOperation
1633: .getName()));
1634: continue;
1635: }
1636:
1637: // the soapFault name must be present
1638: if (soapFault.getName() == null) {
1639: warning(
1640: bindingFault,
1641: ModelerMessages
1642: .WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(
1643: bindingFault.getName(),
1644: info.bindingOperation.getName()));
1645: } else if (!soapFault.getName().equals(
1646: bindingFault.getName())) {
1647: warning(
1648: soapFault,
1649: ModelerMessages
1650: .WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(
1651: soapFault.getName(),
1652: bindingFault.getName(),
1653: info.bindingOperation.getName()));
1654: } else if (soapFault.getNamespace() != null) {
1655: warning(soapFault, ModelerMessages
1656: .WSDLMODELER_WARNING_R_2716_R_2726(
1657: "soapbind:fault", soapFault.getName()));
1658: }
1659:
1660: String faultNamespaceURI = soapFault.getNamespace();
1661: if (faultNamespaceURI == null) {
1662: faultNamespaceURI = portTypeFault.getMessage()
1663: .getNamespaceURI();
1664: }
1665:
1666: com.sun.tools.ws.wsdl.document.Message faultMessage = portTypeFault
1667: .resolveMessage(info.document);
1668: Iterator iter2 = faultMessage.parts();
1669: if (!iter2.hasNext()) {
1670: // the WSDL document is invalid
1671: error(
1672: faultMessage,
1673: ModelerMessages
1674: .WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(
1675: bindingFault.getName(),
1676: faultMessage.getName()));
1677: }
1678: MessagePart faultPart = (MessagePart) iter2.next();
1679: QName faultQName = faultPart.getDescriptor();
1680:
1681: // Don't include fault messages with non-unique soap:fault names
1682: if (duplicateNames.contains(faultQName)) {
1683: warning(faultPart, ModelerMessages
1684: .WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(
1685: bindingFault.getName(),
1686: info.portTypeOperation.getName(),
1687: faultPart.getName()));
1688: continue;
1689: }
1690:
1691: if (iter2.hasNext()) {
1692: // the WSDL document is invalid
1693: error(
1694: faultMessage,
1695: ModelerMessages
1696: .WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(
1697: bindingFault.getName(),
1698: faultMessage.getName()));
1699: }
1700:
1701: if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1702: error(
1703: faultPart,
1704: ModelerMessages
1705: .WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(
1706: faultMessage.getName(),
1707: faultPart.getName()));
1708: }
1709:
1710: JAXBType jaxbType = getJAXBType(faultPart);
1711:
1712: fault.setElementName(faultPart.getDescriptor());
1713: fault
1714: .setJavaMemberName(Names
1715: .getExceptionClassMemberName());
1716:
1717: Block faultBlock = new Block(faultQName, jaxbType,
1718: faultPart);
1719: fault.setBlock(faultBlock);
1720: //createParentFault(fault);
1721: //createSubfaults(fault);
1722: if (!response.getFaultBlocksMap().containsKey(
1723: faultBlock.getName()))
1724: response.addFaultBlock(faultBlock);
1725: info.operation.addFault(fault);
1726: }
1727: }
1728:
1729: private String getFaultClassName(
1730: com.sun.tools.ws.wsdl.document.Fault portTypeFault) {
1731: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
1732: portTypeFault, JAXWSBinding.class);
1733: if (jaxwsBinding != null) {
1734: CustomName className = jaxwsBinding.getClassName();
1735: if (className != null) {
1736: return className.getName();
1737: }
1738: }
1739: return portTypeFault.getMessage().getLocalPart();
1740: }
1741:
1742: protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
1743: SOAPBody inBody = getSOAPRequestBody();
1744: Message inMessage = getInputMessage();
1745: if (!setMessagePartsBinding(inBody, inMessage, styleAndUse,
1746: true))
1747: return false;
1748:
1749: if (isRequestResponse()) {
1750: SOAPBody outBody = getSOAPResponseBody();
1751: Message outMessage = getOutputMessage();
1752: if (!setMessagePartsBinding(outBody, outMessage,
1753: styleAndUse, false))
1754: return false;
1755: }
1756: return true;
1757: }
1758:
1759: //returns false if the wsdl is invalid and operation should be ignored
1760: protected boolean setMessagePartsBinding(SOAPBody body,
1761: Message message, StyleAndUse styleAndUse, boolean isInput) {
1762: List<MessagePart> parts = new ArrayList<MessagePart>();
1763:
1764: //get Mime parts
1765: List<MessagePart> mimeParts = null;
1766: List<MessagePart> headerParts = null;
1767: List<MessagePart> bodyParts = getBodyParts(body, message);
1768:
1769: if (isInput) {
1770: headerParts = getHeaderPartsFromMessage(message, isInput);
1771: mimeParts = getMimeContentParts(message,
1772: info.bindingOperation.getInput());
1773: } else {
1774: headerParts = getHeaderPartsFromMessage(message, isInput);
1775: mimeParts = getMimeContentParts(message,
1776: info.bindingOperation.getOutput());
1777: }
1778:
1779: //As of now WSDL MIME binding is not supported, so throw the exception when such binding is encounterd
1780: // if(mimeParts.size() > 0){
1781: // fail("wsdlmodeler.unsupportedBinding.mime", new Object[]{});
1782: // }
1783:
1784: //if soap:body parts attribute not there, then all unbounded message parts will
1785: // belong to the soap body
1786: if (bodyParts == null) {
1787: bodyParts = new ArrayList<MessagePart>();
1788: for (Iterator<MessagePart> iter = message.parts(); iter
1789: .hasNext();) {
1790: MessagePart mPart = iter.next();
1791: //Its a safe assumption that the parts in the message not belonging to header or mime will
1792: // belong to the body?
1793: if (mimeParts.contains(mPart)
1794: || headerParts.contains(mPart)
1795: || boundToFault(mPart.getName())) {
1796: //throw error that a part cant be bound multiple times, not ignoring operation, if there
1797: //is conflict it will fail latter
1798: if (options.isExtensionMode())
1799: warning(
1800: mPart,
1801: ModelerMessages
1802: .WSDLMODELER_WARNING_BINDING_OPERATION_MULTIPLE_PART_BINDING(
1803: info.bindingOperation
1804: .getName(),
1805: mPart.getName()));
1806: else
1807: error(
1808: mPart,
1809: ModelerMessages
1810: .WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_PART_BINDING(
1811: info.bindingOperation
1812: .getName(),
1813: mPart.getName()));
1814: }
1815: bodyParts.add(mPart);
1816: }
1817: }
1818:
1819: //now build the final parts list with header, mime parts and body parts
1820: for (Iterator iter = message.parts(); iter.hasNext();) {
1821: MessagePart mPart = (MessagePart) iter.next();
1822: if (mimeParts.contains(mPart)) {
1823: mPart
1824: .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
1825: parts.add(mPart);
1826: } else if (headerParts.contains(mPart)) {
1827: mPart
1828: .setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1829: parts.add(mPart);
1830: } else if (bodyParts.contains(mPart)) {
1831: mPart
1832: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1833: parts.add(mPart);
1834: } else {
1835: mPart
1836: .setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
1837: }
1838: }
1839:
1840: if (isOperationDocumentLiteral(styleAndUse)
1841: && bodyParts.size() > 1) {
1842: if (options.isExtensionMode())
1843: warning(
1844: message,
1845: ModelerMessages
1846: .WSDLMODELER_WARNING_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation
1847: .getName()));
1848: else
1849: error(
1850: message,
1851: ModelerMessages
1852: .WSDLMODELER_INVALID_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation
1853: .getName()));
1854: return false;
1855: }
1856: return true;
1857: }
1858:
1859: private boolean boundToFault(String partName) {
1860: for (BindingFault bindingFault : info.bindingOperation.faults()) {
1861: if (partName.equals(bindingFault.getName()))
1862: return true;
1863: }
1864: return false;
1865: }
1866:
1867: //get MessagePart(s) referenced by parts attribute of soap:body element
1868: private List<MessagePart> getBodyParts(SOAPBody body,
1869: Message message) {
1870: String bodyParts = body.getParts();
1871: if (bodyParts != null) {
1872: List<MessagePart> partsList = new ArrayList<MessagePart>();
1873: StringTokenizer in = new StringTokenizer(bodyParts.trim(),
1874: " ");
1875: while (in.hasMoreTokens()) {
1876: String part = in.nextToken();
1877: MessagePart mPart = message.getPart(part);
1878: if (null == mPart) {
1879: error(message, ModelerMessages
1880: .WSDLMODELER_ERROR_PARTS_NOT_FOUND(part,
1881: message.getName()));
1882: }
1883: mPart
1884: .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1885: partsList.add(mPart);
1886: }
1887: return partsList;
1888: }
1889: return null;
1890: }
1891:
1892: private List<MessagePart> getHeaderPartsFromMessage(
1893: Message message, boolean isInput) {
1894: List<MessagePart> headerParts = new ArrayList<MessagePart>();
1895: Iterator<MessagePart> parts = message.parts();
1896: List<MessagePart> headers = getHeaderParts(isInput);
1897: while (parts.hasNext()) {
1898: MessagePart part = parts.next();
1899: if (headers.contains(part)) {
1900: headerParts.add(part);
1901: }
1902: }
1903: return headerParts;
1904: }
1905:
1906: private Message getHeaderMessage(MessagePart part,
1907: TWSDLExtensible ext) {
1908: Iterator<SOAPHeader> headers = getHeaderExtensions(ext)
1909: .iterator();
1910: while (headers.hasNext()) {
1911: SOAPHeader header = headers.next();
1912: if (!header.isLiteral())
1913: continue;
1914: com.sun.tools.ws.wsdl.document.Message headerMessage = findMessage(
1915: header.getMessage(), info);
1916: if (headerMessage == null)
1917: continue;
1918:
1919: MessagePart headerPart = headerMessage.getPart(header
1920: .getPart());
1921: if (headerPart == part)
1922: return headerMessage;
1923: }
1924: return null;
1925: }
1926:
1927: private List<MessagePart> getHeaderPartsNotFromMessage(
1928: Message message, boolean isInput) {
1929: List<MessagePart> headerParts = new ArrayList<MessagePart>();
1930: List<MessagePart> parts = message.getParts();
1931: Iterator<MessagePart> headers = getHeaderParts(isInput)
1932: .iterator();
1933: while (headers.hasNext()) {
1934: MessagePart part = headers.next();
1935: if (!parts.contains(part)) {
1936: headerParts.add(part);
1937: }
1938: }
1939: return headerParts;
1940: }
1941:
1942: private List<MessagePart> getHeaderParts(boolean isInput) {
1943: TWSDLExtensible ext;
1944: if (isInput) {
1945: ext = info.bindingOperation.getInput();
1946: } else {
1947: ext = info.bindingOperation.getOutput();
1948: }
1949:
1950: List<MessagePart> parts = new ArrayList<MessagePart>();
1951: Iterator<SOAPHeader> headers = getHeaderExtensions(ext)
1952: .iterator();
1953: while (headers.hasNext()) {
1954: SOAPHeader header = headers.next();
1955: if (!header.isLiteral()) {
1956: error(header, ModelerMessages
1957: .WSDLMODELER_INVALID_HEADER_NOT_LITERAL(header
1958: .getPart(), info.bindingOperation
1959: .getName()));
1960: }
1961:
1962: if (header.getNamespace() != null) {
1963: warning(header, ModelerMessages
1964: .WSDLMODELER_WARNING_R_2716_R_2726(
1965: "soapbind:header",
1966: info.bindingOperation.getName()));
1967: }
1968: com.sun.tools.ws.wsdl.document.Message headerMessage = findMessage(
1969: header.getMessage(), info);
1970: if (headerMessage == null) {
1971: error(
1972: header,
1973: ModelerMessages
1974: .WSDLMODELER_INVALID_HEADER_CANT_RESOLVE_MESSAGE(
1975: header.getMessage(),
1976: info.bindingOperation.getName()));
1977: }
1978:
1979: MessagePart part = headerMessage.getPart(header.getPart());
1980: if (part == null) {
1981: error(header, ModelerMessages
1982: .WSDLMODELER_INVALID_HEADER_NOT_FOUND(header
1983: .getPart(), info.bindingOperation
1984: .getName()));
1985: }
1986: if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1987: error(
1988: part,
1989: ModelerMessages
1990: .WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(
1991: part.getName(),
1992: info.bindingOperation.getName()));
1993: }
1994: part
1995: .setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1996: parts.add(part);
1997: }
1998: return parts;
1999: }
2000:
2001: private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
2002: return StyleAndUse.DOC_LITERAL == styleAndUse;
2003: }
2004:
2005: private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
2006: return StyleAndUse.RPC_LITERAL == styleAndUse;
2007: }
2008:
2009: /**
2010: * @param part
2011: * @return Returns a JAXBType object
2012: */
2013: private JAXBType getJAXBType(MessagePart part) {
2014: JAXBType type = null;
2015: QName name = part.getDescriptor();
2016: if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
2017: type = jaxbModelBuilder.getJAXBType(name);
2018: if (type == null) {
2019: error(part, ModelerMessages
2020: .WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part
2021: .getName()));
2022: }
2023: } else {
2024: S2JJAXBModel jaxbModel = getJAXBModelBuilder()
2025: .getJAXBModel().getS2JJAXBModel();
2026: TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
2027: if (typeAnno == null) {
2028: error(part, ModelerMessages
2029: .WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part
2030: .getName()));
2031: }
2032: JavaType javaType = new JavaSimpleType(
2033: new JAXBTypeAndAnnotation(typeAnno));
2034: type = new JAXBType(new QName("", part.getName()), javaType);
2035: }
2036: return type;
2037: }
2038:
2039: private List<Parameter> getDoclitParameters(Request req,
2040: Response res, List<MessagePart> parameterList) {
2041: if (parameterList.size() == 0)
2042: return new ArrayList<Parameter>();
2043: List<Parameter> params = new ArrayList<Parameter>();
2044: Message inMsg = getInputMessage();
2045: Message outMsg = getOutputMessage();
2046: boolean unwrappable = isUnwrappable();
2047: List<Parameter> outParams = null;
2048: int pIndex = 0;
2049: for (MessagePart part : parameterList) {
2050: QName reqBodyName = part.getDescriptor();
2051: JAXBType jaxbType = getJAXBType(part);
2052: Block block = new Block(reqBodyName, jaxbType, part);
2053: if (unwrappable) {
2054: //So build body and header blocks and set to request and response
2055: JAXBStructuredType jaxbStructType = ModelerUtils
2056: .createJAXBStructureType(jaxbType);
2057: block = new Block(reqBodyName, jaxbStructType, part);
2058: if (ModelerUtils.isBoundToSOAPBody(part)) {
2059: if (part.isIN()) {
2060: req.addBodyBlock(block);
2061: } else if (part.isOUT()) {
2062: res.addBodyBlock(block);
2063: } else if (part.isINOUT()) {
2064: req.addBodyBlock(block);
2065: res.addBodyBlock(block);
2066: }
2067: } else if (ModelerUtils.isUnbound(part)) {
2068: if (part.isIN())
2069: req.addUnboundBlock(block);
2070: else if (part.isOUT())
2071: res.addUnboundBlock(block);
2072: else if (part.isINOUT()) {
2073: req.addUnboundBlock(block);
2074: res.addUnboundBlock(block);
2075: }
2076:
2077: }
2078: if (part.isIN() || part.isINOUT()) {
2079: params = ModelerUtils.createUnwrappedParameters(
2080: jaxbStructType, block);
2081: int index = 0;
2082: Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
2083: for (Parameter param : params) {
2084: param.setParameterIndex(index++);
2085: param.setMode(mode);
2086: setCustomizedParameterName(
2087: info.portTypeOperation, inMsg, part,
2088: param, unwrappable);
2089: }
2090: } else if (part.isOUT()) {
2091: outParams = ModelerUtils.createUnwrappedParameters(
2092: jaxbStructType, block);
2093: for (Parameter param : outParams) {
2094: param.setMode(Mode.OUT);
2095: setCustomizedParameterName(
2096: info.portTypeOperation, outMsg, part,
2097: param, unwrappable);
2098: }
2099: }
2100: } else {
2101: if (ModelerUtils.isBoundToSOAPBody(part)) {
2102: if (part.isIN()) {
2103: req.addBodyBlock(block);
2104: } else if (part.isOUT()) {
2105: res.addBodyBlock(block);
2106: } else if (part.isINOUT()) {
2107: req.addBodyBlock(block);
2108: res.addBodyBlock(block);
2109: }
2110: } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
2111: if (part.isIN()) {
2112: req.addHeaderBlock(block);
2113: } else if (part.isOUT()) {
2114: res.addHeaderBlock(block);
2115: } else if (part.isINOUT()) {
2116: req.addHeaderBlock(block);
2117: res.addHeaderBlock(block);
2118: }
2119: } else if (ModelerUtils.isBoundToMimeContent(part)) {
2120: List<MIMEContent> mimeContents = null;
2121:
2122: if (part.isIN()) {
2123: mimeContents = getMimeContents(
2124: info.bindingOperation.getInput(),
2125: getInputMessage(), part.getName());
2126: jaxbType = getAttachmentType(mimeContents, part);
2127: block = new Block(jaxbType.getName(), jaxbType,
2128: part);
2129: req.addAttachmentBlock(block);
2130: } else if (part.isOUT()) {
2131: mimeContents = getMimeContents(
2132: info.bindingOperation.getOutput(),
2133: getOutputMessage(), part.getName());
2134: jaxbType = getAttachmentType(mimeContents, part);
2135: block = new Block(jaxbType.getName(), jaxbType,
2136: part);
2137: res.addAttachmentBlock(block);
2138: } else if (part.isINOUT()) {
2139: mimeContents = getMimeContents(
2140: info.bindingOperation.getInput(),
2141: getInputMessage(), part.getName());
2142: jaxbType = getAttachmentType(mimeContents, part);
2143: block = new Block(jaxbType.getName(), jaxbType,
2144: part);
2145: req.addAttachmentBlock(block);
2146: res.addAttachmentBlock(block);
2147:
2148: mimeContents = getMimeContents(
2149: info.bindingOperation.getOutput(),
2150: getOutputMessage(), part.getName());
2151: JAXBType outJaxbType = getAttachmentType(
2152: mimeContents, part);
2153:
2154: String inType = jaxbType.getJavaType()
2155: .getType().getName();
2156: String outType = outJaxbType.getJavaType()
2157: .getType().getName();
2158:
2159: TypeAndAnnotation inTa = jaxbType.getJavaType()
2160: .getType().getTypeAnn();
2161: TypeAndAnnotation outTa = outJaxbType
2162: .getJavaType().getType().getTypeAnn();
2163: if ((((inTa != null) && (outTa != null) && inTa
2164: .equals(outTa)))
2165: && !inType.equals(outType)) {
2166: String javaType = "javax.activation.DataHandler";
2167:
2168: S2JJAXBModel jaxbModel = getJAXBModelBuilder()
2169: .getJAXBModel().getS2JJAXBModel();
2170: //JCodeModel cm = jaxbModel.generateCode(null, errReceiver);
2171: JType jt = null;
2172: jt = options.getCodeModel().ref(javaType);
2173: JAXBTypeAndAnnotation jaxbTa = jaxbType
2174: .getJavaType().getType();
2175: jaxbTa.setType(jt);
2176: }
2177: }
2178: } else if (ModelerUtils.isUnbound(part)) {
2179: if (part.isIN()) {
2180: req.addUnboundBlock(block);
2181: } else if (part.isOUT()) {
2182: res.addUnboundBlock(block);
2183: } else if (part.isINOUT()) {
2184: req.addUnboundBlock(block);
2185: res.addUnboundBlock(block);
2186: }
2187: }
2188: Parameter param = ModelerUtils.createParameter(part
2189: .getName(), jaxbType, block);
2190: param.setMode(part.getMode());
2191: if (part.isReturn()) {
2192: param.setParameterIndex(-1);
2193: } else {
2194: param.setParameterIndex(pIndex++);
2195: }
2196:
2197: if (part.isIN())
2198: setCustomizedParameterName(info.portTypeOperation,
2199: inMsg, part, param, false);
2200: else if (outMsg != null)
2201: setCustomizedParameterName(info.portTypeOperation,
2202: outMsg, part, param, false);
2203:
2204: params.add(param);
2205: }
2206: }
2207: if (unwrappable && (outParams != null)) {
2208: int index = params.size();
2209: for (Parameter param : outParams) {
2210: if (JAXBRIContext.mangleNameToVariableName(
2211: param.getName()).equals("return")) {
2212: param.setParameterIndex(-1);
2213: } else {
2214: Parameter inParam = ModelerUtils.getParameter(param
2215: .getName(), params);
2216: if ((inParam != null) && inParam.isIN()) {
2217: QName inElementName = inParam.getType()
2218: .getName();
2219: QName outElementName = param.getType()
2220: .getName();
2221: String inJavaType = inParam.getTypeName();
2222: String outJavaType = param.getTypeName();
2223: TypeAndAnnotation inTa = inParam.getType()
2224: .getJavaType().getType().getTypeAnn();
2225: TypeAndAnnotation outTa = param.getType()
2226: .getJavaType().getType().getTypeAnn();
2227: if (inElementName.getLocalPart().equals(
2228: outElementName.getLocalPart())
2229: && inJavaType.equals(outJavaType)
2230: && (inTa == null || outTa == null || inTa
2231: .equals(outTa))) {
2232: inParam.setMode(Mode.INOUT);
2233: continue;
2234: }
2235: }
2236: if (outParams.size() == 1) {
2237: param.setParameterIndex(-1);
2238: } else {
2239: param.setParameterIndex(index++);
2240: }
2241: }
2242: params.add(param);
2243: }
2244: }
2245: return params;
2246: }
2247:
2248: private List<Parameter> getRpcLitParameters(Request req,
2249: Response res, Block reqBlock, Block resBlock,
2250: List<MessagePart> paramList) {
2251: List<Parameter> params = new ArrayList<Parameter>();
2252: Message inMsg = getInputMessage();
2253: Message outMsg = getOutputMessage();
2254: S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType())
2255: .getJaxbModel().getS2JJAXBModel();
2256: List<Parameter> inParams = ModelerUtils.createRpcLitParameters(
2257: inMsg, reqBlock, jaxbModel, errReceiver);
2258: List<Parameter> outParams = null;
2259: if (outMsg != null)
2260: outParams = ModelerUtils.createRpcLitParameters(outMsg,
2261: resBlock, jaxbModel, errReceiver);
2262:
2263: //create parameters for header and mime parts
2264: int index = 0;
2265: for (MessagePart part : paramList) {
2266: Parameter param = null;
2267: if (ModelerUtils.isBoundToSOAPBody(part)) {
2268: if (part.isIN()) {
2269: param = ModelerUtils.getParameter(part.getName(),
2270: inParams);
2271: } else if (outParams != null) {
2272: param = ModelerUtils.getParameter(part.getName(),
2273: outParams);
2274: }
2275: } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
2276: QName headerName = part.getDescriptor();
2277: JAXBType jaxbType = getJAXBType(part);
2278: Block headerBlock = new Block(headerName, jaxbType,
2279: part);
2280: param = ModelerUtils.createParameter(part.getName(),
2281: jaxbType, headerBlock);
2282: if (part.isIN()) {
2283: req.addHeaderBlock(headerBlock);
2284: } else if (part.isOUT()) {
2285: res.addHeaderBlock(headerBlock);
2286: } else if (part.isINOUT()) {
2287: req.addHeaderBlock(headerBlock);
2288: res.addHeaderBlock(headerBlock);
2289: }
2290: } else if (ModelerUtils.isBoundToMimeContent(part)) {
2291: List<MIMEContent> mimeContents = null;
2292: if (part.isIN() || part.isINOUT())
2293: mimeContents = getMimeContents(
2294: info.bindingOperation.getInput(),
2295: getInputMessage(), part.getName());
2296: else
2297: mimeContents = getMimeContents(
2298: info.bindingOperation.getOutput(),
2299: getOutputMessage(), part.getName());
2300:
2301: JAXBType type = getAttachmentType(mimeContents, part);
2302: //create Parameters in request or response
2303: //Block mimeBlock = new Block(new QName(part.getName()), type);
2304: Block mimeBlock = new Block(type.getName(), type, part);
2305: param = ModelerUtils.createParameter(part.getName(),
2306: type, mimeBlock);
2307: if (part.isIN()) {
2308: req.addAttachmentBlock(mimeBlock);
2309: } else if (part.isOUT()) {
2310: res.addAttachmentBlock(mimeBlock);
2311: } else if (part.isINOUT()) {
2312: mimeContents = getMimeContents(
2313: info.bindingOperation.getOutput(),
2314: getOutputMessage(), part.getName());
2315: JAXBType outJaxbType = getAttachmentType(
2316: mimeContents, part);
2317:
2318: String inType = type.getJavaType().getType()
2319: .getName();
2320: String outType = outJaxbType.getJavaType()
2321: .getType().getName();
2322: if (!inType.equals(outType)) {
2323: String javaType = "javax.activation.DataHandler";
2324: JType jt = null;
2325: jt = options.getCodeModel().ref(javaType);
2326: JAXBTypeAndAnnotation jaxbTa = type
2327: .getJavaType().getType();
2328: jaxbTa.setType(jt);
2329: }
2330: req.addAttachmentBlock(mimeBlock);
2331: res.addAttachmentBlock(mimeBlock);
2332: }
2333: } else if (ModelerUtils.isUnbound(part)) {
2334: QName name = part.getDescriptor();
2335: JAXBType type = getJAXBType(part);
2336: Block unboundBlock = new Block(name, type, part);
2337: if (part.isIN()) {
2338: req.addUnboundBlock(unboundBlock);
2339: } else if (part.isOUT()) {
2340: res.addUnboundBlock(unboundBlock);
2341: } else if (part.isINOUT()) {
2342: req.addUnboundBlock(unboundBlock);
2343: res.addUnboundBlock(unboundBlock);
2344: }
2345: param = ModelerUtils.createParameter(part.getName(),
2346: type, unboundBlock);
2347: }
2348: if (param != null) {
2349: if (part.isReturn()) {
2350: param.setParameterIndex(-1);
2351: } else {
2352: param.setParameterIndex(index++);
2353: }
2354: param.setMode(part.getMode());
2355: params.add(param);
2356: }
2357: }
2358: for (Parameter param : params) {
2359: if (param.isIN())
2360: setCustomizedParameterName(info.portTypeOperation,
2361: inMsg, inMsg.getPart(param.getName()), param,
2362: false);
2363: else if (outMsg != null)
2364: setCustomizedParameterName(info.portTypeOperation,
2365: outMsg, outMsg.getPart(param.getName()), param,
2366: false);
2367: }
2368: return params;
2369: }
2370:
2371: private List<Parameter> getRequestParameters(Request request,
2372: List<String> parameterList) {
2373: Message inputMessage = getInputMessage();
2374: //there is no input message, return zero parameters
2375: if (inputMessage != null && !inputMessage.parts().hasNext())
2376: return new ArrayList<Parameter>();
2377:
2378: List<Parameter> inParameters = null;
2379: QName reqBodyName = null;
2380: Block reqBlock = null;
2381: JAXBType jaxbReqType = null;
2382: boolean unwrappable = isUnwrappable();
2383: boolean doneSOAPBody = false;
2384: //setup request parameters
2385: for (String inParamName : parameterList) {
2386: MessagePart part = inputMessage.getPart(inParamName);
2387: if (part == null)
2388: continue;
2389: reqBodyName = part.getDescriptor();
2390: jaxbReqType = getJAXBType(part);
2391: if (unwrappable) {
2392: //So build body and header blocks and set to request and response
2393: JAXBStructuredType jaxbRequestType = ModelerUtils
2394: .createJAXBStructureType(jaxbReqType);
2395: reqBlock = new Block(reqBodyName, jaxbRequestType, part);
2396: if (ModelerUtils.isBoundToSOAPBody(part)) {
2397: request.addBodyBlock(reqBlock);
2398: } else if (ModelerUtils.isUnbound(part)) {
2399: request.addUnboundBlock(reqBlock);
2400: }
2401: inParameters = ModelerUtils.createUnwrappedParameters(
2402: jaxbRequestType, reqBlock);
2403: for (Parameter param : inParameters) {
2404: setCustomizedParameterName(info.portTypeOperation,
2405: inputMessage, part, param, unwrappable);
2406: }
2407: } else {
2408: reqBlock = new Block(reqBodyName, jaxbReqType, part);
2409: if (ModelerUtils.isBoundToSOAPBody(part)
2410: && !doneSOAPBody) {
2411: doneSOAPBody = true;
2412: request.addBodyBlock(reqBlock);
2413: } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
2414: request.addHeaderBlock(reqBlock);
2415: } else if (ModelerUtils.isBoundToMimeContent(part)) {
2416: List<MIMEContent> mimeContents = getMimeContents(
2417: info.bindingOperation.getInput(),
2418: getInputMessage(), part.getName());
2419: jaxbReqType = getAttachmentType(mimeContents, part);
2420: //reqBlock = new Block(new QName(part.getName()), jaxbReqType);
2421: reqBlock = new Block(jaxbReqType.getName(),
2422: jaxbReqType, part);
2423: request.addAttachmentBlock(reqBlock);
2424: } else if (ModelerUtils.isUnbound(part)) {
2425: request.addUnboundBlock(reqBlock);
2426: }
2427: if (inParameters == null)
2428: inParameters = new ArrayList<Parameter>();
2429: Parameter param = ModelerUtils.createParameter(part
2430: .getName(), jaxbReqType, reqBlock);
2431: setCustomizedParameterName(info.portTypeOperation,
2432: inputMessage, part, param, false);
2433: inParameters.add(param);
2434: }
2435: }
2436: return inParameters;
2437: }
2438:
2439: /**
2440: * @param part
2441: * @param param
2442: * @param wrapperStyle TODO
2443: */
2444: private void setCustomizedParameterName(TWSDLExtensible extension,
2445: Message msg, MessagePart part, Parameter param,
2446: boolean wrapperStyle) {
2447: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
2448: extension, JAXWSBinding.class);
2449: if (jaxwsBinding == null)
2450: return;
2451: String paramName = part.getName();
2452: QName elementName = part.getDescriptor();
2453: if (wrapperStyle)
2454: elementName = param.getType().getName();
2455: String customName = jaxwsBinding.getParameterName(
2456: msg.getName(), paramName, elementName, wrapperStyle);
2457: if (customName != null && !customName.equals("")) {
2458: param.setCustomName(customName);
2459: }
2460: }
2461:
2462: protected boolean isConflictingPortClassName(String name) {
2463: return false;
2464: }
2465:
2466: protected boolean isUnwrappable() {
2467: if (!getWrapperStyleCustomization())
2468: return false;
2469:
2470: com.sun.tools.ws.wsdl.document.Message inputMessage = getInputMessage();
2471: com.sun.tools.ws.wsdl.document.Message outputMessage = getOutputMessage();
2472:
2473: // Wrapper style if the operation's input and output messages each contain
2474: // only a single part
2475: if ((inputMessage != null && inputMessage.numParts() != 1)
2476: || (outputMessage != null && outputMessage.numParts() != 1)) {
2477: return false;
2478: }
2479:
2480: MessagePart inputPart = inputMessage != null ? inputMessage
2481: .parts().next() : null;
2482: MessagePart outputPart = outputMessage != null ? outputMessage
2483: .parts().next() : null;
2484: String operationName = info.portTypeOperation.getName();
2485:
2486: // Wrapper style if the input message part refers to a global element declaration whose localname
2487: // is equal to the operation name
2488: // Wrapper style if the output message part refers to a global element declaration
2489: if ((inputPart != null && !inputPart.getDescriptor()
2490: .getLocalPart().equals(operationName))
2491: || (outputPart != null && outputPart
2492: .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
2493: return false;
2494:
2495: //check to see if either input or output message part not bound to soapbing:body
2496: //in that case the operation is not wrapper style
2497: if (((inputPart != null) && (inputPart
2498: .getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING))
2499: || ((outputPart != null) && (outputPart
2500: .getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)))
2501: return false;
2502:
2503: // Wrapper style if the elements referred to by the input and output message parts
2504: // (henceforth referred to as wrapper elements) are both complex types defined
2505: // using the xsd:sequence compositor
2506: // Wrapper style if the wrapper elements only contain child elements, they must not
2507: // contain other structures such as xsd:choice, substitution groups1 or attributes
2508: //These checkins are done by jaxb, we just check if jaxb has wrapper children. If there
2509: // are then its wrapper style
2510: //if(inputPart != null && outputPart != null){
2511: if (inputPart != null) {
2512: boolean inputWrappable = false;
2513: JAXBType inputType = getJAXBType(inputPart);
2514: if (inputType != null) {
2515: inputWrappable = inputType.isUnwrappable();
2516: }
2517: //if there are no output part (oneway), the operation can still be wrapper style
2518: if (outputPart == null) {
2519: return inputWrappable;
2520: }
2521: JAXBType outputType = getJAXBType(outputPart);
2522: if ((inputType != null) && (outputType != null))
2523: return inputType.isUnwrappable()
2524: && outputType.isUnwrappable();
2525: }
2526:
2527: return false;
2528: }
2529:
2530: private boolean getWrapperStyleCustomization() {
2531: //first we look into wsdl:portType/wsdl:operation
2532: com.sun.tools.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
2533: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
2534: portTypeOperation, JAXWSBinding.class);
2535: if (jaxwsBinding != null) {
2536: Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2537: if (isWrappable != null)
2538: return isWrappable;
2539: }
2540:
2541: //then into wsdl:portType
2542: PortType portType = info.port.resolveBinding(document)
2543: .resolvePortType(document);
2544: jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType,
2545: JAXWSBinding.class);
2546: if (jaxwsBinding != null) {
2547: Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2548: if (isWrappable != null)
2549: return isWrappable;
2550: }
2551:
2552: //then wsdl:definitions
2553: jaxwsBinding = (JAXWSBinding) getExtensionOfType(document
2554: .getDefinitions(), JAXWSBinding.class);
2555: if (jaxwsBinding != null) {
2556: Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2557: if (isWrappable != null)
2558: return isWrappable;
2559: }
2560: return true;
2561: }
2562:
2563: /* (non-Javadoc)
2564: * @see WSDLModelerBase#isSingleInOutPart(Set, MessagePart)
2565: */
2566: protected boolean isSingleInOutPart(Set inputParameterNames,
2567: MessagePart outputPart) {
2568: // As of now, we dont have support for in/out in doc-lit. So return false.
2569: SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
2570: info.bindingOperation, SOAPOperation.class);
2571: if ((soapOperation != null)
2572: && (soapOperation.isDocument() || info.soapBinding
2573: .isDocument())) {
2574: Iterator iter = getInputMessage().parts();
2575: while (iter.hasNext()) {
2576: MessagePart part = (MessagePart) iter.next();
2577: if (outputPart.getName().equals(part.getName())
2578: && outputPart.getDescriptor().equals(
2579: part.getDescriptor()))
2580: return true;
2581: }
2582: } else if (soapOperation != null && soapOperation.isRPC()
2583: || info.soapBinding.isRPC()) {
2584: com.sun.tools.ws.wsdl.document.Message inputMessage = getInputMessage();
2585: if (inputParameterNames.contains(outputPart.getName())) {
2586: if (inputMessage.getPart(outputPart.getName())
2587: .getDescriptor().equals(
2588: outputPart.getDescriptor())) {
2589: return true;
2590: }
2591: }
2592: }
2593: return false;
2594: }
2595:
2596: private List<Parameter> createRpcLitRequestParameters(
2597: Request request, List<String> parameterList, Block block) {
2598: Message message = getInputMessage();
2599: S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType())
2600: .getJaxbModel().getS2JJAXBModel();
2601: List<Parameter> parameters = ModelerUtils
2602: .createRpcLitParameters(message, block, jaxbModel,
2603: errReceiver);
2604:
2605: //create parameters for header and mime parts
2606: for (String paramName : parameterList) {
2607: MessagePart part = message.getPart(paramName);
2608: if (part == null)
2609: continue;
2610: if (ModelerUtils.isBoundToSOAPHeader(part)) {
2611: if (parameters == null)
2612: parameters = new ArrayList<Parameter>();
2613: QName headerName = part.getDescriptor();
2614: JAXBType jaxbType = getJAXBType(part);
2615: Block headerBlock = new Block(headerName, jaxbType,
2616: part);
2617: request.addHeaderBlock(headerBlock);
2618: Parameter param = ModelerUtils.createParameter(part
2619: .getName(), jaxbType, headerBlock);
2620: if (param != null) {
2621: parameters.add(param);
2622: }
2623: } else if (ModelerUtils.isBoundToMimeContent(part)) {
2624: if (parameters == null)
2625: parameters = new ArrayList<Parameter>();
2626: List<MIMEContent> mimeContents = getMimeContents(
2627: info.bindingOperation.getInput(),
2628: getInputMessage(), paramName);
2629:
2630: JAXBType type = getAttachmentType(mimeContents, part);
2631: //create Parameters in request or response
2632: //Block mimeBlock = new Block(new QName(part.getName()), type);
2633: Block mimeBlock = new Block(type.getName(), type, part);
2634: request.addAttachmentBlock(mimeBlock);
2635: Parameter param = ModelerUtils.createParameter(part
2636: .getName(), type, mimeBlock);
2637: if (param != null) {
2638: parameters.add(param);
2639: }
2640: } else if (ModelerUtils.isUnbound(part)) {
2641: if (parameters == null)
2642: parameters = new ArrayList<Parameter>();
2643: QName name = part.getDescriptor();
2644: JAXBType type = getJAXBType(part);
2645: Block unboundBlock = new Block(name, type, part);
2646: request.addUnboundBlock(unboundBlock);
2647: Parameter param = ModelerUtils.createParameter(part
2648: .getName(), type, unboundBlock);
2649: if (param != null) {
2650: parameters.add(param);
2651: }
2652: }
2653: }
2654: for (Parameter param : parameters) {
2655: setCustomizedParameterName(info.portTypeOperation, message,
2656: message.getPart(param.getName()), param, false);
2657: }
2658: return parameters;
2659: }
2660:
2661: private String getJavaTypeForMimeType(String mimeType) {
2662: if (mimeType.equals("image/jpeg")
2663: || mimeType.equals("image/gif")) {
2664: return "java.awt.Image";
2665: } else if (mimeType.equals("text/xml")
2666: || mimeType.equals("application/xml")) {
2667: return "javax.xml.transform.Source";
2668: }
2669: return "javax.activation.DataHandler";
2670: }
2671:
2672: private JAXBType getAttachmentType(List<MIMEContent> mimeContents,
2673: MessagePart part) {
2674: if (!enableMimeContent()) {
2675: return getJAXBType(part);
2676: }
2677: String javaType = null;
2678: List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
2679: if (mimeTypes.size() > 1) {
2680: javaType = "javax.activation.DataHandler";
2681: } else {
2682: javaType = getJavaTypeForMimeType(mimeTypes.get(0));
2683: }
2684:
2685: S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel()
2686: .getS2JJAXBModel();
2687: JType jt = null;
2688: jt = options.getCodeModel().ref(javaType);
2689: QName desc = part.getDescriptor();
2690: TypeAndAnnotation typeAnno = null;
2691:
2692: if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
2693: typeAnno = jaxbModel.getJavaType(desc);
2694: desc = new QName("", part.getName());
2695: } else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
2696: typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
2697: if (typeAnno == null) {
2698: error(part, ModelerMessages
2699: .WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part
2700: .getDescriptor(), part.getName()));
2701: }
2702: for (Iterator mimeTypeIter = mimeTypes.iterator(); mimeTypeIter
2703: .hasNext();) {
2704: String mimeType = (String) mimeTypeIter.next();
2705: if ((!mimeType.equals("text/xml") && !mimeType
2706: .equals("application/xml"))) {
2707: //According to AP 1.0,
2708: //RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
2709: //global element declaration (via the element attribute of the wsdl:part
2710: //element) then the value of the type attribute of a mime:content element
2711: //that binds that part MUST be a content type suitable for carrying an
2712: //XML serialization.
2713: //should we throw warning?
2714: //type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
2715: warning(
2716: part,
2717: ModelerMessages
2718: .MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(
2719: part.getName(), mimeType));
2720: }
2721: }
2722: }
2723: if (typeAnno == null) {
2724: error(part, ModelerMessages
2725: .WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part
2726: .getName()));
2727: }
2728: return new JAXBType(desc, new JavaSimpleType(
2729: new JAXBTypeAndAnnotation(typeAnno, jt)), null,
2730: getJAXBModelBuilder().getJAXBModel());
2731: }
2732:
2733: protected void buildJAXBModel(WSDLDocument wsdlDocument) {
2734: JAXBModelBuilder jaxbModelBuilder = new JAXBModelBuilder(
2735: options, classNameCollector, forest, errReceiver);
2736: //set the java package where wsdl artifacts will be generated
2737: //if user provided package name using -p switch (or package property on wsimport ant task)
2738: //ignore the package customization in the wsdl and schema bidnings
2739: //formce the -p option only in the first pass
2740: if (explicitDefaultPackage != null) {
2741: jaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(
2742: options.defaultPackage);
2743: } else {
2744: options.defaultPackage = getJavaPackage();
2745: }
2746:
2747: //create pseudo schema for async operations(if any) response bean
2748: List<InputSource> schemas = PseudoSchemaBuilder.build(this ,
2749: options, errReceiver);
2750: for (InputSource schema : schemas) {
2751: jaxbModelBuilder.getJAXBSchemaCompiler()
2752: .parseSchema(schema);
2753: }
2754: jaxbModelBuilder.bind();
2755: this .jaxbModelBuilder = jaxbModelBuilder;
2756: }
2757:
2758: protected String getJavaPackage() {
2759: String jaxwsPackage = null;
2760: JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
2761: document.getDefinitions(), JAXWSBinding.class);
2762: if (jaxwsCustomization != null
2763: && jaxwsCustomization.getJaxwsPackage() != null) {
2764: jaxwsPackage = jaxwsCustomization.getJaxwsPackage()
2765: .getName();
2766: }
2767: if (jaxwsPackage != null) {
2768: return jaxwsPackage;
2769: }
2770: String wsdlUri = document.getDefinitions()
2771: .getTargetNamespaceURI();
2772: return XJC.getDefaultPackageName(wsdlUri);
2773:
2774: }
2775:
2776: protected void createJavaInterfaceForProviderPort(Port port) {
2777: String interfaceName = "javax.xml.ws.Provider";
2778: JavaInterface intf = new JavaInterface(interfaceName);
2779: port.setJavaInterface(intf);
2780: }
2781:
2782: protected void createJavaInterfaceForPort(Port port,
2783: boolean isProvider) {
2784: if (isProvider) {
2785: createJavaInterfaceForProviderPort(port);
2786: return;
2787: }
2788: String interfaceName = getJavaNameOfSEI(port);
2789:
2790: if (isConflictingPortClassName(interfaceName)) {
2791: interfaceName += "_PortType";
2792: }
2793:
2794: JavaInterface intf = new JavaInterface(interfaceName);
2795: for (Operation operation : port.getOperations()) {
2796: createJavaMethodForOperation(port, operation, intf);
2797:
2798: for (JavaParameter jParam : operation.getJavaMethod()
2799: .getParametersList()) {
2800: Parameter param = jParam.getParameter();
2801: if (param.getCustomName() != null)
2802: jParam.setName(param.getCustomName());
2803: }
2804: }
2805:
2806: port.setJavaInterface(intf);
2807: }
2808:
2809: protected String getServiceInterfaceName(QName serviceQName,
2810: com.sun.tools.ws.wsdl.document.Service wsdlService) {
2811: String serviceName = wsdlService.getName();
2812: JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(
2813: wsdlService, JAXWSBinding.class);
2814: if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2815: CustomName name = jaxwsCust.getClassName();
2816: if (name != null && !name.equals(""))
2817: serviceName = name.getName();
2818: }
2819: String serviceInterface = "";
2820: String javaPackageName = options.defaultPackage;
2821: serviceInterface = javaPackageName + ".";
2822:
2823: serviceInterface += JAXBRIContext
2824: .mangleNameToClassName(serviceName);
2825: return serviceInterface;
2826: }
2827:
2828: protected String getJavaNameOfSEI(Port port) {
2829: QName portTypeName = (QName) port
2830: .getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
2831: PortType pt = (PortType) document.find(Kinds.PORT_TYPE,
2832: portTypeName);
2833: //populate the portType map here. We should get rid of all these properties
2834: // lets not do it as it may break NB
2835: //TODO: clean all these stuff part of NB RFE
2836: port.portTypes.put(portTypeName, pt);
2837: JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt,
2838: JAXWSBinding.class);
2839: if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2840: CustomName name = jaxwsCust.getClassName();
2841: if (name != null && !name.equals("")) {
2842: return makePackageQualified(name.getName());
2843: }
2844: }
2845:
2846: String interfaceName = null;
2847: if (portTypeName != null) {
2848: // got portType information from WSDL, use it to name the interface
2849: interfaceName = makePackageQualified(JAXBRIContext
2850: .mangleNameToClassName(portTypeName.getLocalPart()));
2851: } else {
2852: // somehow we only got the port name, so we use that
2853: interfaceName = makePackageQualified(JAXBRIContext
2854: .mangleNameToClassName(port.getName()
2855: .getLocalPart()));
2856: }
2857: return interfaceName;
2858: }
2859:
2860: private void createJavaMethodForAsyncOperation(Port port,
2861: Operation operation, JavaInterface intf) {
2862: String candidateName = getJavaNameForOperation(operation);
2863: JavaMethod method = new JavaMethod(candidateName, options,
2864: errReceiver);
2865: Request request = operation.getRequest();
2866: Iterator requestBodyBlocks = request.getBodyBlocks();
2867: Block requestBlock = (requestBodyBlocks.hasNext() ? (Block) request
2868: .getBodyBlocks().next()
2869: : null);
2870:
2871: Response response = operation.getResponse();
2872: Iterator responseBodyBlocks = null;
2873: Block responseBlock;
2874: if (response != null) {
2875: responseBodyBlocks = response.getBodyBlocks();
2876: responseBlock = responseBodyBlocks.hasNext() ? (Block) response
2877: .getBodyBlocks().next()
2878: : null;
2879: }
2880:
2881: // build a signature of the form "opName%arg1type%arg2type%...%argntype so that we
2882: // detect overloading conflicts in the generated java interface/classes
2883: String signature = candidateName;
2884: for (Iterator iter = request.getParameters(); iter.hasNext();) {
2885: Parameter parameter = (Parameter) iter.next();
2886:
2887: if (parameter.getJavaParameter() != null) {
2888: error(operation.getEntity(), ModelerMessages
2889: .WSDLMODELER_INVALID_OPERATION(operation
2890: .getName().getLocalPart()));
2891: }
2892:
2893: JavaType parameterType = parameter.getType().getJavaType();
2894: JavaParameter javaParameter = new JavaParameter(
2895: JAXBRIContext.mangleNameToVariableName(parameter
2896: .getName()), parameterType, parameter,
2897: parameter.getLinkedParameter() != null);
2898: if (javaParameter.isHolder()) {
2899: javaParameter.setHolderName(javax.xml.ws.Holder.class
2900: .getName());
2901: }
2902: method.addParameter(javaParameter);
2903: parameter.setJavaParameter(javaParameter);
2904:
2905: signature += "%" + parameterType.getName();
2906: }
2907:
2908: if (response != null) {
2909: String resultParameterName = (String) operation
2910: .getProperty(WSDL_RESULT_PARAMETER);
2911: Parameter resultParameter = response
2912: .getParameterByName(resultParameterName);
2913: JavaType returnType = resultParameter.getType()
2914: .getJavaType();
2915: method.setReturnType(returnType);
2916:
2917: }
2918: operation.setJavaMethod(method);
2919: intf.addMethod(method);
2920: }
2921:
2922: /* (non-Javadoc)
2923: * @see WSDLModelerBase#createJavaMethodForOperation(WSDLPort, WSDLOperation, JavaInterface, Set, Set)
2924: */
2925: protected void createJavaMethodForOperation(Port port,
2926: Operation operation, JavaInterface intf) {
2927: if ((operation instanceof AsyncOperation)) {
2928: createJavaMethodForAsyncOperation(port, operation, intf);
2929: return;
2930: }
2931: String candidateName = getJavaNameForOperation(operation);
2932: JavaMethod method = new JavaMethod(candidateName, options,
2933: errReceiver);
2934: Request request = operation.getRequest();
2935: Parameter returnParam = (Parameter) operation
2936: .getProperty(WSDL_RESULT_PARAMETER);
2937: if (returnParam != null) {
2938: JavaType parameterType = returnParam.getType()
2939: .getJavaType();
2940: method.setReturnType(parameterType);
2941: } else {
2942: JavaType ret = new JavaSimpleTypeCreator().VOID_JAVATYPE;
2943: method.setReturnType(ret);
2944: }
2945: List<Parameter> parameterOrder = (List<Parameter>) operation
2946: .getProperty(WSDL_PARAMETER_ORDER);
2947: for (Parameter param : parameterOrder) {
2948: JavaType parameterType = param.getType().getJavaType();
2949: String name = (param.getCustomName() != null) ? param
2950: .getCustomName() : param.getName();
2951: name = JAXBRIContext.mangleNameToVariableName(name);
2952: //if its a java keyword after name mangling, then we simply put underscore as there is no
2953: //need to ask user to customize the parameter name if its java keyword
2954: if (Names.isJavaReservedWord(name)) {
2955: name = "_" + name;
2956: }
2957: JavaParameter javaParameter = new JavaParameter(name,
2958: parameterType, param, param.isINOUT()
2959: || param.isOUT());
2960: if (javaParameter.isHolder()) {
2961: javaParameter.setHolderName(javax.xml.ws.Holder.class
2962: .getName());
2963: }
2964: method.addParameter(javaParameter);
2965: param.setJavaParameter(javaParameter);
2966: }
2967: operation.setJavaMethod(method);
2968: intf.addMethod(method);
2969:
2970: String opName = JAXBRIContext
2971: .mangleNameToVariableName(operation.getName()
2972: .getLocalPart());
2973: for (Iterator iter = operation.getFaults(); iter != null
2974: && iter.hasNext();) {
2975: Fault fault = (Fault) iter.next();
2976: createJavaExceptionFromLiteralType(fault, port, opName);
2977: }
2978: JavaException javaException;
2979: Fault fault;
2980: for (Iterator iter = operation.getFaults(); iter.hasNext();) {
2981: fault = (Fault) iter.next();
2982: javaException = fault.getJavaException();
2983: method.addException(javaException.getName());
2984: }
2985:
2986: }
2987:
2988: protected boolean createJavaExceptionFromLiteralType(Fault fault,
2989: com.sun.tools.ws.processor.model.Port port,
2990: String operationName) {
2991: JAXBType faultType = (JAXBType) fault.getBlock().getType();
2992:
2993: String exceptionName = makePackageQualified(JAXBRIContext
2994: .mangleNameToClassName(fault.getName()));
2995:
2996: // use fault namespace attribute
2997: JAXBStructuredType jaxbStruct = new JAXBStructuredType(
2998: new QName(fault.getBlock().getName().getNamespaceURI(),
2999: fault.getName()));
3000:
3001: QName memberName = fault.getElementName();
3002: JAXBElementMember jaxbMember = new JAXBElementMember(
3003: memberName, faultType);
3004: //jaxbMember.setNillable(faultType.isNillable());
3005:
3006: String javaMemberName = getLiteralJavaMemberName(fault);
3007: JavaStructureMember javaMember = new JavaStructureMember(
3008: javaMemberName, faultType.getJavaType(), jaxbMember);
3009: jaxbMember.setJavaStructureMember(javaMember);
3010: javaMember.setReadMethod(Names
3011: .getJavaMemberReadMethod(javaMember));
3012: javaMember.setInherited(false);
3013: jaxbMember.setJavaStructureMember(javaMember);
3014: jaxbStruct.add(jaxbMember);
3015:
3016: if (isConflictingExceptionClassName(exceptionName)) {
3017: exceptionName += "_Exception";
3018: }
3019:
3020: JavaException existingJavaException = (JavaException) _javaExceptions
3021: .get(exceptionName);
3022: if (existingJavaException != null) {
3023: if (existingJavaException.getName().equals(exceptionName)) {
3024: if (((JAXBType) existingJavaException.getOwner())
3025: .getName().equals(jaxbStruct.getName())
3026: || ModelerUtils
3027: .isEquivalentLiteralStructures(
3028: jaxbStruct,
3029: (JAXBStructuredType) existingJavaException
3030: .getOwner())) {
3031: // we have mapped this fault already
3032: if (faultType instanceof JAXBStructuredType) {
3033: fault.getBlock().setType(
3034: (JAXBType) existingJavaException
3035: .getOwner());
3036: }
3037: fault.setJavaException(existingJavaException);
3038: return false;
3039: }
3040: }
3041: }
3042:
3043: JavaException javaException = new JavaException(exceptionName,
3044: false, jaxbStruct);
3045: javaException.add(javaMember);
3046: jaxbStruct.setJavaType(javaException);
3047:
3048: _javaExceptions.put(javaException.getName(), javaException);
3049:
3050: fault.setJavaException(javaException);
3051: return true;
3052: }
3053:
3054: protected boolean isRequestResponse() {
3055: return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
3056: }
3057:
3058: protected java.util.List<String> getAsynParameterOrder() {
3059: //for async operation ignore the parameterOrder
3060: java.util.List<String> parameterList = new ArrayList<String>();
3061: Message inputMessage = getInputMessage();
3062: List<MessagePart> inputParts = inputMessage.getParts();
3063: for (MessagePart part : inputParts) {
3064: parameterList.add(part.getName());
3065: }
3066: return parameterList;
3067: }
3068:
3069: protected List<MessagePart> getParameterOrder() {
3070: List<MessagePart> params = new ArrayList<MessagePart>();
3071: String parameterOrder = info.portTypeOperation
3072: .getParameterOrder();
3073: java.util.List<String> parameterList = new ArrayList<String>();
3074: boolean parameterOrderPresent = false;
3075: if ((parameterOrder != null)
3076: && !(parameterOrder.trim().equals(""))) {
3077: parameterList = XmlUtil.parseTokenList(parameterOrder);
3078: parameterOrderPresent = true;
3079: } else {
3080: parameterList = new ArrayList<String>();
3081: }
3082: Message inputMessage = getInputMessage();
3083: Message outputMessage = getOutputMessage();
3084: List<MessagePart> outputParts = null;
3085: List<MessagePart> inputParts = inputMessage.getParts();
3086: //reset the mode and ret flag, as MEssagePArts aer shared across ports
3087: for (MessagePart part : inputParts) {
3088: part.setMode(Mode.IN);
3089: part.setReturn(false);
3090: }
3091: if (isRequestResponse()) {
3092: outputParts = outputMessage.getParts();
3093: for (MessagePart part : outputParts) {
3094: part.setMode(Mode.OUT);
3095: part.setReturn(false);
3096: }
3097: }
3098:
3099: if (parameterOrderPresent) {
3100: boolean validParameterOrder = true;
3101: Iterator<String> paramOrders = parameterList.iterator();
3102: // If any part in the parameterOrder is not present in the request or
3103: // response message, we completely ignore the parameterOrder hint
3104: while (paramOrders.hasNext()) {
3105: String param = paramOrders.next();
3106: boolean partFound = false;
3107: for (MessagePart part : inputParts) {
3108: if (param.equals(part.getName())) {
3109: partFound = true;
3110: break;
3111: }
3112: }
3113: // if not found, check in output parts
3114: if (!partFound) {
3115: for (MessagePart part : outputParts) {
3116: if (param.equals(part.getName())) {
3117: partFound = true;
3118: break;
3119: }
3120: }
3121: }
3122: if (!partFound) {
3123: warning(
3124: info.operation.getEntity(),
3125: ModelerMessages
3126: .WSDLMODELER_INVALID_PARAMETERORDER_PARAMETER(
3127: param, info.operation
3128: .getName()
3129: .getLocalPart()));
3130: validParameterOrder = false;
3131: }
3132: }
3133:
3134: List<MessagePart> inputUnlistedParts = new ArrayList<MessagePart>();
3135: List<MessagePart> outputUnlistedParts = new ArrayList<MessagePart>();
3136:
3137: //gather input Parts
3138: if (validParameterOrder) {
3139: for (String param : parameterList) {
3140: MessagePart part = inputMessage.getPart(param);
3141: if (part != null) {
3142: params.add(part);
3143: continue;
3144: }
3145: if (isRequestResponse()) {
3146: MessagePart outPart = outputMessage
3147: .getPart(param);
3148: if (outPart != null) {
3149: params.add(outPart);
3150: continue;
3151: }
3152: }
3153: }
3154:
3155: for (MessagePart part : inputParts) {
3156: if (!parameterList.contains(part.getName())) {
3157: inputUnlistedParts.add(part);
3158: }
3159: }
3160:
3161: if (isRequestResponse()) {
3162: // at most one output part should be unlisted
3163: for (MessagePart part : outputParts) {
3164: if (!parameterList.contains(part.getName())) {
3165: MessagePart inPart = inputMessage
3166: .getPart(part.getName());
3167: //dont add inout as unlisted part
3168: if ((inPart != null)
3169: && inPart.getDescriptor().equals(
3170: part.getDescriptor())) {
3171: inPart.setMode(Mode.INOUT);
3172: } else {
3173: outputUnlistedParts.add(part);
3174: }
3175: } else {
3176: //param list may contain it, check if its INOUT
3177: MessagePart inPart = inputMessage
3178: .getPart(part.getName());
3179: //dont add inout as unlisted part
3180: if ((inPart != null)
3181: && inPart.getDescriptor().equals(
3182: part.getDescriptor())) {
3183: inPart.setMode(Mode.INOUT);
3184: } else if (!params.contains(part)) {
3185: params.add(part);
3186: }
3187: }
3188: }
3189: if (outputUnlistedParts.size() == 1) {
3190: MessagePart resultPart = outputUnlistedParts
3191: .get(0);
3192: resultPart.setReturn(true);
3193: params.add(resultPart);
3194: outputUnlistedParts.clear();
3195: }
3196: }
3197:
3198: //add the input and output unlisted parts
3199: for (MessagePart part : inputUnlistedParts) {
3200: params.add(part);
3201: }
3202:
3203: for (MessagePart part : outputUnlistedParts) {
3204: params.add(part);
3205: }
3206: return params;
3207:
3208: }
3209: //parameterOrder attribute is not valid, we ignore it
3210: warning(
3211: info.operation.getEntity(),
3212: ModelerMessages
3213: .WSDLMODELER_INVALID_PARAMETER_ORDER_INVALID_PARAMETER_ORDER(info.operation
3214: .getName().getLocalPart()));
3215: parameterOrderPresent = false;
3216: parameterList.clear();
3217: }
3218:
3219: List<MessagePart> outParts = new ArrayList<MessagePart>();
3220:
3221: //construct input parameter list with the same order as in input message
3222: for (MessagePart part : inputParts) {
3223: params.add(part);
3224: }
3225:
3226: if (isRequestResponse()) {
3227: for (MessagePart part : outputParts) {
3228: MessagePart inPart = inputMessage.getPart(part
3229: .getName());
3230: if (inPart != null
3231: && part.getDescriptorKind() == inPart
3232: .getDescriptorKind()
3233: && part.getDescriptor().equals(
3234: inPart.getDescriptor())) {
3235: inPart.setMode(Mode.INOUT);
3236: continue;
3237: }
3238: outParts.add(part);
3239: }
3240:
3241: //append the out parts to the parameterList
3242: for (MessagePart part : outParts) {
3243: if (outParts.size() == 1)
3244: part.setReturn(true);
3245: params.add(part);
3246: }
3247: }
3248: return params;
3249: }
3250:
3251: /**
3252: * @param port
3253: * @param suffix
3254: * @return the Java ClassName for a port
3255: */
3256: protected String getClassName(Port port, String suffix) {
3257: String prefix = JAXBRIContext.mangleNameToClassName((port
3258: .getName().getLocalPart()));
3259: return options.defaultPackage + "." + prefix + suffix;
3260: }
3261:
3262: protected boolean isConflictingServiceClassName(String name) {
3263: return conflictsWithSEIClass(name)
3264: || conflictsWithJAXBClass(name)
3265: || conflictsWithExceptionClass(name);
3266: }
3267:
3268: private boolean conflictsWithSEIClass(String name) {
3269: Set<String> seiNames = classNameCollector.getSeiClassNames();
3270: return seiNames != null && seiNames.contains(name);
3271: }
3272:
3273: private boolean conflictsWithJAXBClass(String name) {
3274: Set<String> jaxbNames = classNameCollector
3275: .getJaxbGeneratedClassNames();
3276: return jaxbNames != null && jaxbNames.contains(name);
3277: }
3278:
3279: private boolean conflictsWithExceptionClass(String name) {
3280: Set<String> exceptionNames = classNameCollector
3281: .getExceptionClassNames();
3282: return exceptionNames != null && exceptionNames.contains(name);
3283: }
3284:
3285: protected boolean isConflictingExceptionClassName(String name) {
3286: return conflictsWithSEIClass(name)
3287: || conflictsWithJAXBClass(name);
3288: }
3289:
3290: protected JAXBModelBuilder getJAXBModelBuilder() {
3291: return jaxbModelBuilder;
3292: }
3293:
3294: protected boolean validateWSDLBindingStyle(Binding binding) {
3295: SOAPBinding soapBinding = (SOAPBinding) getExtensionOfType(
3296: binding, SOAPBinding.class);
3297:
3298: //dont process the binding
3299: if (soapBinding == null)
3300: soapBinding = (SOAPBinding) getExtensionOfType(binding,
3301: SOAP12Binding.class);
3302: if (soapBinding == null)
3303: return false;
3304:
3305: //if soapbind:binding has no style attribute, the default is DOCUMENT
3306: if (soapBinding.getStyle() == null)
3307: soapBinding.setStyle(SOAPStyle.DOCUMENT);
3308:
3309: SOAPStyle opStyle = soapBinding.getStyle();
3310: for (Iterator iter = binding.operations(); iter.hasNext();) {
3311: BindingOperation bindingOperation = (BindingOperation) iter
3312: .next();
3313: SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
3314: bindingOperation, SOAPOperation.class);
3315: if (soapOperation != null) {
3316: SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation
3317: .getStyle()
3318: : soapBinding.getStyle();
3319: //dont check for the first operation
3320: if (!currOpStyle.equals(opStyle))
3321: return false;
3322: }
3323: }
3324: return true;
3325: }
3326:
3327: /**
3328: * @param port
3329: */
3330: private void applyWrapperStyleCustomization(Port port,
3331: PortType portType) {
3332: JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
3333: portType, JAXWSBinding.class);
3334: Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding
3335: .isEnableWrapperStyle() : null;
3336: if (wrapperStyle != null) {
3337: port.setWrapped(wrapperStyle);
3338: }
3339: }
3340:
3341: protected static void setDocumentationIfPresent(ModelObject obj,
3342: Documentation documentation) {
3343: if (documentation != null && documentation.getContent() != null) {
3344: obj.setJavaDoc(documentation.getContent());
3345: }
3346: }
3347:
3348: protected String getJavaNameForOperation(Operation operation) {
3349: String name = operation.getJavaMethodName();
3350: if (Names.isJavaReservedWord(name)) {
3351: name = "_" + name;
3352: }
3353: return name;
3354: }
3355:
3356: private void reportError(Entity entity, String formattedMsg,
3357: Exception nestedException) {
3358: Locator locator = (entity == null) ? null : entity.getLocator();
3359:
3360: SAXParseException e = new SAXParseException2(formattedMsg,
3361: locator, nestedException);
3362: errReceiver.error(e);
3363: }
3364:
3365: }
|