use of org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType in project eclipselink by eclipse-ee4j.
the class XmlBindingsGenerator method isDefaultNullPolicy.
/**
* Indicates is a given AbstractNullPolicy is the default. This is useful
* if it is not desirable to write out the default policy in the oxm
* metadata file.
*
* The default policy is NullPolicy, with the following set:
* <ul>
* <li>isNullRepresentedByXsiNil = false
* <li>isNullRepresentedByEmptyNode = true
* <li>isSetPerformedForAbsentNode = true
* <li>marshalNullRepresentation = XMLNullRepresentationType.ABSENT_NODE
* </ul>
*/
protected static boolean isDefaultNullPolicy(AbstractNullPolicy nullPolicy) {
// default policy is NullPolicy
if (nullPolicy instanceof IsSetNullPolicy) {
return false;
}
boolean xsiNil = nullPolicy.isNullRepresentedByXsiNil();
boolean emptyNode = nullPolicy.isNullRepresentedByEmptyNode();
boolean setForAbsent = nullPolicy.getIsSetPerformedForAbsentNode();
XMLNullRepresentationType marshalNull = nullPolicy.getMarshalNullRepresentation();
return (!xsiNil && emptyNode && setForAbsent && marshalNull == XMLNullRepresentationType.ABSENT_NODE);
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType 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);
}
Aggregations