DeserializationContext context)
throws SAXException
{
BeanPropertyDescriptor propDesc = null;
QName elemQName = new QName(namespace, localName);
// The collectionIndex needs to be reset for Beans with multiple arrays
if ((prevQName == null) || (!prevQName.equals(elemQName))) {
prevQName = elemQName;
collectionIndex = -1;
}
prevQName = elemQName;
if (typeDesc != null) {
// First lookup the field using the target namespace context
// and local name. If this fails and the incoming element
// name is not prefixed, lookup the name assuming an unqualified
// name.
String fieldName = typeDesc.getFieldNameForElement(elemQName,
false);
if (fieldName == null && (prefix == null || prefix.equals(""))) {
fieldName =
typeDesc.getFieldNameForElement(
new QName("", elemQName.getLocalPart()), false);
}
propDesc = (BeanPropertyDescriptor)propertyMap.get(fieldName);
}
if (propDesc == null) {
// look for a field by this name.
propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
}
// Currently the meta data does not consider inheritance.
// Glen is working on a fix. In the meantime, the following
// code attempts to get the meta data from the base class.
// (this fix does not work in all cases, but is necessary to
// get comprehensive tests Animal - Cat inheritance to work).
if (propDesc == null) {
Class superClass = javaType;
while (superClass != null && propDesc == null) {
superClass = superClass.getSuperclass();
if (superClass != null) {
TypeDesc td = TypeDesc.getTypeDescForClass(superClass);
if (td != null) {
String fieldName =
td.getFieldNameForElement(elemQName,
false);
if (fieldName == null &&
(prefix == null || prefix.equals(""))) {
fieldName =
td.getFieldNameForElement(
new QName("", elemQName.getLocalPart()), false);
}
propDesc =
(BeanPropertyDescriptor)propertyMap.get(fieldName);
}
}
}
}
if (propDesc == null) {
// No such field
throw new SAXException(
JavaUtils.getMessage("badElem00", javaType.getName(),
localName));
}
// Determine the QName for this child element.
// Look at the type attribute specified. If this fails,
// use the javaType of the property to get the type qname.
QName qn = context.getTypeFromAttributes(namespace, localName, attributes);
// get the deserializer
Deserializer dSer = context.getDeserializerForType(qn);
// If no deserializer, use the base DeserializerImpl.