Search in sources :

Example 1 with CoreField

use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.

the class XMLObjectReferenceMappingNodeValue method marshalSingleValue.

@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object targetObject, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
    Object fieldValue = xmlObjectReferenceMapping.buildFieldValue(targetObject, xmlField, session);
    if (fieldValue == null) {
        if (null != targetObject) {
            Field fkField = (Field) xmlObjectReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField);
            if (null == fkField) {
                Descriptor targetDescriptor = (Descriptor) session.getDescriptor(targetObject);
                fieldValue = marshalRecord.getMarshaller().getContext().getValueByXPath(targetObject, ((CoreField) targetDescriptor.getPrimaryKeyFields().get(0)).getName(), targetDescriptor.getNamespaceResolver(), Object.class);
            } else {
                fieldValue = marshalRecord.getMarshaller().getContext().getValueByXPath(targetObject, fkField.getXPath(), fkField.getNamespaceResolver(), Object.class);
            }
        }
        if (null == fieldValue) {
            return false;
        }
    }
    QName schemaType = xmlField.getSchemaTypeForValue(fieldValue, session);
    XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
    if (xPathFragment != null && xPathFragment.isAttribute()) {
        marshalRecord.attribute(xPathFragment, namespaceResolver, fieldValue, schemaType);
        marshalRecord.closeStartGroupingElements(groupingFragment);
    } else {
        marshalRecord.closeStartGroupingElements(groupingFragment);
        marshalRecord.characters(schemaType, fieldValue, null, false);
    }
    return true;
}
Also used : CoreField(org.eclipse.persistence.internal.core.helper.CoreField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) QName(javax.xml.namespace.QName) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) CoreField(org.eclipse.persistence.internal.core.helper.CoreField)

Example 2 with CoreField

use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.

the class QNameInheritancePolicy method addClassIndicatorFieldToRow.

/**
 * INTERNAL:
 * Add abstract class indicator information to the database row.  This is
 * required when building a row for an insert or an update of a concrete child
 * descriptor.
 */
@Override
public void addClassIndicatorFieldToRow(AbstractRecord databaseRow) {
    if (hasClassExtractor()) {
        return;
    }
    CoreField field = getClassIndicatorField();
    Object value = getClassIndicatorValue();
    if (usesXsiType) {
        boolean namespaceAware = ((XMLRecord) databaseRow).isNamespaceAware() || ((XMLRecord) databaseRow).hasCustomNamespaceMapper();
        if (value instanceof String) {
            if (namespaceAware) {
                if (((XMLRecord) databaseRow).getNamespaceSeparator() != Constants.COLON) {
                    value = ((String) value).replace(Constants.COLON, ((XMLRecord) databaseRow).getNamespaceSeparator());
                }
            } else {
                int colonIndex = ((String) value).indexOf(Constants.COLON);
                if (colonIndex > -1) {
                    value = ((String) value).substring(colonIndex + 1);
                }
            }
        }
    }
    databaseRow.put(field, value);
}
Also used : CoreField(org.eclipse.persistence.internal.core.helper.CoreField) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 3 with CoreField

use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.

the class MarshalRecord method add.

/**
 * INTERNAL:
 * Add the field-value pair to the document.
 */
@Override
public void add(CoreField key, Object value) {
    if (null == value) {
        return;
    }
    Field xmlField = convertToXMLField(key);
    XPathFragment lastFragment = xmlField.getLastXPathFragment();
    if (lastFragment.nameIsText()) {
        characters(xmlField.getSchemaType(), value, null, xmlField.isCDATA());
    } else if (lastFragment.isAttribute()) {
        attribute(lastFragment, xmlField.getNamespaceResolver(), value, xmlField.getSchemaType());
    } else {
        element(lastFragment);
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) CoreField(org.eclipse.persistence.internal.core.helper.CoreField) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 4 with CoreField

use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.

the class XMLChoiceObjectMappingNodeValue method marshalSingleValue.

@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
    Class<?> valueClass = null;
    if (value instanceof Root) {
        Root root = (Root) value;
        for (CoreField next : (List<CoreField>) this.xmlChoiceMapping.getFields()) {
            XPathFragment fragment = ((Field) next).getXPathFragment();
            while (fragment != null && !fragment.nameIsText) {
                if (fragment.getNextFragment() == null || fragment.getHasText()) {
                    if (fragment.getLocalName().equals(root.getLocalName())) {
                        String fragUri = fragment.getNamespaceURI();
                        String namespaceUri = root.getNamespaceURI();
                        if ((namespaceUri == null && fragUri == null) || (namespaceUri != null && fragUri != null && namespaceUri.equals(fragUri))) {
                            if (next == this.xmlField) {
                                return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
                            } else {
                                // If this root is associated with another field, then return and let that NodeValue handle it
                                return false;
                            }
                        }
                    }
                }
                fragment = fragment.getNextFragment();
            }
        }
        valueClass = root.getObject().getClass();
    }
    if (value != null) {
        if (valueClass == null) {
            valueClass = value.getClass();
        }
        Field fieldForClass = null;
        Class<?> theClass = valueClass;
        while (theClass != null) {
            fieldForClass = (Field) xmlChoiceMapping.getClassToFieldMappings().get(valueClass);
            if (fieldForClass != null) {
                break;
            }
            theClass = theClass.getSuperclass();
        }
        if (fieldForClass != null && fieldForClass.equals(this.xmlField)) {
            if (this.choiceElementNodeValues != null) {
                NodeValue nodeValue = this.choiceElementNodeValues.get(theClass);
                if (nodeValue != null) {
                    return nodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
                }
            }
            return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
        }
        List<Field> sourceFields = null;
        theClass = valueClass;
        while (theClass != null) {
            sourceFields = (List<Field>) xmlChoiceMapping.getClassToSourceFieldsMappings().get(theClass);
            if (sourceFields != null) {
                break;
            }
            theClass = theClass.getSuperclass();
        }
        if (sourceFields != null && sourceFields.contains(this.xmlField)) {
            return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
        }
    }
    return false;
}
Also used : CoreField(org.eclipse.persistence.internal.core.helper.CoreField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) List(java.util.List) CoreField(org.eclipse.persistence.internal.core.helper.CoreField)

Example 5 with CoreField

use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.

the class UnmarshalRecordImpl method get.

@Override
public Object get(CoreField key) {
    Field xmlField = this.convertToXMLField(key);
    XPathFragment lastFragment = xmlField.getLastXPathFragment();
    String namespaceURI = lastFragment.getNamespaceURI();
    if (namespaceURI == null) {
        NamespaceResolver namespaceResolver = xmlField.getNamespaceResolver();
        namespaceURI = Constants.EMPTY_STRING;
        if (null != namespaceResolver && !(lastFragment.isAttribute() && lastFragment.getPrefix() == null)) {
            namespaceURI = namespaceResolver.resolveNamespacePrefix(lastFragment.getPrefix());
            if (null == namespaceURI) {
                namespaceURI = Constants.EMPTY_STRING;
            }
        }
    }
    if (isNamespaceAware()) {
        return attributes.getValue(namespaceURI, lastFragment.getLocalName());
    }
    return attributes.getValue(lastFragment.getLocalName());
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) CoreField(org.eclipse.persistence.internal.core.helper.CoreField) NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver) UnmarshalNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.UnmarshalNamespaceResolver) StackUnmarshalNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.StackUnmarshalNamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Aggregations

CoreField (org.eclipse.persistence.internal.core.helper.CoreField)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)4 List (java.util.List)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 DataObject (commonj.sdo.DataObject)1 QName (javax.xml.namespace.QName)1 NamespaceResolver (org.eclipse.persistence.internal.oxm.NamespaceResolver)1 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)1 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)1 StackUnmarshalNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.StackUnmarshalNamespaceResolver)1 UnmarshalNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.UnmarshalNamespaceResolver)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 ContainerMapping (org.eclipse.persistence.mappings.ContainerMapping)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 XMLInverseReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)1 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)1 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)1