Search in sources :

Example 11 with JAnnotationElement

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

the class WrapperBeanFieldAnnotator method annotate.

public void annotate(final JavaAnnotatable field) {
    JavaField jField = null;
    if (field instanceof JavaField) {
        jField = (JavaField) field;
    } else {
        throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
    }
    String rawName = jField.getRawName();
    boolean hasEl = false;
    for (Annotation ann : jField.getJaxbAnnotaions()) {
        if (ann instanceof XmlMimeType) {
            JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
            mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
            jField.addAnnotation(mimeAnno);
        } else if (ann instanceof XmlJavaTypeAdapter) {
            JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
            jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
            jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlAttachmentRef) {
            JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlList) {
            JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlElement) {
            hasEl = true;
            XmlElement el = (XmlElement) ann;
            JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
            xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
            if (!StringUtils.isEmpty(el.namespace())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
            }
            if (el.nillable()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
            }
            if (el.required()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
            }
            if (!StringUtils.isEmpty(el.defaultValue())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
            }
            jField.addAnnotation(xmlElementAnnotation);
        }
    }
    if (!hasEl) {
        JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
        xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
        if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
            xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
        }
        jField.addAnnotation(xmlElementAnnotation);
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Example 12 with JAnnotationElement

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

the class ServiceProcessor method setParameterAsHeader.

private void setParameterAsHeader(JavaParameter parameter) {
    parameter.setHeader(true);
    JAnnotation parameterAnnotation = parameter.getAnnotation("WebParam");
    parameterAnnotation.addElement(new JAnnotationElement("header", true, true));
    parameterAnnotation.addElement(new JAnnotationElement("name", parameter.getQName().getLocalPart()));
    parameterAnnotation.addElement(new JAnnotationElement("partName", parameter.getPartName()));
    parameterAnnotation.addElement(new JAnnotationElement("targetNamespace", parameter.getTargetNamespace()));
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement)

Example 13 with JAnnotationElement

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

the class BindingAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaInterface intf;
    if (ja instanceof JavaInterface) {
        intf = (JavaInterface) ja;
    } else {
        throw new RuntimeException("BindingAnnotator can only annotate JavaInterface");
    }
    if (processBinding(intf)) {
        JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
        if (!SOAPBinding.Style.DOCUMENT.equals(intf.getSOAPStyle())) {
            bindingAnnotation.addElement(new JAnnotationElement("style", intf.getSOAPStyle()));
        }
        if (!SOAPBinding.Use.LITERAL.equals(intf.getSOAPUse())) {
            bindingAnnotation.addElement(new JAnnotationElement("use", intf.getSOAPUse()));
        }
        if (intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT && intf.getSOAPParameterStyle() != SOAPBinding.ParameterStyle.WRAPPED) {
            bindingAnnotation.addElement(new JAnnotationElement("parameterStyle", intf.getSOAPParameterStyle()));
        }
        intf.addAnnotation(bindingAnnotation);
    }
    for (JavaMethod method : intf.getMethods()) {
        if (!method.isAsync()) {
            method.annotate(new SoapBindingAnnotator());
        }
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 14 with JAnnotationElement

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

the class WebMethodAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method = null;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("WebMethod can only annotate JavaMethod");
    }
    String operationName = method.getOperationName();
    JAnnotation methodAnnotation = new JAnnotation(WebMethod.class);
    if (!method.getName().equals(operationName)) {
        methodAnnotation.addElement(new JAnnotationElement("operationName", operationName));
    }
    if (!StringUtils.isEmpty(method.getSoapAction())) {
        methodAnnotation.addElement(new JAnnotationElement("action", method.getSoapAction()));
    }
    method.addAnnotation("WebMethod", methodAnnotation);
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 15 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement 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)

Aggregations

JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)20 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)20 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)11 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 ArrayList (java.util.ArrayList)4 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)3 Test (org.junit.Test)3 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 Message (org.apache.cxf.common.i18n.Message)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 Annotation (java.lang.annotation.Annotation)1 HandlerChain (javax.jws.HandlerChain)1 SOAPBinding (javax.jws.soap.SOAPBinding)1 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlList (javax.xml.bind.annotation.XmlList)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlType (javax.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)1