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());
}
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);
}
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;
}
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;
}
Aggregations