use of org.eclipse.persistence.internal.oxm.record.deferred.DescriptorNotFoundContentHandler in project eclipselink by eclipse-ee4j.
the class XMLRelationshipMappingNodeValue method processChild.
// Protected to public
public void processChild(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts, Descriptor xmlDescriptor, Mapping mapping) throws SAXException {
if (xmlDescriptor == null) {
// Use the DescriptorNotFoundContentHandler to "look ahead" and determine if this is a simple or complex element
// if it is complex the exception should be thrown
DescriptorNotFoundContentHandler handler = new DescriptorNotFoundContentHandler(unmarshalRecord, mapping);
String qnameString = xPathFragment.getLocalName();
if (xPathFragment.getPrefix() != null) {
qnameString = xPathFragment.getPrefix() + Constants.COLON + qnameString;
}
handler.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
XMLReader xmlReader = unmarshalRecord.getXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.setLexicalHandler(handler);
return;
}
if (xmlDescriptor.hasInheritance()) {
unmarshalRecord.setAttributes(atts);
CoreAbstractSession session = unmarshalRecord.getSession();
Class<?> classValue = ((ObjectBuilder) xmlDescriptor.getObjectBuilder()).classFromRow(unmarshalRecord, session);
if (classValue == null) {
// no xsi:type attribute - look for type indicator on the default root element
XPathQName leafElementType = unmarshalRecord.getLeafElementType();
// if we have a user-set type, try to get the class from the inheritance policy
if (leafElementType != null) {
Object indicator = xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
if (indicator != null) {
classValue = (Class) indicator;
}
}
// if xsi:type is overriden by JSON_TYPE_ATTRIBUTE_NAME unmarshall property
if (classValue == null && unmarshalRecord.getUnmarshaller().isApplicationJSON() && unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName() != null && atts.getValue(unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName()) != null) {
QName qname = new QName(xmlDescriptor.getSchemaReference().getSchemaContextAsQName().getNamespaceURI(), atts.getValue(unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName()));
classValue = (Class) xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(qname);
}
}
if (classValue != null) {
xmlDescriptor = (Descriptor) session.getDescriptor(classValue);
} else {
// on the mapping - make sure it is non-abstract
if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
// need to throw an exception here
throw DescriptorException.missingClassIndicatorField(unmarshalRecord, (org.eclipse.persistence.oxm.XMLDescriptor) xmlDescriptor.getInheritancePolicy().getDescriptor());
}
}
}
ObjectBuilder targetObjectBuilder = (ObjectBuilder) xmlDescriptor.getObjectBuilder();
CoreAttributeGroup group = unmarshalRecord.getUnmarshalAttributeGroup();
CoreAttributeGroup nestedGroup = null;
if (group == XMLRecord.DEFAULT_ATTRIBUTE_GROUP) {
nestedGroup = group;
}
if (nestedGroup == null) {
CoreAttributeItem item = group.getItem(getMapping().getAttributeName());
nestedGroup = item.getGroup(xmlDescriptor.getJavaClass());
if (nestedGroup == null) {
if (item.getGroup() == null) {
nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
} else {
nestedGroup = item.getGroup();
}
}
}
UnmarshalRecord childRecord = unmarshalRecord.getChildUnmarshalRecord(targetObjectBuilder);
childRecord.setAttributes(atts);
childRecord.startDocument();
childRecord.initializeRecord(null);
childRecord.setUnmarshalAttributeGroup(nestedGroup);
childRecord.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), xPathFragment.getShortName(), atts);
XMLReader xmlReader = unmarshalRecord.getXMLReader();
xmlReader.setContentHandler(childRecord);
xmlReader.setLexicalHandler(childRecord);
}
Aggregations