Search in sources :

Example 16 with JAnnotation

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

the class WrapperBeanAnnotator method annotate.

public void annotate(final JavaAnnotatable clz) {
    final WrapperBeanClass beanClass;
    if (clz instanceof WrapperBeanClass) {
        beanClass = (WrapperBeanClass) clz;
    } else {
        throw new RuntimeException("WrapperBeanAnnotator expect JavaClass as input");
    }
    JAnnotation xmlRootElement = new JAnnotation(XmlRootElement.class);
    xmlRootElement.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
    xmlRootElement.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
    JAnnotation xmlAccessorType = new JAnnotation(XmlAccessorType.class);
    xmlAccessorType.addElement(new JAnnotationElement(null, XmlAccessType.FIELD));
    XmlType tp = null;
    if (sourceClass != null) {
        tp = sourceClass.getAnnotation(XmlType.class);
    }
    JAnnotation xmlType = new JAnnotation(XmlType.class);
    if (tp == null) {
        xmlType.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
        xmlType.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
    } else {
        if (!"##default".equals(tp.name())) {
            xmlType.addElement(new JAnnotationElement("name", tp.name()));
        }
        if (!"##default".equals(tp.namespace())) {
            xmlType.addElement(new JAnnotationElement("namespace", tp.namespace()));
        }
        if (!StringUtils.isEmpty(tp.factoryMethod())) {
            xmlType.addElement(new JAnnotationElement("factoryMethod", tp.factoryMethod()));
        }
        if (tp.propOrder().length != 1 || !StringUtils.isEmpty(tp.propOrder()[0])) {
            xmlType.addElement(new JAnnotationElement("propOrder", tp.propOrder()));
        }
    }
    List<String> props = new ArrayList<>();
    for (JavaField f : beanClass.getFields()) {
        props.add(f.getParaName());
    }
    if (props.size() > 1) {
        xmlType.addElement(new JAnnotationElement("propOrder", props));
    }
    // Revisit: why annotation is string?
    beanClass.addAnnotation(xmlRootElement);
    beanClass.addAnnotation(xmlAccessorType);
    beanClass.addAnnotation(xmlType);
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass) XmlType(javax.xml.bind.annotation.XmlType)

Example 17 with JAnnotation

use of org.apache.cxf.tools.common.model.JAnnotation 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 18 with JAnnotation

use of org.apache.cxf.tools.common.model.JAnnotation 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 19 with JAnnotation

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

the class WebParamAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    final JavaParameter parameter;
    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 20 with JAnnotation

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

the class WebServiceAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    final JavaInterface intf;
    if (ja instanceof JavaInterface) {
        intf = (JavaInterface) ja;
    } else {
        throw new RuntimeException("WebService can only annotate JavaInterface");
    }
    JAnnotation serviceAnnotation = new JAnnotation(WebService.class);
    serviceAnnotation.addElement(new JAnnotationElement("targetNamespace", intf.getNamespace()));
    serviceAnnotation.addElement(new JAnnotationElement("name", intf.getWebServiceName()));
    intf.addAnnotation(serviceAnnotation);
}
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)

Aggregations

JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)27 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)20 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)14 Test (org.junit.Test)7 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)3 Message (org.apache.cxf.common.i18n.Message)3 JavaField (org.apache.cxf.tools.common.model.JavaField)3 XmlList (javax.xml.bind.annotation.XmlList)2 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)2 WrapperBeanClass (org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)2 WebMethodAnnotator (org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)2 Annotation (java.lang.annotation.Annotation)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1