use of javax.xml.bind.annotation.XmlElement in project zm-mailbox by Zimbra.
the class JaxbInfo method getKeyValuePairElementInfo.
/**
* If this object has keyvaluepairs for children, this returns information about them, otherwise returns null.
* Note implicit assumption that there can only be one set of keyvaluepairs - this is because the JSON
* representation would be unable to differentiate between them.
*/
public KeyValuePairXmlRepresentationInfo getKeyValuePairElementInfo() {
if (haveKvpXmlInfo) {
return kvpXmlInfo;
}
String elemName = null;
String attrName = null;
Field[] fields = jaxbClass.getDeclaredFields();
for (Field field : fields) {
ZimbraKeyValuePairs annot = field.getAnnotation(ZimbraKeyValuePairs.class);
if (annot == null) {
continue;
}
XmlElement xmlElemAnnot = field.getAnnotation(XmlElement.class);
if (xmlElemAnnot != null) {
elemName = xmlElemAnnot.name();
} else {
elemName = field.getName();
}
}
if (elemName != null) {
Method[] methods = jaxbClass.getDeclaredMethods();
for (Method method : methods) {
ZimbraKeyValuePairs annot = method.getAnnotation(ZimbraKeyValuePairs.class);
if (annot == null) {
continue;
}
XmlElement xmlElemAnnot = method.getAnnotation(XmlElement.class);
if (xmlElemAnnot != null) {
elemName = xmlElemAnnot.name();
} else {
elemName = method.getName();
}
}
}
if (elemName != null) {
Class<?> kvpElemClass = this.getClassForElement(elemName);
if (kvpElemClass != null) {
JaxbInfo kvpJaxbInfo = JaxbInfo.getFromCache(kvpElemClass);
if (kvpJaxbInfo != null) {
Iterable<String> attribNames = kvpJaxbInfo.getAttributeNames();
if (attribNames != null) {
for (String attribName : attribNames) {
// Should only be one...
attrName = attribName;
break;
}
}
}
}
}
if ((elemName != null) && (attrName != null)) {
kvpXmlInfo = new KeyValuePairXmlRepresentationInfo(elemName, attrName);
} else {
kvpXmlInfo = null;
}
haveKvpXmlInfo = true;
return kvpXmlInfo;
}
use of javax.xml.bind.annotation.XmlElement in project midpoint by Evolveum.
the class PrismBeanInspector method findPropertyGetterUncached.
private <T> Method findPropertyGetterUncached(Class<T> classType, String propName) {
if (propName.startsWith("_")) {
propName = propName.substring(1);
}
for (Method method : classType.getDeclaredMethods()) {
XmlElement xmlElement = method.getAnnotation(XmlElement.class);
if (xmlElement != null && xmlElement.name().equals(propName)) {
return method;
}
XmlAttribute xmlAttribute = method.getAnnotation(XmlAttribute.class);
if (xmlAttribute != null && xmlAttribute.name().equals(propName)) {
return method;
}
}
String getterName = "get" + StringUtils.capitalize(propName);
try {
return classType.getDeclaredMethod(getterName);
} catch (NoSuchMethodException e) {
// nothing found
}
getterName = "is" + StringUtils.capitalize(propName);
try {
return classType.getDeclaredMethod(getterName);
} catch (NoSuchMethodException e) {
// nothing found
}
Class<? super T> superclass = classType.getSuperclass();
if (superclass == null || superclass.equals(Object.class)) {
return null;
}
return findPropertyGetter(superclass, propName);
}
use of javax.xml.bind.annotation.XmlElement in project ddf by codice.
the class AdaptedSourceResponse method getMetacard.
@XmlElement(namespace = METACARD_URI)
public List<MetacardElement> getMetacard() {
List<MetacardElement> metacards = new ArrayList<MetacardElement>();
for (Result r : delegate.getResults()) {
Metacard metacard = r.getMetacard();
if (metacard == null) {
continue;
}
MetacardElement element = new MetacardElement();
element.setId(metacard.getId());
element.setSource(metacard.getSourceId());
if (metacard.getMetacardType() != null) {
String metacardTypeName = BasicTypes.BASIC_METACARD.getName();
if (isNotBlank(metacard.getMetacardType().getName())) {
metacardTypeName = metacard.getMetacardType().getName();
}
element.setType(metacardTypeName);
AttributeAdapter attributeAdapter = new AttributeAdapter(metacard.getMetacardType());
for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
try {
element.getAttributes().add(attributeAdapter.marshal(metacard.getAttribute(descriptor.getName())));
} catch (CatalogTransformerException e) {
LOGGER.info("Marshalling error with attribute", e);
}
}
}
metacards.add(element);
}
return metacards;
}
use of javax.xml.bind.annotation.XmlElement 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.XmlElement in project winery by eclipse.
the class FieldValidator method setDeclaredFields.
private void setDeclaredFields(Class base, Class parent) {
if (!this.declaredFields.containsKey(base)) {
this.declaredFields.put(base, new HashSet<>());
}
if (parent.equals(TArtifactDefinition.class)) {
this.declaredFields.get(base).add("file");
}
if (!parent.equals(Object.class)) {
this.declaredFields.get(base).addAll(Arrays.stream(parent.getDeclaredFields()).map(field -> {
XmlAttribute xmlAttribute = field.getAnnotation(XmlAttribute.class);
XmlElement xmlElement = field.getAnnotation(XmlElement.class);
if (Objects.nonNull(xmlAttribute) && !xmlAttribute.name().equals("##default")) {
return xmlAttribute.name();
} else if (Objects.nonNull(xmlElement) && !xmlElement.name().equals("##default")) {
return xmlElement.name();
} else {
return field.getName();
}
}).collect(Collectors.toList()));
setDeclaredFields(base, parent.getSuperclass());
}
}
Aggregations