use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class JAXBUtils method getAdapter.
public static XmlJavaTypeAdapter getAdapter(Class<?> objectClass, Annotation[] anns) {
XmlJavaTypeAdapter typeAdapter = AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class);
if (typeAdapter == null) {
typeAdapter = objectClass.getAnnotation(XmlJavaTypeAdapter.class);
if (typeAdapter == null) {
// lets just try the 1st interface for now
Class<?>[] interfaces = objectClass.getInterfaces();
typeAdapter = interfaces.length > 0 ? interfaces[0].getAnnotation(XmlJavaTypeAdapter.class) : null;
}
}
return typeAdapter;
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class JAXBUtils method getTypeFromAdapter.
public static Class<?> getTypeFromAdapter(XmlJavaTypeAdapter adapter, Class<?> theType, boolean boundType) {
if (adapter != null) {
if (adapter.type() != XmlJavaTypeAdapter.DEFAULT.class) {
theType = adapter.type();
} else {
Type topAdapterType = adapter.value().getGenericSuperclass();
Class<?> superClass = adapter.value().getSuperclass();
while (superClass != null) {
Class<?> nextSuperClass = superClass.getSuperclass();
if (nextSuperClass != null && !Object.class.equals(nextSuperClass)) {
topAdapterType = superClass.getGenericSuperclass();
}
superClass = nextSuperClass;
}
Type[] types = InjectionUtils.getActualTypes(topAdapterType);
if (types != null && types.length == 2) {
int index = boundType ? 1 : 0;
theType = InjectionUtils.getActualType(types[index]);
}
}
}
return theType;
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter 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.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class XmlJavaTypeAdapterAnnotator method annotate.
public void annotate(JavaAnnotatable jn) {
JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
if (jn instanceof JavaParameter) {
JavaParameter jp = (JavaParameter) jn;
jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else if (jn instanceof JavaMethod) {
JavaMethod jm = (JavaMethod) jn;
jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
} else {
throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
}
jf.addImport(XmlJavaTypeAdapter.class.getName());
jf.addImport(adapter.getName());
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter 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;
}
Aggregations