use of javax.xml.bind.annotation.XmlList in project cxf by apache.
the class CodeGenTest method testGenerateXmlListAnno.
@Test
public void testGenerateXmlListAnno() throws Exception {
env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/cxf-1354/string_array_test.wsdl"));
processor.setContext(env);
processor.execute();
Class<?> sei = classLoader.loadClass("org.apache.stringarray.StringListTest");
Method method = sei.getMethods()[0];
assertNotNull("@XmlList is not generated for method", method.getAnnotation(XmlList.class));
boolean xmlListGenerated = false;
for (Annotation ann : method.getParameterAnnotations()[0]) {
if (ann instanceof XmlList) {
xmlListGenerated = true;
}
}
assertTrue("@XmlList is not generated for paramter", xmlListGenerated);
}
use of javax.xml.bind.annotation.XmlList in project cxf by apache.
the class WrapperBeanFieldAnnotator method annotate.
public void annotate(final JavaAnnotatable field) {
JavaField jField = null;
if (field instanceof JavaField) {
jField = (JavaField) field;
} else {
throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
}
String rawName = jField.getRawName();
boolean hasEl = false;
for (Annotation ann : jField.getJaxbAnnotaions()) {
if (ann instanceof XmlMimeType) {
JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
jField.addAnnotation(mimeAnno);
} else if (ann instanceof XmlJavaTypeAdapter) {
JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlAttachmentRef) {
JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlList) {
JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
jField.addAnnotation(jaxbAnn);
} else if (ann instanceof XmlElement) {
hasEl = true;
XmlElement el = (XmlElement) ann;
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
if (!StringUtils.isEmpty(el.namespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
}
if (el.nillable()) {
xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
}
if (el.required()) {
xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
}
if (!StringUtils.isEmpty(el.defaultValue())) {
xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
if (!hasEl) {
JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
}
jField.addAnnotation(xmlElementAnnotation);
}
}
use of javax.xml.bind.annotation.XmlList 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());
}
use of javax.xml.bind.annotation.XmlList in project cxf by apache.
the class WrapperClassGenerator method addJAXBAnnotations.
private boolean addJAXBAnnotations(FieldVisitor fv, List<Annotation> jaxbAnnos, String name) {
AnnotationVisitor av0;
boolean addedEl = false;
for (Annotation ann : jaxbAnnos) {
if (ann instanceof XmlMimeType) {
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlMimeType;", true);
av0.visit("value", ((XmlMimeType) ann).value());
av0.visitEnd();
} else if (ann instanceof XmlJavaTypeAdapter) {
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
generateXmlJavaTypeAdapter(av0, (XmlJavaTypeAdapter) ann);
av0.visitEnd();
} else if (ann instanceof XmlAttachmentRef) {
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlAttachmentRef;", true);
av0.visitEnd();
} else if (ann instanceof XmlList) {
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlList;", true);
av0.visitEnd();
} else if (ann instanceof XmlElement) {
addedEl = true;
XmlElement el = (XmlElement) ann;
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
if ("##default".equals(el.name())) {
av0.visit("name", name);
} else {
av0.visit("name", el.name());
}
av0.visit("nillable", el.nillable());
av0.visit("required", el.required());
av0.visit("namespace", el.namespace());
av0.visit("defaultValue", el.defaultValue());
if (el.type() != XmlElement.DEFAULT.class) {
av0.visit("type", el.type());
}
av0.visitEnd();
} else if (ann instanceof XmlElementWrapper) {
XmlElementWrapper el = (XmlElementWrapper) ann;
av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElementWrapper;", true);
av0.visit("name", el.name());
av0.visit("nillable", el.nillable());
av0.visit("required", el.required());
av0.visit("namespace", el.namespace());
av0.visitEnd();
}
}
return addedEl;
}
use of javax.xml.bind.annotation.XmlList in project cxf by apache.
the class ReflectionServiceFactoryBean method getJaxbAnnoMap.
private Map<Class<?>, Boolean> getJaxbAnnoMap(MessagePartInfo mpi) {
Map<Class<?>, Boolean> map = new ConcurrentHashMap<Class<?>, Boolean>(4, 0.75f, 1);
Annotation[] anns = getMethodParameterAnnotations(mpi);
if (anns != null) {
for (Annotation anno : anns) {
if (anno instanceof XmlList) {
map.put(XmlList.class, true);
}
if (anno instanceof XmlAttachmentRef) {
map.put(XmlAttachmentRef.class, true);
}
if (anno instanceof XmlJavaTypeAdapter) {
map.put(XmlJavaTypeAdapter.class, true);
}
if (anno instanceof XmlElementWrapper) {
map.put(XmlElementWrapper.class, true);
}
}
}
return map;
}
Aggregations