Search in sources :

Example 21 with JAnnotation

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

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

the class WebMethodAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    final JavaMethod method;
    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 23 with JAnnotation

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

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

Example 25 with JAnnotation

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

the class OperationProcessor method addPollingMethod.

private void addPollingMethod(JavaMethod method) throws ToolException {
    JavaMethod pollingMethod = new JavaMethod(method.getInterface());
    pollingMethod.setAsync(true);
    pollingMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
    pollingMethod.setStyle(method.getStyle());
    pollingMethod.setWrapperStyle(method.isWrapperStyle());
    pollingMethod.setSoapAction(method.getSoapAction());
    pollingMethod.setOperationName(method.getOperationName());
    boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
    String asyncCname = null;
    for (JavaParameter param : method.getParameters()) {
        if (convertOutToAsync) {
            if (param.isHolder()) {
                if (param.isINOUT()) {
                    JavaParameter p2 = new JavaParameter();
                    p2.setName(param.getName());
                    p2.setClassName(param.getHolderName());
                    p2.setStyle(JavaType.Style.IN);
                    pollingMethod.addParameter(p2);
                    for (String s : param.getAnnotationTags()) {
                        JAnnotation ann = param.getAnnotation(s);
                        p2.addAnnotation(s, ann);
                    }
                } else if (!param.isHeader() && asyncCname == null) {
                    asyncCname = param.getClassName();
                }
            } else {
                pollingMethod.addParameter(param);
            }
        } else {
            pollingMethod.addParameter(param);
        }
    }
    JavaReturn response = new JavaReturn();
    response.setClassName(getAsyncClassName(method, "Response", asyncCname));
    pollingMethod.setReturn(response);
    // REVISIT: test the operation name in the annotation
    pollingMethod.annotate(new WebMethodAnnotator());
    pollingMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
    pollingMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
    pollingMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
    method.getInterface().addMethod(pollingMethod);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) WebMethodAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)

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