use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class JAXBContextInitializer method walkReferences.
private void walkReferences(Class<?> cls) {
if (cls == null) {
return;
}
if (cls.getName().startsWith("java.") || cls.getName().startsWith("javax.")) {
return;
}
// walk the public fields/methods to try and find all the classes. JAXB will only load the
// EXACT classes in the fields/methods if they are in a different package. Thus,
// subclasses won't be found and the xsi:type stuff won't work at all.
// We'll grab the public field/method types and then add the ObjectFactory stuff
// as well as look for jaxb.index files in those packages.
XmlAccessType accessType = Utils.getXmlAccessType(cls);
if (accessType != XmlAccessType.PROPERTY) {
// only look for fields if we are instructed to
// fields are accessible even if not public, must look at the declared fields
// then walk to parents declared fields, etc...
Field[] fields = ReflectionUtil.getDeclaredFields(cls);
for (Field f : fields) {
if (isFieldAccepted(f, accessType)) {
XmlJavaTypeAdapter xjta = Utils.getFieldXJTA(f);
if (xjta != null) {
Type t = Utils.getTypeFromXmlAdapter(xjta);
if (t != null) {
addType(t);
continue;
}
}
addType(f.getGenericType());
}
}
walkReferences(cls.getSuperclass());
}
if (accessType != XmlAccessType.FIELD) {
// only look for methods if we are instructed to
Method[] methods = ReflectionUtil.getDeclaredMethods(cls);
for (Method m : methods) {
if (isMethodAccepted(m, accessType)) {
XmlJavaTypeAdapter xjta = Utils.getMethodXJTA(m);
if (xjta != null) {
Type t = Utils.getTypeFromXmlAdapter(xjta);
if (t != null) {
addType(t);
continue;
}
}
addType(m.getGenericReturnType());
for (Type t : m.getGenericParameterTypes()) {
addType(t);
}
}
}
}
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class Utils method setMethodValue.
@SuppressWarnings({ "rawtypes", "unchecked" })
static void setMethodValue(Method getter, Method setter, Object target, Object value) throws Exception {
XmlJavaTypeAdapter xjta = getMethodXJTA(getter);
XmlAdapter adapter = getXmlAdapter(xjta);
setter.invoke(target, adapter != null ? adapter.unmarshal(value) : value);
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class Utils method getMethodValue.
@SuppressWarnings({ "rawtypes", "unchecked" })
static Object getMethodValue(Method m, Object target) throws Exception {
XmlJavaTypeAdapter adapterAnnotation = getMethodXJTA(m);
XmlAdapter adapter = getXmlAdapter(adapterAnnotation);
return adapter != null ? adapter.marshal(m.invoke(target)) : m.invoke(target);
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class Utils method getFieldType.
static Class<?> getFieldType(Field f) {
XmlJavaTypeAdapter adapter = getFieldXJTA(f);
if (adapter == null && f.getGenericType() instanceof ParameterizedType && ((ParameterizedType) f.getGenericType()).getActualTypeArguments().length == 1) {
return null;
}
Class<?> adapterType = (Class<?>) getTypeFromXmlAdapter(adapter);
return adapterType != null ? adapterType : f.getType();
}
use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter in project cxf by apache.
the class Utils method setFieldValue.
@SuppressWarnings({ "rawtypes", "unchecked" })
static void setFieldValue(Field f, Object target, Object value) throws Exception {
XmlJavaTypeAdapter xjta = getFieldXJTA(f);
XmlAdapter adapter = getXmlAdapter(xjta);
f.set(target, adapter != null ? adapter.unmarshal(value) : value);
}
Aggregations