Search in sources :

Example 1 with WrapperBeanAnnotator

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator in project cxf by apache.

the class WrapperBeanAnnotatorTest method testAnnotate.

@Test
public void testAnnotate() {
    String pkgName = "org.apache.cxf.tools.fortest.withannotation.doc.jaxws";
    WrapperBeanClass clz = new WrapperBeanClass();
    clz.setFullClassName(pkgName + ".SayHi");
    clz.setElementName(new QName("http://doc.withannotation.fortest.tools.cxf.apache.org/", "sayHi"));
    clz.annotate(new WrapperBeanAnnotator());
    List<JAnnotation> annotations = clz.getAnnotations();
    String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
    JAnnotation rootElementAnnotation = annotations.get(0);
    assertEquals("@XmlRootElement(name = \"sayHi\", " + "namespace = \"" + expectedNamespace + "\")", rootElementAnnotation.toString());
    JAnnotation xmlTypeAnnotation = annotations.get(2);
    assertEquals("@XmlType(name = \"sayHi\", " + "namespace = \"" + expectedNamespace + "\")", xmlTypeAnnotation.toString());
    JAnnotation accessorTypeAnnotation = annotations.get(1);
    assertEquals("@XmlAccessorType(XmlAccessType.FIELD)", accessorTypeAnnotation.toString());
    WrapperBeanClass resWrapperClass = new WrapperBeanClass();
    resWrapperClass.setFullClassName(pkgName + ".SayHiResponse");
    resWrapperClass.setElementName(new QName(expectedNamespace, "sayHiResponse"));
    resWrapperClass.annotate(new WrapperBeanAnnotator());
    annotations = resWrapperClass.getAnnotations();
    rootElementAnnotation = annotations.get(0);
    assertEquals("@XmlRootElement(name = \"sayHiResponse\", " + "namespace = \"" + expectedNamespace + "\")", rootElementAnnotation.toString());
    accessorTypeAnnotation = annotations.get(1);
    assertEquals("@XmlAccessorType(XmlAccessType.FIELD)", accessorTypeAnnotation.toString());
    xmlTypeAnnotation = annotations.get(2);
    assertEquals("@XmlType(name = \"sayHiResponse\", " + "namespace = \"" + expectedNamespace + "\")", xmlTypeAnnotation.toString());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) QName(javax.xml.namespace.QName) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass) Test(org.junit.Test)

Example 2 with WrapperBeanAnnotator

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator 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 3 with WrapperBeanAnnotator

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator in project cxf by apache.

the class FaultBean method transform.

public WrapperBeanClass transform(final Class<?> exceptionClass, final String defaultPackage) {
    WrapperBeanClass jClass = new WrapperBeanClass();
    if (isWebFaultAbsent(exceptionClass)) {
        jClass.setName(exceptionClass.getSimpleName() + "Bean");
        jClass.setPackageName(defaultPackage);
    } else {
        jClass.setFullClassName(getWebFaultBean(exceptionClass));
    }
    buildBeanFields(exceptionClass, jClass);
    String pkg = PackageUtils.getPackageName(exceptionClass);
    if (pkg.length() > 0) {
        jClass.setElementName(new QName(PackageUtils.getNamespace(pkg), exceptionClass.getSimpleName()));
    } else {
        jClass.setElementName(new QName(PackageUtils.getNamespace(ToolConstants.DEFAULT_PACKAGE_NAME), exceptionClass.getSimpleName()));
    }
    jClass.annotate(new WrapperBeanAnnotator(exceptionClass));
    return jClass;
}
Also used : WrapperBeanAnnotator(org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator) QName(javax.xml.namespace.QName) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)

Example 4 with WrapperBeanAnnotator

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator in project cxf by apache.

the class Wrapper method buildWrapperBeanClass.

public WrapperBeanClass buildWrapperBeanClass() {
    WrapperBeanClass jClass = getJavaClass();
    List<JavaField> fields = buildFields();
    for (JavaField field : fields) {
        field.setOwner(jClass);
        field.annotate(new WrapperBeanFieldAnnotator());
        jClass.addField(field);
        jClass.appendGetter(field);
        jClass.appendSetter(field);
    }
    jClass.annotate(new WrapperBeanAnnotator());
    return jClass;
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) WrapperBeanAnnotator(org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator) WrapperBeanFieldAnnotator(org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanFieldAnnotator) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)

Aggregations

WrapperBeanClass (org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)4 QName (javax.xml.namespace.QName)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 WrapperBeanAnnotator (org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator)2 ArrayList (java.util.ArrayList)1 XmlType (javax.xml.bind.annotation.XmlType)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 WrapperBeanFieldAnnotator (org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanFieldAnnotator)1 Test (org.junit.Test)1