Search in sources :

Example 1 with XMLNullRepresentationType

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);
}
Also used : XMLNullRepresentationType(org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy)

Example 2 with XMLNullRepresentationType

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

Aggregations

XMLNullRepresentationType (org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType)2 Vector (java.util.Vector)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 MapContainerPolicy (org.eclipse.persistence.internal.queries.MapContainerPolicy)1 XmlIsSetNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)1 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)1 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)1 Node (org.w3c.dom.Node)1