Search in sources :

Example 1 with ObjectMarshalContext

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

the class XPathObjectBuilder method marshalAttributes.

@Override
public boolean marshalAttributes(MarshalRecord marshalRecord, Object object, CoreAbstractSession session) {
    lazyInitialize();
    boolean hasValue = false;
    NamespaceResolver namespaceResolver = ((Descriptor) descriptor).getNamespaceResolver();
    List<XPathNode> attributeChildren = rootXPathNode.getAttributeChildren();
    if (null != attributeChildren) {
        ObjectMarshalContext objectMarshalContext = ObjectMarshalContext.getInstance();
        for (XPathNode anAttributeChildren : attributeChildren) {
            hasValue = anAttributeChildren.marshal(marshalRecord, object, session, namespaceResolver, null, objectMarshalContext, null) || hasValue;
        }
    }
    if (rootXPathNode.getAnyAttributeNode() != null) {
        hasValue = rootXPathNode.getAnyAttributeNode().marshal(marshalRecord, object, session, namespaceResolver, null, ObjectMarshalContext.getInstance(), null) || hasValue;
    }
    List<XPathNode> selfChildren = rootXPathNode.getSelfChildren();
    if (null != selfChildren) {
        for (XPathNode selfXPathNode : selfChildren) {
            NodeValue marshalNodeValue = selfXPathNode.getMarshalNodeValue();
            if (marshalNodeValue instanceof MappingNodeValue) {
                Mapping selfMapping = ((MappingNodeValue) marshalNodeValue).getMapping();
                Object value = selfMapping.getAttributeValueFromObject(object);
                Descriptor referenceDescriptor = (Descriptor) selfMapping.getReferenceDescriptor();
                Descriptor valueDescriptor;
                if (value != null && (referenceDescriptor == null || referenceDescriptor.hasInheritance())) {
                    valueDescriptor = (Descriptor) session.getDescriptor(value.getClass());
                } else {
                    valueDescriptor = referenceDescriptor;
                }
                if (null != valueDescriptor) {
                    marshalRecord.addXsiTypeAndClassIndicatorIfRequired(valueDescriptor, referenceDescriptor, (Field) selfMapping.getField(), false);
                }
            }
            selfXPathNode.marshalSelfAttributes(marshalRecord, object, session, namespaceResolver, marshalRecord.getMarshaller());
        }
    }
    return hasValue;
}
Also used : ObjectMarshalContext(org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) CoreDescriptor(org.eclipse.persistence.core.descriptors.CoreDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) FragmentMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) FragmentCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject)

Aggregations

CoreDescriptor (org.eclipse.persistence.core.descriptors.CoreDescriptor)1 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)1 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)1 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)1 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)1 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)1 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)1 ChoiceObjectMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)1 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)1 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)1 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)1 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)1 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)1 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)1 FragmentCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.FragmentCollectionMapping)1 FragmentMapping (org.eclipse.persistence.internal.oxm.mappings.FragmentMapping)1 InverseReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping)1 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)1