use of org.eclipse.persistence.internal.oxm.record.UnmarshalRecord in project eclipselink by eclipse-ee4j.
the class XMLVariableXPathMappingNodeValue method endElement.
@Override
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
UnmarshalRecord childRecord = unmarshalRecord.getChildRecord();
if (childRecord != null) {
Object childObject = childRecord.getCurrentObject();
String localName = xPathFragment.getLocalName();
setXPathInObject(xPathFragment.getNamespaceURI(), localName, childObject);
childObject = getMapping().convertDataValueToObjectValue(childObject, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
setOrAddAttributeValue(unmarshalRecord, childObject, xPathFragment, null);
unmarshalRecord.setChildRecord(null);
} else {
unmarshalRecord.resetStringBuffer();
}
}
use of org.eclipse.persistence.internal.oxm.record.UnmarshalRecord 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);
}
use of org.eclipse.persistence.internal.oxm.record.UnmarshalRecord in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMappingNodeValue method buildSelfRecord.
@Override
public UnmarshalRecord buildSelfRecord(UnmarshalRecord unmarshalRecord, Attributes atts) {
try {
Descriptor xmlDescriptor = (Descriptor) xmlCompositeObjectMapping.getReferenceDescriptor();
if (null == xmlDescriptor) {
xmlDescriptor = findReferenceDescriptor(null, unmarshalRecord, atts, xmlCompositeObjectMapping, xmlCompositeObjectMapping.getKeepAsElementPolicy());
}
if (xmlDescriptor != null) {
if (xmlDescriptor.hasInheritance()) {
unmarshalRecord.setAttributes(atts);
Class<?> clazz = ((ObjectBuilder) xmlDescriptor.getObjectBuilder()).classFromRow(unmarshalRecord, unmarshalRecord.getSession());
if (clazz == 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) {
clazz = (Class) indicator;
}
}
}
if (clazz != null) {
xmlDescriptor = (Descriptor) unmarshalRecord.getSession().getDescriptor(clazz);
} 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());
}
}
}
UnmarshalRecord childRecord = unmarshalRecord.getChildUnmarshalRecord((ObjectBuilder) xmlDescriptor.getObjectBuilder());
childRecord.setSelfRecord(true);
unmarshalRecord.setChildRecord(childRecord);
childRecord.startDocument();
childRecord.initializeRecord(this.xmlCompositeObjectMapping);
return childRecord;
} else {
return null;
}
} catch (SAXException e) {
throw XMLMarshalException.unmarshalException(e);
}
}
use of org.eclipse.persistence.internal.oxm.record.UnmarshalRecord in project eclipselink by eclipse-ee4j.
the class XMLAnyCollectionMappingNodeValue method endElement.
@Override
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Object collection) {
UnmarshalRecord childRecord = unmarshalRecord.getChildRecord();
if (null != childRecord) {
// OBJECT VALUE
if (!xmlAnyCollectionMapping.usesXMLRoot()) {
Object objectValue = childRecord.getCurrentObject();
objectValue = xmlAnyCollectionMapping.convertDataValueToObjectValue(objectValue, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
unmarshalRecord.addAttributeValue(this, objectValue);
} else {
Object childObject = childRecord.getCurrentObject();
Descriptor workingDescriptor = childRecord.getDescriptor();
if (workingDescriptor != null) {
String prefix = xPathFragment.getPrefix();
if ((prefix == null) && (xPathFragment.getNamespaceURI() != null)) {
prefix = unmarshalRecord.resolveNamespaceUri(xPathFragment.getNamespaceURI());
}
childObject = workingDescriptor.wrapObjectInXMLRoot(childObject, xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), prefix, false, unmarshalRecord.isNamespaceAware(), unmarshalRecord.getUnmarshaller());
childObject = xmlAnyCollectionMapping.convertDataValueToObjectValue(childObject, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
unmarshalRecord.addAttributeValue(this, childObject);
}
}
unmarshalRecord.setChildRecord(null);
} else {
SAXFragmentBuilder builder = unmarshalRecord.getFragmentBuilder();
if (xmlAnyCollectionMapping.isMixedContent() && unmarshalRecord.getTextWrapperFragment() != null && unmarshalRecord.getTextWrapperFragment().equals(xPathFragment)) {
endElementProcessText(unmarshalRecord, xmlAnyCollectionMapping, xPathFragment, null);
return;
}
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlAnyCollectionMapping.getKeepAsElementPolicy();
if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && builder.getNodes().size() > 1) {
setOrAddAttributeValueForKeepAsElement(builder, xmlAnyCollectionMapping, xmlAnyCollectionMapping, unmarshalRecord, true, collection);
} else {
// TEXT VALUE
if (xmlAnyCollectionMapping.isMixedContent()) {
endElementProcessText(unmarshalRecord, xmlAnyCollectionMapping, xPathFragment, null);
} else {
unmarshalRecord.resetStringBuffer();
}
}
}
}
use of org.eclipse.persistence.internal.oxm.record.UnmarshalRecord in project eclipselink by eclipse-ee4j.
the class XMLAnyObjectMappingNodeValue method endElement.
@Override
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
UnmarshalRecord childRecord = unmarshalRecord.getChildRecord();
if (null != childRecord) {
Object childObject = childRecord.getCurrentObject();
// OBJECT VALUE
if (xmlAnyObjectMapping.usesXMLRoot()) {
Descriptor workingDescriptor = childRecord.getDescriptor();
if (workingDescriptor != null) {
String prefix = xPathFragment.getPrefix();
if ((prefix == null) && (xPathFragment.getNamespaceURI() != null)) {
prefix = unmarshalRecord.resolveNamespaceUri(xPathFragment.getNamespaceURI());
}
childObject = workingDescriptor.wrapObjectInXMLRoot(childObject, xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), prefix, false, unmarshalRecord.isNamespaceAware(), unmarshalRecord.getUnmarshaller());
workingDescriptor = null;
}
}
childObject = xmlAnyObjectMapping.convertDataValueToObjectValue(childObject, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
unmarshalRecord.setAttributeValue(childObject, xmlAnyObjectMapping);
} else {
SAXFragmentBuilder builder = unmarshalRecord.getFragmentBuilder();
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlAnyObjectMapping.getKeepAsElementPolicy();
if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && builder.getNodes().size() > 1) {
setOrAddAttributeValueForKeepAsElement(builder, xmlAnyObjectMapping, xmlAnyObjectMapping, unmarshalRecord, false, null);
} else {
// TEXT VALUE
if (xmlAnyObjectMapping.isMixedContent()) {
endElementProcessText(unmarshalRecord, xmlAnyObjectMapping, xPathFragment, null);
} else {
unmarshalRecord.resetStringBuffer();
}
}
}
}
Aggregations