Search in sources :

Example 1 with MIMEContent

use of com.sun.tools.ws.wsdl.document.mime.MIMEContent in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method getDoclitParameters.

private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
    if (parameterList.isEmpty()) {
        return new ArrayList<>();
    }
    List<Parameter> params = new ArrayList<>();
    Message inMsg = getInputMessage();
    Message outMsg = getOutputMessage();
    boolean unwrappable = isUnwrappable();
    List<Parameter> outParams = null;
    int pIndex = 0;
    for (MessagePart part : parameterList) {
        QName reqBodyName = part.getDescriptor();
        JAXBType jaxbType = getJAXBType(part);
        Block block = new Block(reqBodyName, jaxbType, part);
        if (unwrappable) {
            // So build body and header blocks and set to request and response
            JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
            block = new Block(reqBodyName, jaxbStructType, part);
            if (ModelerUtils.isBoundToSOAPBody(part)) {
                if (part.isIN()) {
                    req.addBodyBlock(block);
                } else if (part.isOUT()) {
                    res.addBodyBlock(block);
                } else if (part.isINOUT()) {
                    req.addBodyBlock(block);
                    res.addBodyBlock(block);
                }
            } else if (ModelerUtils.isUnbound(part)) {
                if (part.isIN()) {
                    req.addUnboundBlock(block);
                } else if (part.isOUT()) {
                    res.addUnboundBlock(block);
                } else if (part.isINOUT()) {
                    req.addUnboundBlock(block);
                    res.addUnboundBlock(block);
                }
            }
            if (part.isIN() || part.isINOUT()) {
                params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
                int index = 0;
                Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
                for (Parameter param : params) {
                    param.setParameterIndex(index++);
                    param.setMode(mode);
                    setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
                }
            } else if (part.isOUT()) {
                outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
                for (Parameter param : outParams) {
                    param.setMode(Mode.OUT);
                    setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
                }
            }
        } else {
            if (ModelerUtils.isBoundToSOAPBody(part)) {
                if (part.isIN()) {
                    req.addBodyBlock(block);
                } else if (part.isOUT()) {
                    res.addBodyBlock(block);
                } else if (part.isINOUT()) {
                    req.addBodyBlock(block);
                    res.addBodyBlock(block);
                }
            } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
                if (part.isIN()) {
                    req.addHeaderBlock(block);
                } else if (part.isOUT()) {
                    res.addHeaderBlock(block);
                } else if (part.isINOUT()) {
                    req.addHeaderBlock(block);
                    res.addHeaderBlock(block);
                }
            } else if (ModelerUtils.isBoundToMimeContent(part)) {
                List<MIMEContent> mimeContents;
                if (part.isIN()) {
                    mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
                    jaxbType = getAttachmentType(mimeContents, part);
                    block = new Block(jaxbType.getName(), jaxbType, part);
                    req.addAttachmentBlock(block);
                } else if (part.isOUT()) {
                    mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
                    jaxbType = getAttachmentType(mimeContents, part);
                    block = new Block(jaxbType.getName(), jaxbType, part);
                    res.addAttachmentBlock(block);
                } else if (part.isINOUT()) {
                    mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
                    jaxbType = getAttachmentType(mimeContents, part);
                    block = new Block(jaxbType.getName(), jaxbType, part);
                    req.addAttachmentBlock(block);
                    res.addAttachmentBlock(block);
                    mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
                    JAXBType outJaxbType = getAttachmentType(mimeContents, part);
                    String inType = jaxbType.getJavaType().getType().getName();
                    String outType = outJaxbType.getJavaType().getType().getName();
                    TypeAndAnnotation inTa = jaxbType.getJavaType().getType().getTypeAnn();
                    TypeAndAnnotation outTa = outJaxbType.getJavaType().getType().getTypeAnn();
                    if ((((inTa != null) && (outTa != null) && inTa.equals(outTa))) && !inType.equals(outType)) {
                        String javaType = "jakarta.activation.DataHandler";
                        // S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
                        // JCodeModel cm = jaxbModel.generateCode(null, errReceiver);
                        JType jt = options.getCodeModel().ref(javaType);
                        JAXBTypeAndAnnotation jaxbTa = jaxbType.getJavaType().getType();
                        jaxbTa.setType(jt);
                    }
                }
            } else if (ModelerUtils.isUnbound(part)) {
                if (part.isIN()) {
                    req.addUnboundBlock(block);
                } else if (part.isOUT()) {
                    res.addUnboundBlock(block);
                } else if (part.isINOUT()) {
                    req.addUnboundBlock(block);
                    res.addUnboundBlock(block);
                }
            }
            Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
            param.setMode(part.getMode());
            if (part.isReturn()) {
                param.setParameterIndex(-1);
            } else {
                param.setParameterIndex(pIndex++);
            }
            if (part.isIN()) {
                setCustomizedParameterName(info.bindingOperation, inMsg, part, param, false);
            } else if (outMsg != null) {
                setCustomizedParameterName(info.bindingOperation, outMsg, part, param, false);
            }
            params.add(param);
        }
    }
    if (unwrappable && (outParams != null)) {
        int index = params.size();
        for (Parameter param : outParams) {
            if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
                param.setParameterIndex(-1);
            } else {
                Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
                if ((inParam != null) && inParam.isIN()) {
                    QName inElementName = inParam.getType().getName();
                    QName outElementName = param.getType().getName();
                    String inJavaType = inParam.getTypeName();
                    String outJavaType = param.getTypeName();
                    TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
                    TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
                    QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
                    QName outRawTypeName = ModelerUtils.getRawTypeName(param);
                    if (inElementName.getLocalPart().equals(outElementName.getLocalPart()) && inJavaType.equals(outJavaType) && (inTa == null || outTa == null || inTa.equals(outTa)) && (inRawTypeName == null || outRawTypeName == null || inRawTypeName.equals(outRawTypeName))) {
                        inParam.setMode(Mode.INOUT);
                        continue;
                    }
                }
                if (outParams.size() == 1) {
                    param.setParameterIndex(-1);
                } else {
                    param.setParameterIndex(index++);
                }
            }
            params.add(param);
        }
    }
    return params;
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TypeAndAnnotation(com.sun.tools.xjc.api.TypeAndAnnotation) MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent) JType(com.sun.codemodel.JType)

Example 2 with MIMEContent

use of com.sun.tools.ws.wsdl.document.mime.MIMEContent in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method getRpcLitParameters.

private List<Parameter> getRpcLitParameters(Request req, Response res, Block reqBlock, Block resBlock, List<MessagePart> paramList) {
    List<Parameter> params = new ArrayList<>();
    Message inMsg = getInputMessage();
    Message outMsg = getOutputMessage();
    S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType()).getJaxbModel().getS2JJAXBModel();
    List<Parameter> inParams = ModelerUtils.createRpcLitParameters(inMsg, reqBlock, jaxbModel, errReceiver);
    List<Parameter> outParams = null;
    if (outMsg != null) {
        outParams = ModelerUtils.createRpcLitParameters(outMsg, resBlock, jaxbModel, errReceiver);
    }
    // create parameters for header and mime parts
    int index = 0;
    for (MessagePart part : paramList) {
        Parameter param = null;
        if (ModelerUtils.isBoundToSOAPBody(part)) {
            if (part.isIN()) {
                param = ModelerUtils.getParameter(part.getName(), inParams);
            } else if (outParams != null) {
                param = ModelerUtils.getParameter(part.getName(), outParams);
            }
        } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
            QName headerName = part.getDescriptor();
            JAXBType jaxbType = getJAXBType(part);
            Block headerBlock = new Block(headerName, jaxbType, part);
            param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
            if (part.isIN()) {
                req.addHeaderBlock(headerBlock);
            } else if (part.isOUT()) {
                res.addHeaderBlock(headerBlock);
            } else if (part.isINOUT()) {
                req.addHeaderBlock(headerBlock);
                res.addHeaderBlock(headerBlock);
            }
        } else if (ModelerUtils.isBoundToMimeContent(part)) {
            List<MIMEContent> mimeContents;
            if (part.isIN() || part.isINOUT()) {
                mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
            } else {
                mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
            }
            JAXBType type = getAttachmentType(mimeContents, part);
            // create Parameters in request or response
            // Block mimeBlock = new Block(new QName(part.getName()), type);
            Block mimeBlock = new Block(type.getName(), type, part);
            param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
            if (part.isIN()) {
                req.addAttachmentBlock(mimeBlock);
            } else if (part.isOUT()) {
                res.addAttachmentBlock(mimeBlock);
            } else if (part.isINOUT()) {
                mimeContents = getMimeContents(info.bindingOperation.getOutput(), getOutputMessage(), part.getName());
                JAXBType outJaxbType = getAttachmentType(mimeContents, part);
                String inType = type.getJavaType().getType().getName();
                String outType = outJaxbType.getJavaType().getType().getName();
                if (!inType.equals(outType)) {
                    String javaType = "jakarta.activation.DataHandler";
                    JType jt = options.getCodeModel().ref(javaType);
                    JAXBTypeAndAnnotation jaxbTa = type.getJavaType().getType();
                    jaxbTa.setType(jt);
                }
                req.addAttachmentBlock(mimeBlock);
                res.addAttachmentBlock(mimeBlock);
            }
        } else if (ModelerUtils.isUnbound(part)) {
            QName name = part.getDescriptor();
            JAXBType type = getJAXBType(part);
            Block unboundBlock = new Block(name, type, part);
            if (part.isIN()) {
                req.addUnboundBlock(unboundBlock);
            } else if (part.isOUT()) {
                res.addUnboundBlock(unboundBlock);
            } else if (part.isINOUT()) {
                req.addUnboundBlock(unboundBlock);
                res.addUnboundBlock(unboundBlock);
            }
            param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
        }
        if (param != null) {
            if (part.isReturn()) {
                param.setParameterIndex(-1);
            } else {
                param.setParameterIndex(index++);
            }
            param.setMode(part.getMode());
            params.add(param);
        }
    }
    for (Parameter param : params) {
        if (param.isIN()) {
            setCustomizedParameterName(info.portTypeOperation, inMsg, inMsg.getPart(param.getName()), param, false);
        } else if (outMsg != null) {
            setCustomizedParameterName(info.portTypeOperation, outMsg, outMsg.getPart(param.getName()), param, false);
        }
    }
    return params;
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent) S2JJAXBModel(com.sun.tools.xjc.api.S2JJAXBModel) JType(com.sun.codemodel.JType)

Example 3 with MIMEContent

use of com.sun.tools.ws.wsdl.document.mime.MIMEContent in project metro-jax-ws by eclipse-ee4j.

the class WSDLModelerBase method getMimeContentPart.

private MessagePart getMimeContentPart(Message message, MIMEPart part) {
    for (MIMEContent mimeContent : getMimeContents(part)) {
        String mimeContentPartName = mimeContent.getPart();
        MessagePart mPart = message.getPart(mimeContentPartName);
        // RXXXX mime:content MUST have part attribute
        if (null == mPart) {
            error(mimeContent, ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(mimeContentPartName, message.getName()));
        }
        mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
        return mPart;
    }
    return null;
}
Also used : MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent)

Example 4 with MIMEContent

use of com.sun.tools.ws.wsdl.document.mime.MIMEContent in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method getRequestParameters.

private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
    Message inputMessage = getInputMessage();
    // there is no input message, return zero parameters
    if (inputMessage != null && !inputMessage.parts().hasNext()) {
        return new ArrayList<>();
    }
    List<Parameter> inParameters = null;
    QName reqBodyName;
    Block reqBlock;
    JAXBType jaxbReqType;
    boolean unwrappable = isUnwrappable();
    boolean doneSOAPBody = false;
    // setup request parameters
    for (String inParamName : parameterList) {
        MessagePart part = inputMessage.getPart(inParamName);
        if (part == null) {
            continue;
        }
        reqBodyName = part.getDescriptor();
        jaxbReqType = getJAXBType(part);
        if (unwrappable) {
            // So build body and header blocks and set to request and response
            JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
            reqBlock = new Block(reqBodyName, jaxbRequestType, part);
            if (ModelerUtils.isBoundToSOAPBody(part)) {
                request.addBodyBlock(reqBlock);
            } else if (ModelerUtils.isUnbound(part)) {
                request.addUnboundBlock(reqBlock);
            }
            inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
            for (Parameter param : inParameters) {
                setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
            }
        } else {
            reqBlock = new Block(reqBodyName, jaxbReqType, part);
            if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
                doneSOAPBody = true;
                request.addBodyBlock(reqBlock);
            } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
                request.addHeaderBlock(reqBlock);
            } else if (ModelerUtils.isBoundToMimeContent(part)) {
                List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
                jaxbReqType = getAttachmentType(mimeContents, part);
                // reqBlock = new Block(new QName(part.getName()), jaxbReqType);
                reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
                request.addAttachmentBlock(reqBlock);
            } else if (ModelerUtils.isUnbound(part)) {
                request.addUnboundBlock(reqBlock);
            }
            if (inParameters == null) {
                inParameters = new ArrayList<>();
            }
            Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
            setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
            inParameters.add(param);
        }
    }
    return inParameters;
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent)

Example 5 with MIMEContent

use of com.sun.tools.ws.wsdl.document.mime.MIMEContent in project metro-jax-ws by eclipse-ee4j.

the class WSDLModelerBase method validateMimeParts.

/**
 */
protected boolean validateMimeParts(Iterable<MIMEPart> mimeParts) {
    boolean gotRootPart = false;
    List<MIMEContent> mimeContents = new ArrayList<>();
    for (MIMEPart mPart : mimeParts) {
        for (TWSDLExtension obj : mPart.extensions()) {
            if (obj instanceof SOAPBody) {
                if (gotRootPart) {
                    warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_MORE_THAN_ONE_SOAP_BODY(info.operation.getName().getLocalPart()));
                    return false;
                }
                gotRootPart = true;
            } else if (obj instanceof MIMEContent) {
                mimeContents.add((MIMEContent) obj);
            }
        }
        if (!validateMimeContentPartNames(mimeContents)) {
            return false;
        }
        if (mPart.getName() != null) {
            warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_NAME_NOT_ALLOWED(info.portTypeOperation.getName()));
        }
    }
    return true;
}
Also used : MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent) TWSDLExtension(com.sun.tools.ws.api.wsdl.TWSDLExtension) MIMEPart(com.sun.tools.ws.wsdl.document.mime.MIMEPart)

Aggregations

MIMEContent (com.sun.tools.ws.wsdl.document.mime.MIMEContent)6 Message (com.sun.tools.ws.wsdl.document.Message)3 QName (javax.xml.namespace.QName)3 JType (com.sun.codemodel.JType)2 TWSDLExtension (com.sun.tools.ws.api.wsdl.TWSDLExtension)1 MIMEPart (com.sun.tools.ws.wsdl.document.mime.MIMEPart)1 S2JJAXBModel (com.sun.tools.xjc.api.S2JJAXBModel)1 TypeAndAnnotation (com.sun.tools.xjc.api.TypeAndAnnotation)1 Mode (jakarta.jws.WebParam.Mode)1