Search in sources :

Example 6 with WrapperBeanClass

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass in project cxf by apache.

the class FaultBeanTest method testTransform.

@Test
public void testTransform() throws Exception {
    Class<?> faultClass = Class.forName("org.apache.cxf.tools.fortest.cxf523.DBServiceFault");
    FaultBean bean = new FaultBean();
    WrapperBeanClass beanClass = bean.transform(faultClass, "org.apache.cxf.tools.fortest.cxf523.jaxws");
    assertNotNull(beanClass);
    assertEquals("DBServiceFaultBean", beanClass.getName());
    assertEquals("org.apache.cxf.tools.fortest.cxf523.jaxws", beanClass.getPackageName());
    assertEquals(1, beanClass.getFields().size());
    JavaField field = beanClass.getFields().get(0);
    assertEquals("message", field.getName());
    assertEquals("java.lang.String", field.getType());
    QName qname = beanClass.getElementName();
    assertEquals("DBServiceFault", qname.getLocalPart());
    assertEquals("http://cxf523.fortest.tools.cxf.apache.org/", qname.getNamespaceURI());
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) QName(javax.xml.namespace.QName) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass) Test(org.junit.Test)

Example 7 with WrapperBeanClass

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass 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)

Example 8 with WrapperBeanClass

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass 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(URIParserUtil.getNamespace(pkg), exceptionClass.getSimpleName()));
    } else {
        jClass.setElementName(new QName(URIParserUtil.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 9 with WrapperBeanClass

use of org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass 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)9 QName (javax.xml.namespace.QName)3 JavaField (org.apache.cxf.tools.common.model.JavaField)3 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 WrapperBeanAnnotator (org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator)2 Test (org.junit.Test)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