Search in sources :

Example 16 with JAnnotationElement

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

the class WebServiceAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaInterface intf = null;
    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)

Example 17 with JAnnotationElement

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

the class WrapperAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("RequestWrapper and ResponseWrapper can only annotate JavaMethod");
    }
    if (wrapperRequest != null) {
        JAnnotation requestAnnotation = new JAnnotation(RequestWrapper.class);
        requestAnnotation.addElement(new JAnnotationElement("localName", wrapperRequest.getType()));
        requestAnnotation.addElement(new JAnnotationElement("targetNamespace", wrapperRequest.getTargetNamespace()));
        requestAnnotation.addElement(new JAnnotationElement("className", wrapperRequest.getClassName()));
        method.addAnnotation("RequestWrapper", requestAnnotation);
        method.getInterface().addImports(requestAnnotation.getImports());
    }
    if (wrapperResponse != null) {
        List<JAnnotationElement> elements = new ArrayList<>();
        elements.add(new JAnnotationElement("localName", wrapperResponse.getType()));
        elements.add(new JAnnotationElement("targetNamespace", wrapperResponse.getTargetNamespace()));
        elements.add(new JAnnotationElement("className", wrapperResponse.getClassName()));
        JAnnotation responseAnnotation = new JAnnotation(ResponseWrapper.class);
        responseAnnotation.getElements().addAll(elements);
        method.addAnnotation("ResponseWrapper", responseAnnotation);
        method.getInterface().addImports(responseAnnotation.getImports());
    }
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 18 with JAnnotationElement

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

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

the class WebParamAnnotatorTest method testAnnotateDOCWrapped.

@Test
public void testAnnotateDOCWrapped() throws Exception {
    init(method, parameter, SOAPBinding.Style.DOCUMENT, true);
    parameter.annotate(new WebParamAnnotator());
    JAnnotation annotation = parameter.getAnnotation("WebParam");
    assertEquals("@WebParam(name = \"x\", targetNamespace = \"http://apache.org/cxf\")", annotation.toString());
    List<JAnnotationElement> elements = annotation.getElements();
    assertEquals(2, elements.size());
    assertEquals("http://apache.org/cxf", elements.get(1).getValue());
    assertEquals("x", elements.get(0).getValue());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) Test(org.junit.Test)

Example 20 with JAnnotationElement

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

the class WrapperBeanAnnotator method annotate.

public void annotate(final JavaAnnotatable clz) {
    WrapperBeanClass beanClass = null;
    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)

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