use of javax.xml.bind.annotation.XmlElementWrapper in project cxf by apache.
the class ReflectionServiceFactoryBean method getJaxbAnnoMap.
private Map<Class<?>, Boolean> getJaxbAnnoMap(MessagePartInfo mpi) {
Map<Class<?>, Boolean> map = new ConcurrentHashMap<>(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;
}
use of javax.xml.bind.annotation.XmlElementWrapper in project zm-mailbox by Zimbra.
the class JaxbInfo method processFieldRelatedAnnotations.
private void processFieldRelatedAnnotations(Annotation[] annots, String fieldName, Type defaultGenericType) {
WrappedElementInfo wrappedInfo = null;
for (Annotation annot : annots) {
if (annot instanceof XmlElementWrapper) {
XmlElementWrapper wrapper = (XmlElementWrapper) annot;
wrappedInfo = new WrappedElementInfo(wrapper, fieldName);
jaxbElemNodeInfo.add(wrappedInfo);
break;
}
}
for (Annotation annot : annots) {
if (annot instanceof XmlValue) {
elementValue = new JaxbValueInfo((XmlValue) annot, fieldName, defaultGenericType);
} else if (annot instanceof XmlAttribute) {
XmlAttribute attr = (XmlAttribute) annot;
String attrName = attr.name();
if ((attrName == null) || DEFAULT_MARKER.equals(attrName)) {
attrName = fieldName;
}
this.setXmlAttributeInfo(attr, fieldName, defaultGenericType);
this.attributeNames.add(attrName);
} else if (annot instanceof XmlElement) {
XmlElement xmlElem = (XmlElement) annot;
if (wrappedInfo == null) {
setXmlElementInfo(xmlElem, fieldName, defaultGenericType);
} else {
wrappedInfo.add(xmlElem, fieldName, defaultGenericType);
}
} else if (annot instanceof XmlElementRef) {
XmlElementRef xmlElemR = (XmlElementRef) annot;
if (wrappedInfo == null) {
setXmlElementInfo(xmlElemR, null, null);
} else {
wrappedInfo.add(xmlElemR, null, null);
}
} else if (annot instanceof XmlElements) {
JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType);
if (wrappedInfo == null) {
jaxbElemNodeInfo.add(choiceNode);
} else {
wrappedInfo.add(choiceNode);
}
XmlElements xmlElemsAnnot = (XmlElements) annot;
for (XmlElement xmlE : xmlElemsAnnot.value()) {
choiceNode.add(xmlE);
}
} else if (annot instanceof XmlElementRefs) {
JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType);
if (wrappedInfo == null) {
jaxbElemNodeInfo.add(choiceNode);
} else {
wrappedInfo.add(choiceNode);
}
XmlElementRefs elemRefs = (XmlElementRefs) annot;
for (XmlElementRef xmlE : elemRefs.value()) {
choiceNode.add(xmlE);
}
}
}
}
use of javax.xml.bind.annotation.XmlElementWrapper in project swagger-core by swagger-api.
the class JAXBAnnotationsHelper method apply.
/**
* Applies annotations to property's {@link XML} definition.
*
* @param member annotations provider
* @param property property instance to be updated
*/
public static void apply(Annotated member, Annotation[] annotations, Schema property) {
XmlElementWrapper wrapper = member.getAnnotation(XmlElementWrapper.class);
if (wrapper == null) {
wrapper = AnnotationsUtils.getAnnotation(XmlElementWrapper.class, annotations);
}
XmlAttribute attr = member.getAnnotation(XmlAttribute.class);
if (attr == null) {
attr = AnnotationsUtils.getAnnotation(XmlAttribute.class, annotations);
}
XmlElement elem = member.getAnnotation(XmlElement.class);
if (elem == null) {
elem = AnnotationsUtils.getAnnotation(XmlElement.class, annotations);
}
if (wrapper != null) {
applyElement(wrapper, property);
} else if (elem != null) {
applyElement(elem, property);
} else if (attr != null && isAttributeAllowed(property)) {
applyAttribute(attr, property);
}
}
use of javax.xml.bind.annotation.XmlElementWrapper in project knox by apache.
the class ServiceModel method getSamples.
@XmlElement(name = "sample")
@XmlElementWrapper(name = "samples")
public List<Sample> getSamples() {
final List<Sample> samples = new ArrayList<>();
if (serviceMetadata != null && serviceMetadata.getSamples() != null) {
serviceMetadata.getSamples().forEach(sample -> {
final Sample resolvedSample = new Sample();
resolvedSample.setDescription(sample.getDescription());
if (StringUtils.isNotBlank(sample.getValue())) {
resolvedSample.setValue(sample.getValue());
} else {
final String method = StringUtils.isBlank(sample.getMethod()) ? "GET" : sample.getMethod();
resolvedSample.setValue(String.format(Locale.ROOT, CURL_SAMPLE_TEMPLATE, method, getServiceUrl(), sample.getPath()));
}
samples.add(resolvedSample);
});
}
return samples;
}
use of javax.xml.bind.annotation.XmlElementWrapper in project groovity by disney.
the class ModelXmlWriter method visitObjectField.
@SuppressWarnings("rawtypes")
public void visitObjectField(String name, Object value) throws Exception {
if (inAttribute) {
writer.write(" ");
writer.write(name);
writer.write("=\"");
super.visitObjectField(name, value);
writer.write("\"");
return;
}
boolean writeTag = true;
Object currentObject = getCurrentObject();
MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(currentObject.getClass());
MetaProperty mp = mc.hasProperty(currentObject, name);
XmlAttribute xa = getAnnotation(mp, XmlAttribute.class);
if (xa != null) {
// attributes are written with open tag
return;
}
String listElementName = null;
// aggressively resolve closures and futures so we can determine type
if (value instanceof Closure) {
value = ((Closure) value).call();
} else if (value instanceof Future) {
value = ((Future) value).get();
}
if (value instanceof List || (value != null && value.getClass().isArray()) || (mp != null && (mp.getType().isArray() || List.class.isAssignableFrom(mp.getType())))) {
writeTag = false;
listElementName = name;
Map<Class<?>, String> listTypedNames = NO_NAMES;
XmlElementWrapper xew = getAnnotation(mp, XmlElementWrapper.class);
if (xew != null) {
writeTag = true;
if (!"##default".equals(xew.name())) {
name = xew.name();
}
name = getTagName(xew.namespace(), name);
}
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
listElementName = xe.name();
}
listElementName = getTagName(xe.namespace(), listElementName);
}
if (xe == null) {
XmlElements xes = getAnnotation(mp, XmlElements.class);
if (xes != null) {
listTypedNames = new HashMap<>();
for (int i = 0; i < xes.value().length; i++) {
XmlElement e = xes.value()[i];
listTypedNames.put(e.type(), e.name());
}
}
}
XmlList xel = getAnnotation(mp, XmlList.class);
if (xel != null) {
writeTag = true;
name = listElementName;
value = transformField(mp, value);
}
XmlMixed xm = getAnnotation(mp, XmlMixed.class);
if (xm != null) {
listTypedNames = SKIP_TAG;
}
listElementNames.push(Optional.of(listElementName));
listTypedElementNames.push(Optional.ofNullable(listTypedNames));
} else {
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
name = xe.name();
}
name = getTagName(xe.namespace(), name);
}
listElementNames.push(Optional.empty());
listTypedElementNames.push(Optional.empty());
}
doDelimit = true;
if (writeTag) {
final String n = name;
writeTag(name, value, o -> {
try {
super.visitObjectField(n, o);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} else {
super.visitObjectField(name, value);
}
listElementNames.pop();
listTypedElementNames.pop();
}
Aggregations