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