reader.nextTag();
} catch (XMLStreamException e) {
// ignore
}
} else {
throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
}
try {
QName qn = part.getElementQName();
if (!qn.equals(reader.getName())) {
throw new Fault(new Message("ELEMENT_NAME_MISMATCH", LOG, qn, reader.getName()));
}
Class<?> cls = part.getTypeClass();
Object obj = null;
try {
Constructor<?> cons = cls.getConstructor();
obj = cons.newInstance();
} catch (NoSuchMethodException nse) {
Constructor<?> cons = cls.getConstructor(new Class[] {String.class});
obj = cons.newInstance(new Object[1]);
}
XmlAccessType accessType = Utils.getXmlAccessType(cls);
reader.nextTag();
while (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
QName q = reader.getName();
String fieldName = q.getLocalPart();
Field f = Utils.getField(cls, accessType, fieldName);
if (f != null) {
Type type = f.getGenericType();
ReflectionUtil.setAccessible(f);
if (JAXBSchemaInitializer.isArray(type)) {
Class<?> compType = JAXBSchemaInitializer.getArrayComponentType(type);
List<Object> ret = unmarshallArray(u, reader, q, compType, createList(type));
Object o = ret;
if (!isList(type)) {
if (compType.isPrimitive()) {
o = java.lang.reflect.Array.newInstance(compType, ret.size());
for (int x = 0; x < ret.size(); x++) {
Array.set(o, x, ret.get(x));
}
} else {
o = ret.toArray((Object[]) Array.newInstance(compType, ret.size()));
}
}
f.set(obj, o);
} else {
Object o = getElementValue(u.unmarshal(reader, Utils.getFieldType(f)));
Utils.setFieldValue(f, obj, o);
}
} else {
String s = Character.toUpperCase(q.getLocalPart().charAt(0))
+ q.getLocalPart().substring(1);
Method m = Utils.getMethod(cls, accessType, "get" + s);
if (m == null) {
m = Utils.getMethod(cls, accessType, "is" + s);
}
Type type = m.getGenericReturnType();
Object o = null;
if (JAXBSchemaInitializer.isArray(type)) {
Class<?> compType = JAXBSchemaInitializer
.getArrayComponentType(type);
List<Object> ret = unmarshallArray(u, reader,
q,
compType,
createList(type));
o = ret;
if (!isList(type)) {
if (compType.isPrimitive()) {
o = java.lang.reflect.Array.newInstance(compType, ret.size());
for (int x = 0; x < ret.size(); x++) {
Array.set(o, x, ret.get(x));
}
} else {
o = ret.toArray((Object[])Array.newInstance(compType, ret.size()));
}
}
} else {
o = getElementValue(u.unmarshal(reader, Utils.getMethodReturnType(m)));
}
Method m2 = Utils.getMethod(cls, accessType, "set" + s, m.getReturnType());
if (m2 != null) {
if (JAXBSchemaInitializer.isArray(type)) {
m2.invoke(obj, o);
} else {
Utils.setMethodValue(m, m2, obj, o);
}
} else {
Field fn = ReflectionUtil.getDeclaredField(cls, q.getLocalPart());
if (fn != null) {
ReflectionUtil.setAccessible(fn);
fn.set(obj, o);
}
}
}
if (reader.getEventType() == XMLStreamReader.END_ELEMENT && q.equals(reader.getName())) {
reader.next();
}
}
return (Exception)obj;
} catch (Exception e) {
throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
}
}