use of javax.xml.bind.annotation.XmlElementWrapper in project cxf by apache.
the class WrapperClassGenerator method addJAXBAnnotations.
private boolean addJAXBAnnotations(ASMHelper.FieldVisitor fv, List<Annotation> jaxbAnnos, String name) {
ASMHelper.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.XmlElementWrapper in project groovity by disney.
the class ModelXmlWriter method writeTag.
protected void writeTag(String name, Object value, Consumer<Object> body) throws Exception {
int s = name.lastIndexOf("/");
int h = name.lastIndexOf("#");
if (s != -1 || h != -1) {
int l = s > h ? s : h;
name = getTagName(name.substring(0, l + 1), name.substring(l + 1));
}
delimit();
writer.write('<');
writer.write(name);
List<String> removeNamespaces = null;
Object xmlValue = null;
boolean foundXmlValue = false;
if (value != null) {
MetaProperty[] props = MetaPropertyLookup.getOrderedGettableProperties(value);
AtomicInteger pos = new AtomicInteger(0);
positions.push(pos);
for (int i = 0; i < props.length; i++) {
MetaProperty mp = props[i];
XmlAttribute xa = getAnnotation(mp, XmlAttribute.class);
if (xa != null) {
String attName = xa.name();
Object attValue = transformField(mp, mp.getProperty(value));
if ("##default".equals(attName)) {
attName = mp.getName();
}
attName = getTagName(xa.namespace(), attName);
inAttribute = true;
handleField(attName, attValue);
inAttribute = false;
}
XmlValue xv = getAnnotation(mp, XmlValue.class);
if (xv != null) {
if (foundXmlValue) {
log.warning("Found more than one @XmlValue on " + value.getClass().getName());
} else {
foundXmlValue = true;
xmlValue = transformField(mp, mp.getProperty(value));
}
}
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null && !"##default".equals(xe.namespace())) {
getNamespacePrefix(xe.namespace());
}
XmlElementWrapper xew = getAnnotation(mp, XmlElementWrapper.class);
if (xew != null && !"##default".equals(xew.namespace())) {
getNamespacePrefix(xew.namespace());
}
}
positions.pop();
}
if (declareNamespaces != null && !declareNamespaces.isEmpty()) {
removeNamespaces = new ArrayList<>();
for (Iterator<Entry<String, String>> iter = declareNamespaces.entrySet().iterator(); iter.hasNext(); ) {
Entry<String, String> ns = iter.next();
writer.write(" xmlns:");
writer.write(ns.getValue());
writer.write("=\"");
escape.write(ns.getKey());
writer.write("\"");
iter.remove();
removeNamespaces.add(ns.getKey());
}
}
writer.write('>');
if (foundXmlValue) {
value = xmlValue;
}
if (indent >= 0) {
indent++;
}
body.accept(value);
if (indent >= 0) {
indent--;
}
delimit();
writer.write("</");
writer.write(name);
writer.write('>');
doDelimit = true;
if (removeNamespaces != null) {
for (int i = 0; i < removeNamespaces.size(); i++) {
namespacePrefixes.remove(removeNamespaces.get(i));
}
}
}
use of javax.xml.bind.annotation.XmlElementWrapper in project swagger-core by swagger-api.
the class JAXBAnnotationsHelper method applyElement.
/**
* Puts definitions for XML element.
*
* @param member annotations provider
* @param property property instance to be updated
*/
private static void applyElement(AnnotatedMember member, Property property) {
final XmlElementWrapper wrapper = member.getAnnotation(XmlElementWrapper.class);
if (wrapper != null) {
final Xml xml = getXml(property);
xml.setWrapped(true);
// No need to set the xml name if the name provided by xmlelementwrapper annotation is ##default or equal to the property name | https://github.com/swagger-api/swagger-core/pull/2050
if (!"##default".equals(wrapper.name()) && !wrapper.name().isEmpty() && !wrapper.name().equals(property.getName())) {
xml.setName(wrapper.name());
}
} else {
final XmlElement element = member.getAnnotation(XmlElement.class);
if (element != null) {
setName(element.namespace(), element.name(), property);
}
}
}
use of javax.xml.bind.annotation.XmlElementWrapper 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.XmlElementWrapper in project ibas-framework by color-coding.
the class Serializer method getSerializedElements.
private List<SchemaElement> getSerializedElements(Field[] fields) {
List<SchemaElement> elements = new ArrayList<>();
for (Field field : fields) {
Class<?> elementType = field.getType();
String elementName = field.getName();
String wrapperName = null;
XmlElementWrapper xmlWrapper = field.getAnnotation(XmlElementWrapper.class);
if (xmlWrapper != null) {
// 首先判断是否为数组元素
wrapperName = xmlWrapper.name();
}
XmlElement xmlElement = field.getAnnotation(XmlElement.class);
if (xmlElement != null) {
if (!xmlElement.name().equals("##default")) {
elementName = xmlElement.name();
}
if (xmlElement.type() != null && !xmlElement.type().getName().startsWith(XmlElement.class.getName())) {
elementType = xmlElement.type();
}
} else {
continue;
}
if (elementName == null) {
continue;
}
if (elementType == null) {
continue;
}
elements.add(new SchemaElement(elementName, wrapperName, elementType));
}
return elements;
}
Aggregations