Search in sources :

Example 11 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class ServiceProcessor method processMultipart.

public void processMultipart(JavaMethod jm, BindingOperationInfo operation, MIMEMultipartRelated ext, JavaType.Style style) throws ToolException {
    List<MIMEPart> mimeParts = CastUtils.cast(ext.getMIMEParts());
    for (MIMEPart mPart : mimeParts) {
        List<ExtensibilityElement> extns = CastUtils.cast(mPart.getExtensibilityElements());
        for (ExtensibilityElement extElement : extns) {
            if (extElement instanceof MIMEContent) {
                MIMEContent mimeContent = (MIMEContent) extElement;
                String mimeJavaType = getJavaTypeForMimeType(mPart);
                if (JavaType.Style.IN.equals(style)) {
                    String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
                    JavaParameter jp = jm.getParameter(paramName);
                    if (jp == null) {
                        Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
                        throw new ToolException(message);
                    }
                    if (!jp.getClassName().equals(mimeJavaType)) {
                        // jp.setType(mimeJavaType);
                        jp.setClassName(mimeJavaType);
                    }
                } else if (JavaType.Style.OUT.equals(style)) {
                    JavaType jp = null;
                    if (!"void".equals(jm.getReturn().getType()) && mimeContent.getPart().equals(jm.getReturn().getName())) {
                        jp = jm.getReturn();
                        jp.setClassName(mimeJavaType);
                    }
                    if (jp == null) {
                        for (JavaParameter para : jm.getParameters()) {
                            if (mimeContent.getPart().equals(para.getPartName())) {
                                jp = para;
                            }
                        }
                        if (jp != null) {
                            ((JavaParameter) jp).setClassName(mimeJavaType);
                        }
                    }
                    if (jp == null) {
                        Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
                        throw new ToolException(message);
                    }
                }
            } else if (extElement instanceof SOAPHeader) {
                processSoapHeader(jm, operation, extElement);
            }
        }
    }
}
Also used : JavaType(org.apache.cxf.tools.common.model.JavaType) MIMEContent(javax.wsdl.extensions.mime.MIMEContent) Message(org.apache.cxf.common.i18n.Message) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) ToolException(org.apache.cxf.tools.common.ToolException) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 12 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class ServiceProcessor method processParameter.

private void processParameter(JavaMethod jm, BindingOperationInfo operation) throws ToolException {
    // process input
    List<ExtensibilityElement> inbindings = null;
    if (operation.getInput() != null) {
        inbindings = operation.getInput().getExtensors(ExtensibilityElement.class);
    }
    if (inbindings == null) {
        inbindings = new ArrayList<>();
    }
    String use = null;
    for (ExtensibilityElement ext : inbindings) {
        if (SOAPBindingUtil.isSOAPBody(ext)) {
            SoapBody soapBody = SOAPBindingUtil.getSoapBody(ext);
            use = soapBody.getUse();
        } else if (SOAPBindingUtil.isSOAPHeader(ext)) {
            processSoapHeader(jm, operation, ext);
        }
        if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
            processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.IN);
        }
    }
    // process output
    if (operation.getOutput() != null) {
        List<ExtensibilityElement> outbindings = operation.getOutput().getExtensors(ExtensibilityElement.class);
        if (outbindings == null) {
            outbindings = new ArrayList<>();
        }
        for (ExtensibilityElement ext : outbindings) {
            if (SOAPBindingUtil.isSOAPHeader(ext)) {
                SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
                if (isOutOfBandHeader(operation.getOutput(), ext)) {
                    continue;
                }
                boolean found = false;
                for (JavaParameter parameter : jm.getParameters()) {
                    if (soapHeader.getPart().equals(parameter.getPartName())) {
                        setParameterAsHeader(parameter);
                        found = true;
                    }
                }
                if (jm.getReturn().getName() != null && jm.getReturn().getName().equals(soapHeader.getPart())) {
                    found = true;
                }
                if (Boolean.valueOf((String) context.get(ToolConstants.CFG_EXTRA_SOAPHEADER)) && !found) {
                    // Header can't be found in java method parameters, in
                    // different message
                    // other than messages used in porttype operation
                    ParameterProcessor processor = new ParameterProcessor(context);
                    MessagePartInfo exPart = service.getMessage(soapHeader.getMessage()).getMessagePart(new QName(soapHeader.getMessage().getNamespaceURI(), soapHeader.getPart()));
                    JavaParameter jp = processor.addParameterFromBinding(jm, exPart, JavaType.Style.OUT);
                    setParameterAsHeader(jp);
                }
            }
            if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
                processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.OUT);
            }
        }
    }
    jm.setSoapUse(SOAPBindingUtil.getSoapUse(use));
    if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.ENCODED == jm.getSoapUse()) {
        System.err.println("** Unsupported RPC-Encoded Style Use **");
    }
    if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
        return;
    }
    if (javax.jws.soap.SOAPBinding.Style.DOCUMENT == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
        return;
    }
}
Also used : QName(javax.xml.namespace.QName) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated)

Example 13 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class WebParamAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaParameter parameter = null;
    if (ja instanceof JavaParameter) {
        parameter = (JavaParameter) ja;
    } else {
        throw new RuntimeException("WebParamAnnotator only annotate the JavaParameter");
    }
    JavaMethod method = parameter.getMethod();
    if (method.hasParameter(parameter.getName())) {
        JavaParameter paramInList = method.getParameter(parameter.getName());
        if (paramInList.isIN() && parameter.isOUT()) {
            parameter.setStyle(JavaType.Style.INOUT);
        }
    }
    JAnnotation webParamAnnotation = new JAnnotation(WebParam.class);
    String name = parameter.getName();
    String targetNamespace = method.getInterface().getNamespace();
    String partName = null;
    if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader()) {
        targetNamespace = parameter.getTargetNamespace();
        if (parameter.getQName() != null) {
            name = parameter.getQName().getLocalPart();
        }
        if (!method.isWrapperStyle()) {
            partName = parameter.getPartName();
        }
    }
    if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
        name = parameter.getPartName();
        partName = parameter.getPartName();
    }
    if (partName != null) {
        webParamAnnotation.addElement(new JAnnotationElement("partName", partName));
    }
    if (parameter.getStyle() == JavaType.Style.OUT) {
        webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.OUT));
    } else if (parameter.getStyle() == JavaType.Style.INOUT) {
        webParamAnnotation.addElement(new JAnnotationElement("mode", WebParam.Mode.INOUT));
    }
    webParamAnnotation.addElement(new JAnnotationElement("name", name));
    if (null != targetNamespace && (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT || parameter.isHeader())) {
        webParamAnnotation.addElement(new JAnnotationElement("targetNamespace", targetNamespace));
    }
    for (String importClz : webParamAnnotation.getImports()) {
        parameter.getMethod().getInterface().addImport(importClz);
    }
    if (forceHeader) {
        webParamAnnotation.addElement(new JAnnotationElement("header", true, true));
    }
    parameter.addAnnotation("WebParam", webParamAnnotation);
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 14 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class XmlJavaTypeAdapterAnnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
    jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else {
        throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
    }
    jf.addImport(XmlJavaTypeAdapter.class.getName());
    jf.addImport(adapter.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 15 with JavaParameter

use of org.apache.cxf.tools.common.model.JavaParameter in project cxf by apache.

the class XmlListAnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlList", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlList", jaxbAnnotation);
    } else {
        throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
    }
    jf.addImport(XmlList.class.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) XmlList(javax.xml.bind.annotation.XmlList)

Aggregations

JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)18 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)9 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)5 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)5 QName (javax.xml.namespace.QName)4 Message (org.apache.cxf.common.i18n.Message)3 ToolException (org.apache.cxf.tools.common.ToolException)3 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)3 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2 OperationInfo (org.apache.cxf.service.model.OperationInfo)2 JavaException (org.apache.cxf.tools.common.model.JavaException)2 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)2 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)2 JAXWSParameter (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter)2