if (!useXMLRoot) {
referenceDescriptor = getDescriptor(nestedRecord, session, null);
if ((referenceDescriptor != null) && (keepAsElementPolicy != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
objectValue = builder.buildObject(query, nestedRecord, joinManager);
if(getConverter() != null) {
objectValue = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller());
}
cp.addInto(objectValue, container, session);
} else {
if ((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element) next);
objectValue = next;
if(getConverter() != null) {
objectValue = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller());
}
cp.addInto(objectValue, container, session);
}
}
} else {
String schemaType = ((Element) next).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
QName schemaTypeQName = null;
XPathFragment frag = new XPathFragment();
if ((null != schemaType) && (!schemaType.equals(""))) {
frag.setXPath(schemaType);
if (frag.hasNamespace()) {
String prefix = frag.getPrefix();
XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
String url = xmlPlatform.resolveNamespacePrefix(next, prefix);
frag.setNamespaceURI(url);
schemaTypeQName = new QName(url, frag.getLocalName());
}
XMLContext xmlContext = nestedRecord.getUnmarshaller().getXMLContext();
referenceDescriptor = xmlContext.getDescriptorByGlobalType(frag);
}
if (referenceDescriptor == null) {
try {
QName qname = new QName(nestedRecord.getNamespaceURI(), nestedRecord.getLocalName());
referenceDescriptor = getDescriptor(nestedRecord, session, qname);
} catch (XMLMarshalException e) {
referenceDescriptor = null;
}
// Check if descriptor is for a wrapper, if it is null it out and let continue
XMLDescriptor xmlReferenceDescriptor = (XMLDescriptor) referenceDescriptor;
if (referenceDescriptor != null && xmlReferenceDescriptor.isWrapper()) {
referenceDescriptor = null;
}
}
if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
objectValue = builder.buildObject(query, nestedRecord, joinManager);
Object updated = ((XMLDescriptor) referenceDescriptor).wrapObjectInXMLRoot(objectValue, next.getNamespaceURI(), next.getLocalName(), next.getPrefix(), false);
if(getConverter() != null) {
updated = getConverter().convertDataValueToObjectValue(updated, session, record.getUnmarshaller());
}