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 {
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 candlepin by candlepin.
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);
if (!"##default".equals(wrapper.name()) && !wrapper.name().isEmpty()) {
xml.setName(wrapper.name());
}
}
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 ibas-framework by color-coding.
the class Serializer method getSerializedElements.
private List<SchemaElement> getSerializedElements(Method[] methods) {
List<SchemaElement> elements = new ArrayList<>();
for (Method method : methods) {
Class<?> elementType = method.getReturnType();
if (elementType == null && method.getParameterTypes().length == 1) {
// 没有返回类型时,取一个参数的设置类型
elementType = method.getParameterTypes()[0];
}
String elementName = null;
String wrapperName = null;
XmlElementWrapper xmlWrapper = method.getAnnotation(XmlElementWrapper.class);
if (xmlWrapper != null) {
// 首先判断是否为数组元素
wrapperName = xmlWrapper.name();
}
XmlElement xmlElement = method.getAnnotation(XmlElement.class);
if (xmlElement != null) {
if (elementName == null) {
elementName = xmlElement.name();
}
if (xmlElement.type() != null && !xmlElement.type().getName().startsWith(XmlElement.class.getName())) {
elementType = xmlElement.type();
}
}
if (elementName == null) {
continue;
}
if (elementType == null) {
continue;
}
elements.add(new SchemaElement(elementName, wrapperName, elementType));
}
return elements;
}
use of javax.xml.bind.annotation.XmlElementWrapper in project killbill by killbill.
the class CatalogSafetyInitializer method initializeNonRequiredFields.
// For each type of catalog object we keep the 'Field' associated to non required attribute fields
private static LinkedList<Field> initializeNonRequiredFields(final Class<?> aClass) {
final LinkedList<Field> result = new LinkedList();
final Field[] fields = aClass.getDeclaredFields();
for (final Field f : fields) {
if (f.getType().isArray()) {
final XmlElementWrapper xmlElementWrapper = f.getAnnotation(XmlElementWrapper.class);
if (xmlElementWrapper != null) {
if (!xmlElementWrapper.required()) {
result.add(f);
}
} else {
final XmlElement xmlElement = f.getAnnotation(XmlElement.class);
if (xmlElement != null && !xmlElement.required()) {
result.add(f);
}
}
} else if (!f.getType().isPrimitive()) {
if (f.getType().isEnum()) {
if (FixedType.class.equals(f.getType())) {
result.add(f);
} else if (BlockType.class.equals(f.getType())) {
result.add(f);
} else if (TierBlockPolicy.class.equals(f.getType())) {
result.add(f);
}
} else if (Integer.class.equals(f.getType())) {
result.add(f);
} else if (Double.class.equals(f.getType())) {
result.add(f);
}
}
}
return result;
}
use of javax.xml.bind.annotation.XmlElementWrapper in project zm-mailbox by Zimbra.
the class NameInfo method setWrapperInfo.
private void setWrapperInfo(AnnotationIntrospector ai, AnnotatedMember prop) {
XmlElementWrapper wrapper = prop.getAnnotation(XmlElementWrapper.class);
if (wrapper == null) {
return;
}
wrapperName = new QName(wrapper.namespace(), wrapper.name());
}
Aggregations