Search in sources :

Example 1 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method sortMethodParameters.

/**
 * Sorts the parameters for the method by their position
 * @param method the {@link JavaMethod} used to sort the parameters
 * @return the sorted {@link List} of parameters
 */
protected List<ParameterImpl> sortMethodParameters(JavaMethodImpl method) {
    Set<ParameterImpl> paramSet = new HashSet<>();
    List<ParameterImpl> sortedParams = new ArrayList<>();
    if (isRpcLit(method)) {
        for (ParameterImpl param : method.getRequestParameters()) {
            if (param instanceof WrapperParameter) {
                paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
            } else {
                paramSet.add(param);
            }
        }
        for (ParameterImpl param : method.getResponseParameters()) {
            if (param instanceof WrapperParameter) {
                paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
            } else {
                paramSet.add(param);
            }
        }
    } else {
        paramSet.addAll(method.getRequestParameters());
        paramSet.addAll(method.getResponseParameters());
    }
    Iterator<ParameterImpl> params = paramSet.iterator();
    if (paramSet.isEmpty())
        return sortedParams;
    ParameterImpl param = params.next();
    sortedParams.add(param);
    ParameterImpl sortedParam;
    int pos;
    for (int i = 1; i < paramSet.size(); i++) {
        param = params.next();
        for (pos = 0; pos < i; pos++) {
            sortedParam = sortedParams.get(pos);
            if (param.getIndex() == sortedParam.getIndex() && param instanceof WrapperParameter)
                break;
            if (param.getIndex() < sortedParam.getIndex()) {
                break;
            }
        }
        sortedParams.add(pos, param);
    }
    return sortedParams;
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl) ArrayList(java.util.ArrayList) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) HashSet(java.util.HashSet)

Example 2 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateSOAPHeaders.

protected void generateSOAPHeaders(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {
    for (ParameterImpl headerParam : parameters) {
        Header header = writer._element(Header.class);
        header.message(message);
        header.part(headerParam.getPartName());
        header.use(LITERAL);
    }
}
Also used : Header(com.sun.xml.ws.wsdl.writer.document.soap.Header) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 3 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateSOAP12Headers.

protected void generateSOAP12Headers(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {
    for (ParameterImpl headerParam : parameters) {
        com.sun.xml.ws.wsdl.writer.document.soap12.Header header = writer._element(com.sun.xml.ws.wsdl.writer.document.soap12.Header.class);
        header.message(message);
        header.part(headerParam.getPartName());
        header.use(LITERAL);
    }
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 4 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateBindingOperation.

protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    List<ParameterImpl> bodyParams = new ArrayList<>();
    List<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    operation.soapOperation().soapAction(soapBinding.getSOAPAction());
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    BodyType body = input._element(Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse() == Use.LITERAL) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAPHeaders(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            StringBuilder parts = new StringBuilder();
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
                if (param != null) {
                    if (isRpc) {
                        int i = 0;
                        for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                            if (i++ > 0) {
                                parts.append(" ");
                            }
                            parts.append(parameter.getPartName());
                        }
                    } else {
                        parts = new StringBuilder(param.getPartName());
                    }
                }
            }
            body.parts(parts.toString());
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAPHeaders(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) BodyType(com.sun.xml.ws.wsdl.writer.document.soap.BodyType) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body)

Example 5 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateRpcParameterOrder.

/**
 * Generates the parameterOrder for a PortType operation
 * @param operation the operation to generate the parameterOrder for
 * @param method the {@link JavaMethod} to generate the parameterOrder from
 */
protected void generateRpcParameterOrder(Operation operation, JavaMethodImpl method) {
    String partName;
    StringBuilder paramOrder = new StringBuilder();
    Set<String> partNames = new HashSet<>();
    List<ParameterImpl> sortedParams = sortMethodParameters(method);
    int i = 0;
    for (ParameterImpl parameter : sortedParams) {
        if (parameter.getIndex() >= 0) {
            partName = parameter.getPartName();
            if (!partNames.contains(partName)) {
                if (i++ > 0)
                    paramOrder.append(' ');
                paramOrder.append(partName);
                partNames.add(partName);
            }
        }
    }
    if (i > 1) {
        operation.parameterOrder(paramOrder.toString());
    }
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl) HashSet(java.util.HashSet)

Aggregations

ParameterImpl (com.sun.xml.ws.model.ParameterImpl)15 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)9 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)5 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)3 QName (javax.xml.namespace.QName)3 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)2 SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)2 BindingOperationType (com.sun.xml.ws.wsdl.writer.document.BindingOperationType)2 Fault (com.sun.xml.ws.wsdl.writer.document.Fault)2 Body (com.sun.xml.ws.wsdl.writer.document.soap.Body)2 SOAPFault (com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)2 Schema (com.sun.xml.ws.wsdl.writer.document.xsd.Schema)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 HashMap (java.util.HashMap)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)1 Message (com.sun.xml.ws.wsdl.writer.document.Message)1