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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations