if (!useXMLRoot) {
referenceDescriptor = getDescriptor(nestedRecord, session, null);
if (referenceDescriptor != null) {
ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
Object objectValue = builder.buildObject(query, nestedRecord, joinManager);
if(getConverter() != null) {
objectValue = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller());
}
return objectValue;
}
} 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;
}
}
if (referenceDescriptor != null) {
ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
Object 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(objectValue, session, record.getUnmarshaller());
}
return updated;