Search in sources :

Example 1 with Mode

use of jakarta.jws.WebParam.Mode in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processRpcMethod.

/**
 * models a rpc/literal method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param methodName the name of the <code>method</code> being modeled.
 * @param operationName the WSDL operation name for this <code>method</code>
 * @param method the runtime model <code>JavaMethod</code> instance being created
 */
protected void processRpcMethod(JavaMethodImpl javaMethod, String methodName, String operationName, Method method) {
    boolean isOneway = getAnnotation(method, Oneway.class) != null;
    // use Map to build parameters in the part order when they are known.
    // if part is unbound, we just put them at the end, and for that we
    // use a large index (10000+) to avoid colliding with ordered ones.
    // this assumes that there's no operation with # of parameters > 10000,
    // but I think it's a pretty safe assumption - KK.
    Map<Integer, ParameterImpl> resRpcParams = new TreeMap<>();
    Map<Integer, ParameterImpl> reqRpcParams = new TreeMap<>();
    // Lets take the service namespace and overwrite it with the one we get it from wsdl
    String reqNamespace = targetNamespace;
    String respNamespace = targetNamespace;
    if (binding != null && Style.RPC.equals(binding.getBinding().getStyle())) {
        QName opQName = new QName(binding.getBinding().getPortTypeName().getNamespaceURI(), operationName);
        WSDLBoundOperation op = binding.getBinding().get(opQName);
        if (op != null) {
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getRequestNamespace() != null) {
                reqNamespace = op.getRequestNamespace();
            }
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getResponseNamespace() != null) {
                respNamespace = op.getResponseNamespace();
            }
        }
    }
    QName reqElementName = new QName(reqNamespace, operationName);
    javaMethod.setRequestPayloadName(reqElementName);
    QName resElementName = null;
    if (!isOneway) {
        resElementName = new QName(respNamespace, operationName + RESPONSE);
    }
    Class wrapperType = WrapperComposite.class;
    TypeInfo typeRef = new TypeInfo(reqElementName, wrapperType);
    WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
    requestWrapper.setInBinding(ParameterBinding.BODY);
    javaMethod.addParameter(requestWrapper);
    WrapperParameter responseWrapper = null;
    if (!isOneway) {
        typeRef = new TypeInfo(resElementName, wrapperType);
        responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
        responseWrapper.setOutBinding(ParameterBinding.BODY);
        javaMethod.addParameter(responseWrapper);
    }
    Class returnType = method.getReturnType();
    String resultName = RETURN;
    String resultTNS = targetNamespace;
    String resultPartName = resultName;
    boolean isResultHeader = false;
    WebResult webResult = getAnnotation(method, WebResult.class);
    if (webResult != null) {
        isResultHeader = webResult.header();
        if (webResult.name().length() > 0)
            resultName = webResult.name();
        if (webResult.partName().length() > 0) {
            resultPartName = webResult.partName();
            if (!isResultHeader)
                resultName = resultPartName;
        } else
            resultPartName = resultName;
        if (webResult.targetNamespace().length() > 0)
            resultTNS = webResult.targetNamespace();
        isResultHeader = webResult.header();
    }
    QName resultQName;
    if (isResultHeader)
        resultQName = new QName(resultTNS, resultName);
    else
        resultQName = new QName(resultName);
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
    }
    if (!isOneway && returnType != null && returnType != void.class) {
        Annotation[] rann = getAnnotations(method);
        TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
        metadataReader.getProperties(rTypeReference.properties(), method);
        rTypeReference.setGenericType(method.getGenericReturnType());
        ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
        returnParameter.setPartName(resultPartName);
        if (isResultHeader) {
            returnParameter.setBinding(ParameterBinding.HEADER);
            javaMethod.addParameter(returnParameter);
            rTypeReference.setGlobalElement(true);
        } else {
            ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
            returnParameter.setBinding(rb);
            if (rb.isBody()) {
                rTypeReference.setGlobalElement(false);
                WSDLPart p = getPart(new QName(targetNamespace, operationName), resultPartName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, returnParameter);
                else
                    resRpcParams.put(p.getIndex(), returnParameter);
            } else {
                javaMethod.addParameter(returnParameter);
            }
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        String paramName = "";
        String paramNamespace = "";
        String partName = "";
        boolean isHeader = false;
        if (javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)) {
            continue;
        }
        boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
        // set the actual type argument of Holder in the TypeReference
        if (isHolder) {
            if (clazzType == Holder.class)
                clazzType = erasure(((ParameterizedType) genericParameterTypes[pos]).getActualTypeArguments()[0]);
        }
        Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == jakarta.jws.WebParam.class) {
                jakarta.jws.WebParam webParam = (jakarta.jws.WebParam) annotation;
                paramName = webParam.name();
                partName = webParam.partName();
                isHeader = webParam.header();
                WebParam.Mode mode = webParam.mode();
                paramNamespace = webParam.targetNamespace();
                if (isHolder && mode == Mode.IN)
                    mode = Mode.INOUT;
                paramMode = mode;
                break;
            }
        }
        if (paramName.length() == 0) {
            paramName = "arg" + pos;
        }
        if (partName.length() == 0) {
            partName = paramName;
        } else if (!isHeader) {
            paramName = partName;
        }
        if (partName.length() == 0) {
            partName = paramName;
        }
        QName paramQName;
        if (!isHeader) {
            // its rpclit body param, set namespace to ""
            paramQName = new QName("", paramName);
        } else {
            if (paramNamespace.length() == 0)
                paramNamespace = targetNamespace;
            paramQName = new QName(paramNamespace, paramName);
        }
        typeRef = new TypeInfo(paramQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        param.setPartName(partName);
        if (paramMode == Mode.INOUT) {
            ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
            param.setInBinding(pb);
            pb = getBinding(operationName, partName, isHeader, Mode.OUT);
            param.setOutBinding(pb);
        } else {
            if (isHeader) {
                typeRef.setGlobalElement(true);
                param.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
                param.setBinding(pb);
            }
        }
        if (param.getInBinding().isBody()) {
            typeRef.setGlobalElement(false);
            if (!param.isOUT()) {
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.IN);
                if (p == null)
                    reqRpcParams.put(reqRpcParams.size() + 10000, param);
                else
                    reqRpcParams.put(param.getIndex(), param);
            }
            if (!param.isIN()) {
                if (isOneway) {
                    throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters", portClass.getCanonicalName(), methodName);
                }
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, param);
                else
                    resRpcParams.put(p.getIndex(), param);
            }
        } else {
            javaMethod.addParameter(param);
        }
    }
    for (ParameterImpl p : reqRpcParams.values()) requestWrapper.addWrapperChild(p);
    for (ParameterImpl p : resRpcParams.values()) responseWrapper.addWrapperChild(p);
    processExceptions(javaMethod, method);
}
Also used : jakarta.jws(jakarta.jws) ParameterizedType(java.lang.reflect.ParameterizedType) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite) Mode(jakarta.jws.WebParam.Mode) QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TreeMap(java.util.TreeMap) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) WSDLPart(com.sun.xml.ws.api.model.wsdl.WSDLPart)

Example 2 with Mode

use of jakarta.jws.WebParam.Mode in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processDocWrappedMethod.

/**
 * models a document/literal wrapped method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param methodName the runtime model <code>JavaMethod</code> instance being created
 * @param operationName the runtime model <code>JavaMethod</code> instance being created
 * @param method the <code>method</code> to model
 */
protected void processDocWrappedMethod(JavaMethodImpl javaMethod, String methodName, String operationName, Method method) {
    boolean methodHasHeaderParams = false;
    boolean isOneway = getAnnotation(method, Oneway.class) != null;
    RequestWrapper reqWrapper = getAnnotation(method, RequestWrapper.class);
    ResponseWrapper resWrapper = getAnnotation(method, ResponseWrapper.class);
    String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
    if (packageName == null || packageName.length() == 0) {
        beanPackage = JAXWS_PACKAGE_PD;
    }
    String requestClassName;
    if (reqWrapper != null && reqWrapper.className().length() > 0) {
        requestClassName = reqWrapper.className();
    } else {
        requestClassName = beanPackage + capitalize(method.getName());
    }
    String responseClassName;
    if (resWrapper != null && resWrapper.className().length() > 0) {
        responseClassName = resWrapper.className();
    } else {
        responseClassName = beanPackage + capitalize(method.getName()) + RESPONSE;
    }
    String reqName = operationName;
    String reqNamespace = targetNamespace;
    String reqPartName = "parameters";
    if (reqWrapper != null) {
        if (reqWrapper.targetNamespace().length() > 0)
            reqNamespace = reqWrapper.targetNamespace();
        if (reqWrapper.localName().length() > 0)
            reqName = reqWrapper.localName();
        try {
            if (reqWrapper.partName().length() > 0)
                reqPartName = reqWrapper.partName();
        } catch (LinkageError e) {
        // 2.1 API dopes n't have this method
        // Do nothing, just default to "parameters"
        }
    }
    QName reqElementName = new QName(reqNamespace, reqName);
    javaMethod.setRequestPayloadName(reqElementName);
    Class requestClass = getRequestWrapperClass(requestClassName, method, reqElementName);
    Class responseClass = null;
    String resName = operationName + "Response";
    String resNamespace = targetNamespace;
    QName resElementName = null;
    String resPartName = "parameters";
    if (!isOneway) {
        if (resWrapper != null) {
            if (resWrapper.targetNamespace().length() > 0)
                resNamespace = resWrapper.targetNamespace();
            if (resWrapper.localName().length() > 0)
                resName = resWrapper.localName();
            try {
                if (resWrapper.partName().length() > 0)
                    resPartName = resWrapper.partName();
            } catch (LinkageError e) {
            // 2.1 API does n't have this method
            // Do nothing, just default to "parameters"
            }
        }
        resElementName = new QName(resNamespace, resName);
        responseClass = getResponseWrapperClass(responseClassName, method, resElementName);
    }
    TypeInfo typeRef = new TypeInfo(reqElementName, requestClass);
    typeRef.setNillable(false);
    WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
    requestWrapper.setPartName(reqPartName);
    requestWrapper.setBinding(ParameterBinding.BODY);
    javaMethod.addParameter(requestWrapper);
    WrapperParameter responseWrapper = null;
    if (!isOneway) {
        typeRef = new TypeInfo(resElementName, responseClass);
        typeRef.setNillable(false);
        responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
        javaMethod.addParameter(responseWrapper);
        responseWrapper.setBinding(ParameterBinding.BODY);
    }
    // return value
    WebResult webResult = getAnnotation(method, WebResult.class);
    XmlElement xmlElem = getAnnotation(method, XmlElement.class);
    QName resultQName = getReturnQName(method, webResult, xmlElem);
    Class returnType = method.getReturnType();
    boolean isResultHeader = false;
    if (webResult != null) {
        isResultHeader = webResult.header();
        methodHasHeaderParams = isResultHeader || methodHasHeaderParams;
        if (isResultHeader && xmlElem != null) {
            throw new RuntimeModelerException("@XmlElement cannot be specified on method " + method + " as the return value is bound to header");
        }
        if (resultQName.getNamespaceURI().length() == 0 && webResult.header()) {
            // headers must have a namespace
            resultQName = new QName(targetNamespace, resultQName.getLocalPart());
        }
    }
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
        resultQName = new QName(RETURN);
    }
    resultQName = qualifyWrappeeIfNeeded(resultQName, resNamespace);
    if (!isOneway && (returnType != null) && (!returnType.getName().equals("void"))) {
        Annotation[] rann = getAnnotations(method);
        if (resultQName.getLocalPart() != null) {
            TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
            metadataReader.getProperties(rTypeReference.properties(), method);
            rTypeReference.setGenericType(method.getGenericReturnType());
            ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
            if (isResultHeader) {
                returnParameter.setBinding(ParameterBinding.HEADER);
                javaMethod.addParameter(returnParameter);
            } else {
                returnParameter.setBinding(ParameterBinding.BODY);
                responseWrapper.addWrapperChild(returnParameter);
            }
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        String partName = null;
        String paramName = "arg" + pos;
        // String paramNamespace = "";
        boolean isHeader = false;
        if (javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)) {
            continue;
        }
        boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
        // set the actual type argument of Holder in the TypeReference
        if (isHolder) {
            if (clazzType == Holder.class) {
                clazzType = erasure(((ParameterizedType) genericParameterTypes[pos]).getActualTypeArguments()[0]);
            }
        }
        Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
        WebParam webParam = null;
        xmlElem = null;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == WebParam.class)
                webParam = (WebParam) annotation;
            else if (annotation.annotationType() == XmlElement.class)
                xmlElem = (XmlElement) annotation;
        }
        QName paramQName = getParameterQName(method, webParam, xmlElem, paramName);
        if (webParam != null) {
            isHeader = webParam.header();
            methodHasHeaderParams = isHeader || methodHasHeaderParams;
            if (isHeader && xmlElem != null) {
                throw new RuntimeModelerException("@XmlElement cannot be specified on method " + method + " parameter that is bound to header");
            }
            if (webParam.partName().length() > 0)
                partName = webParam.partName();
            else
                partName = paramQName.getLocalPart();
            if (isHeader && paramQName.getNamespaceURI().equals("")) {
                // headers cannot be in empty namespace
                paramQName = new QName(targetNamespace, paramQName.getLocalPart());
            }
            paramMode = webParam.mode();
            if (isHolder && paramMode == Mode.IN)
                paramMode = Mode.INOUT;
        }
        paramQName = qualifyWrappeeIfNeeded(paramQName, reqNamespace);
        typeRef = new TypeInfo(paramQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        if (isHeader) {
            param.setBinding(ParameterBinding.HEADER);
            javaMethod.addParameter(param);
            param.setPartName(partName);
        } else {
            param.setBinding(ParameterBinding.BODY);
            if (paramMode != Mode.OUT) {
                requestWrapper.addWrapperChild(param);
            }
            if (paramMode != Mode.IN) {
                if (isOneway) {
                    throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters", portClass.getCanonicalName(), methodName);
                }
                responseWrapper.addWrapperChild(param);
            }
        }
    }
    // client mapping.
    if (methodHasHeaderParams) {
        resPartName = "result";
    }
    if (responseWrapper != null)
        responseWrapper.setPartName(resPartName);
    processExceptions(javaMethod, method);
}
Also used : QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType) XmlElement(jakarta.xml.bind.annotation.XmlElement)

Example 3 with Mode

use of jakarta.jws.WebParam.Mode 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 4 with Mode

use of jakarta.jws.WebParam.Mode in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processDocBareMethod.

/**
 * models a document/literal bare method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param operationName the runtime model <code>JavaMethod</code> instance being created
 * @param method the runtime model <code>JavaMethod</code> instance being created
 */
protected void processDocBareMethod(JavaMethodImpl javaMethod, String operationName, Method method) {
    String resultName = operationName + RESPONSE;
    String resultTNS = targetNamespace;
    String resultPartName = null;
    boolean isResultHeader = false;
    WebResult webResult = getAnnotation(method, WebResult.class);
    if (webResult != null) {
        if (webResult.name().length() > 0)
            resultName = webResult.name();
        if (webResult.targetNamespace().length() > 0)
            resultTNS = webResult.targetNamespace();
        resultPartName = webResult.partName();
        isResultHeader = webResult.header();
    }
    Class returnType = method.getReturnType();
    Type gReturnType = method.getGenericReturnType();
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
    }
    if ((returnType != null) && (!returnType.getName().equals("void"))) {
        Annotation[] rann = getAnnotations(method);
        if (resultName != null) {
            QName responseQName = new QName(resultTNS, resultName);
            TypeInfo rTypeReference = new TypeInfo(responseQName, returnType, rann);
            rTypeReference.setGenericType(gReturnType);
            metadataReader.getProperties(rTypeReference.properties(), method);
            ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
            if (resultPartName == null || (resultPartName.length() == 0)) {
                resultPartName = resultName;
            }
            returnParameter.setPartName(resultPartName);
            if (isResultHeader) {
                returnParameter.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
                returnParameter.setBinding(rb);
            }
            javaMethod.addParameter(returnParameter);
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        // method.getName();
        String paramName = operationName;
        String partName = null;
        String requestNamespace = targetNamespace;
        boolean isHeader = false;
        // async
        if (javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)) {
            continue;
        }
        boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
        // set the actual type argument of Holder in the TypeReference
        if (isHolder) {
            if (clazzType == Holder.class)
                clazzType = erasure(((ParameterizedType) genericParameterTypes[pos]).getActualTypeArguments()[0]);
        }
        Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == jakarta.jws.WebParam.class) {
                jakarta.jws.WebParam webParam = (jakarta.jws.WebParam) annotation;
                paramMode = webParam.mode();
                if (isHolder && paramMode == Mode.IN)
                    paramMode = Mode.INOUT;
                isHeader = webParam.header();
                if (isHeader)
                    paramName = "arg" + pos;
                if (paramMode == Mode.OUT && !isHeader)
                    paramName = operationName + RESPONSE;
                if (webParam.name().length() > 0)
                    paramName = webParam.name();
                partName = webParam.partName();
                if (!webParam.targetNamespace().equals("")) {
                    requestNamespace = webParam.targetNamespace();
                }
                break;
            }
        }
        QName requestQName = new QName(requestNamespace, paramName);
        if (!isHeader && paramMode != Mode.OUT)
            javaMethod.setRequestPayloadName(requestQName);
        // doclit/wrapped
        // operationName with upper 1 char
        TypeInfo typeRef = new TypeInfo(requestQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        if (partName == null || (partName.length() == 0)) {
            partName = paramName;
        }
        param.setPartName(partName);
        if (paramMode == Mode.INOUT) {
            ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
            param.setInBinding(pb);
            pb = getBinding(operationName, partName, isHeader, Mode.OUT);
            param.setOutBinding(pb);
        } else {
            if (isHeader) {
                param.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
                param.setBinding(pb);
            }
        }
        javaMethod.addParameter(param);
    }
    validateDocBare(javaMethod);
    processExceptions(javaMethod, method);
}
Also used : QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) jakarta.jws(jakarta.jws) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType)

Aggregations

Mode (jakarta.jws.WebParam.Mode)4 QName (javax.xml.namespace.QName)4 ExceptionType (com.sun.xml.ws.api.model.ExceptionType)3 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)3 Annotation (java.lang.annotation.Annotation)3 ParameterizedType (java.lang.reflect.ParameterizedType)3 Type (java.lang.reflect.Type)3 ParameterBinding (com.sun.xml.ws.api.model.ParameterBinding)2 jakarta.jws (jakarta.jws)2 JType (com.sun.codemodel.JType)1 Message (com.sun.tools.ws.wsdl.document.Message)1 MIMEContent (com.sun.tools.ws.wsdl.document.mime.MIMEContent)1 TypeAndAnnotation (com.sun.tools.xjc.api.TypeAndAnnotation)1 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)1 WSDLPart (com.sun.xml.ws.api.model.wsdl.WSDLPart)1 WrapperComposite (com.sun.xml.ws.spi.db.WrapperComposite)1 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 TreeMap (java.util.TreeMap)1