Search in sources :

Example 11 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLMarshaller method objectToXML.

/**
 * INTERNAL:
 * Convert the given object to an XML Document
 * @param object the object to marshal
 * @return the document which the specified object has been marshalled to
 * @param descriptor the XMLDescriptor for the object being marshalled
 * @throws XMLMarshalException if an error occurred during marshalling
 */
@Override
protected Document objectToXML(Object object, XMLDescriptor descriptor, boolean isXMLRoot) throws XMLMarshalException {
    AbstractSession session = context.getSession(descriptor);
    DocumentPreservationPolicy docPresPolicy = context.getDocumentPreservationPolicy(session);
    if (docPresPolicy != null && docPresPolicy.shouldPreserveDocument()) {
        XMLRecord xmlRow = null;
        if (!isXMLRoot) {
            xmlRow = (XMLRecord) ((XMLObjectBuilder) descriptor.getObjectBuilder()).createRecordFor(object, context.getDocumentPreservationPolicy(session));
            xmlRow.setMarshaller(this);
            if (this.attachmentMarshaller != null) {
                xmlRow.setXOPPackage(this.attachmentMarshaller.isXOPPackage());
            }
            addDescriptorNamespacesToXMLRecord(descriptor, xmlRow);
        }
        return objectToXML(object, descriptor, xmlRow, isXMLRoot, docPresPolicy);
    }
    return super.objectToXML(object, descriptor, isXMLRoot);
}
Also used : DocumentPreservationPolicy(org.eclipse.persistence.oxm.documentpreservation.DocumentPreservationPolicy) XMLObjectBuilder(org.eclipse.persistence.internal.oxm.XMLObjectBuilder) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) CoreAbstractSession(org.eclipse.persistence.internal.core.sessions.CoreAbstractSession)

Example 12 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLCompositeCollectionMapping method buildCompositeRowForDescriptor.

protected AbstractRecord buildCompositeRowForDescriptor(ClassDescriptor classDesc, Object attributeValue, AbstractSession session, XMLRecord parentRow, WriteType writeType) {
    XMLObjectBuilder objectBuilder = (XMLObjectBuilder) classDesc.getObjectBuilder();
    XMLRecord child = (XMLRecord) objectBuilder.createRecordFor(attributeValue, (XMLField) getField(), parentRow, this);
    child.setNamespaceResolver(parentRow.getNamespaceResolver());
    child.setSession(session);
    objectBuilder.buildIntoNestedRow(child, attributeValue, session, (XMLDescriptor) getReferenceDescriptor(), (XMLField) getField());
    return child;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLObjectBuilder(org.eclipse.persistence.internal.oxm.XMLObjectBuilder) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 13 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLCompositeCollectionMapping method writeFromObjectIntoRow.

/**
 * INTERNAL:
 */
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
    if (this.isReadOnly()) {
        return;
    }
    Object attributeValue = this.getAttributeValueFromObject(object);
    if (attributeValue == null) {
        row.put(this.getField(), null);
        return;
    }
    ContainerPolicy cp = this.getContainerPolicy();
    Vector nestedRows = new Vector(cp.sizeFor(attributeValue));
    Object iter = cp.iteratorFor(attributeValue);
    if (null != iter) {
        while (cp.hasNext(iter)) {
            Object element = cp.next(iter, session);
            // convert the value - if necessary
            element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
            if (element == null) {
                XMLNullRepresentationType nullRepresentation = getNullPolicy().getMarshalNullRepresentation();
                if (nullRepresentation == XMLNullRepresentationType.XSI_NIL) {
                    nestedRows.add(XMLRecord.NIL);
                } else if (nullRepresentation == XMLNullRepresentationType.EMPTY_NODE) {
                    Node emptyNode = XPathEngine.getInstance().createUnownedElement(((XMLRecord) row).getDOM(), (XMLField) field);
                    DOMRecord nestedRow = new DOMRecord(emptyNode);
                    nestedRows.add(nestedRow);
                }
            } else {
                nestedRows.addElement(buildCompositeRow(element, session, row, writeType));
            }
        }
    }
    Object fieldValue = null;
    if (!nestedRows.isEmpty()) {
        fieldValue = this.getDescriptor().buildFieldValueFromNestedRows(nestedRows, getStructureName(), session);
    }
    row.put(this.getField(), fieldValue);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) MapContainerPolicy(org.eclipse.persistence.internal.queries.MapContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLNullRepresentationType(org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType) DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) Node(org.w3c.dom.Node) Vector(java.util.Vector) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 14 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLCompositeCollectionMapping method writeSingleValue.

@Override
public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session) {
    Object element = convertObjectValueToDataValue(value, session, record.getMarshaller());
    XMLRecord nestedRow = (XMLRecord) buildCompositeRow(element, session, record, WriteType.UNDEFINED);
    record.add(getField(), nestedRow);
}
Also used : XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 15 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLCompositeCollectionMapping method valueFromRow.

@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
    ContainerPolicy cp = this.getContainerPolicy();
    Object fieldValue = row.getValues(this.getField());
    // BUG#2667762 there could be whitespace in the row instead of null
    if ((fieldValue == null) || (fieldValue instanceof String)) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Vector nestedRows = this.getDescriptor().buildNestedRowsFromFieldValue(fieldValue, executionSession);
    if (nestedRows == null) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Object result = null;
    if (reuseContainer) {
        Object currentObject = ((XMLRecord) row).getCurrentObject();
        Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
        result = container != null ? container : cp.containerInstance();
    } else {
        result = cp.containerInstance(nestedRows.size());
    }
    for (Enumeration stream = nestedRows.elements(); stream.hasMoreElements(); ) {
        XMLRecord nestedRow = (XMLRecord) stream.nextElement();
        Object objectToAdd;
        if (getNullPolicy().valueIsNull((Element) nestedRow.getDOM())) {
            objectToAdd = null;
        } else {
            objectToAdd = buildObjectFromNestedRow(nestedRow, joinManager, sourceQuery, executionSession, isTargetProtected);
        }
        cp.addInto(objectToAdd, result, sourceQuery.getSession());
        if (null != getContainerAccessor()) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            if (this.inverseReferenceMapping.getContainerPolicy() == null) {
                getContainerAccessor().setAttributeValueInObject(objectToAdd, currentObject);
            } else {
                Object backpointerContainer = getContainerAccessor().getAttributeValueFromObject(objectToAdd);
                if (backpointerContainer == null) {
                    backpointerContainer = this.inverseReferenceMapping.getContainerPolicy().containerInstance();
                    getContainerAccessor().setAttributeValueInObject(objectToAdd, backpointerContainer);
                }
                this.inverseReferenceMapping.getContainerPolicy().addInto(currentObject, backpointerContainer, executionSession);
            }
        }
    }
    return result;
}
Also used : MapContainerPolicy(org.eclipse.persistence.internal.queries.MapContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Enumeration(java.util.Enumeration) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Vector(java.util.Vector)

Aggregations

XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)50 XMLField (org.eclipse.persistence.oxm.XMLField)19 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)16 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)14 Element (org.w3c.dom.Element)11 Vector (java.util.Vector)10 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)10 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 XMLObjectBuilder (org.eclipse.persistence.internal.oxm.XMLObjectBuilder)7 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)6 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)6 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)6 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)6 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)6 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)6 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)6 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)5