Search in sources :

Example 1 with UnmarshalRecord

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();
    }
}
Also used : UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord)

Example 2 with UnmarshalRecord

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);
}
Also used : CoreAbstractSession(org.eclipse.persistence.internal.core.sessions.CoreAbstractSession) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) QName(javax.xml.namespace.QName) CoreAttributeItem(org.eclipse.persistence.core.queries.CoreAttributeItem) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) XMLReader(org.eclipse.persistence.internal.oxm.record.XMLReader) DescriptorNotFoundContentHandler(org.eclipse.persistence.internal.oxm.record.deferred.DescriptorNotFoundContentHandler)

Example 3 with UnmarshalRecord

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);
    }
}
Also used : UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) SAXException(org.xml.sax.SAXException)

Example 4 with UnmarshalRecord

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();
            }
        }
    }
}
Also used : UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)

Example 5 with UnmarshalRecord

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();
            }
        }
    }
}
Also used : UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)

Aggregations

UnmarshalRecord (org.eclipse.persistence.internal.oxm.record.UnmarshalRecord)9 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)3 JsonArray (jakarta.json.JsonArray)2 JsonString (jakarta.json.JsonString)2 JsonValue (jakarta.json.JsonValue)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)2 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)2 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)2 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)2 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)2 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)2 Field (org.eclipse.persistence.internal.oxm.mappings.Field)2 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)2 AbstractUnmarshalRecord (org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord)2 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2