Search in sources :

Example 1 with XMLEntry

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

the class XPathEngine method create.

public void create(List<Field> xmlFields, Node contextNode, List<XMLEntry> values, Field lastUpdatedField, DocumentPreservationPolicy docPresPolicy, CoreAbstractSession session) {
    List itemsToWrite = new ArrayList();
    for (int i = 0, size = values.size(); i < size; i++) {
        XMLEntry nextEntry = values.get(i);
        itemsToWrite.add(nextEntry.getValue());
        if (i == (values.size() - 1) || values.get(i + 1).getXMLField() != nextEntry.getXMLField()) {
            create(nextEntry.getXMLField(), contextNode, itemsToWrite, lastUpdatedField, docPresPolicy, session);
            itemsToWrite = new ArrayList();
            lastUpdatedField = nextEntry.getXMLField();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) XMLNodeList(org.eclipse.persistence.platform.xml.XMLNodeList) List(java.util.List) XMLEntry(org.eclipse.persistence.oxm.record.XMLEntry)

Example 2 with XMLEntry

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

the class UnmarshalXPathEngine method addXMLEntry.

private void addXMLEntry(Node entryNode, XML_FIELD xmlField, List<XMLEntry> entries) {
    XMLEntry entry = new XMLEntry();
    entry.setValue(entryNode);
    entry.setXMLField(xmlField);
    entries.add(entry);
}
Also used : XMLEntry(org.eclipse.persistence.oxm.record.XMLEntry)

Example 3 with XMLEntry

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

the class XMLChoiceCollectionMapping method writeFromObjectIntoRow.

@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
    if (this.isReadOnly()) {
        return;
    }
    Object attributeValue = getAttributeValueFromObject(object);
    List<XMLEntry> nestedRows = new ArrayList<>();
    XMLRecord record = (XMLRecord) row;
    // First determine which Field is associated with each value:
    if (null != attributeValue) {
        ContainerPolicy cp = getContainerPolicy();
        Object iterator = cp.iteratorFor(attributeValue);
        if (null != iterator) {
            while (cp.hasNext(iterator)) {
                Object value = cp.next(iterator, session);
                value = convertObjectValueToDataValue(value, session, record.getMarshaller());
                NodeValue associatedNodeValue = null;
                XMLField associatedField = null;
                Object fieldValue = value;
                if (value instanceof XMLRoot) {
                    XMLRoot rootValue = (XMLRoot) value;
                    String localName = rootValue.getLocalName();
                    String namespaceUri = rootValue.getNamespaceURI();
                    fieldValue = rootValue.getObject();
                    associatedField = getFieldForName(localName, namespaceUri);
                    if (associatedField == null) {
                        associatedField = getClassToFieldMappings().get(fieldValue.getClass());
                    }
                } else {
                    associatedField = getClassToFieldMappings().get(value.getClass());
                }
                if (associatedField == null) {
                    // this may be a reference mapping
                    List<XMLField> sourceFields = classToSourceFieldsMappings.get(value.getClass());
                    if (sourceFields != null && sourceFields.size() > 0) {
                        DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(sourceFields.get(0));
                        for (XMLField next : sourceFields) {
                            fieldValue = ((XMLCollectionReferenceMapping) xmlMapping).buildFieldValue(value, next, session);
                            XMLEntry entry = new XMLEntry();
                            entry.setValue(fieldValue);
                            entry.setXMLField(next);
                            nestedRows.add(entry);
                        }
                    }
                } else {
                    DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(associatedField);
                    if (xmlMapping.isAbstractCompositeCollectionMapping()) {
                        fieldValue = ((XMLCompositeCollectionMapping) xmlMapping).buildCompositeRow(fieldValue, session, row, writeType);
                    }
                    XMLEntry entry = new XMLEntry();
                    entry.setValue(fieldValue);
                    entry.setXMLField(associatedField);
                    nestedRows.add(entry);
                }
            }
        }
    }
    row.put(getFields(), nestedRows);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) NodeValue(org.eclipse.persistence.internal.oxm.NodeValue) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) ArrayList(java.util.ArrayList) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLEntry(org.eclipse.persistence.oxm.record.XMLEntry) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 4 with XMLEntry

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

the class XMLChoiceCollectionMapping method valueFromRow.

@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
    List<XMLEntry> values = ((DOMRecord) row).getValuesIndicatingNoEntry(this.getFields());
    Object container = getContainerPolicy().containerInstance(values.size());
    for (XMLEntry next : values) {
        Field valueField = next.getXMLField();
        DatabaseMapping nextMapping = (DatabaseMapping) this.choiceElementMappings.get(valueField);
        if (nextMapping.isAbstractCompositeCollectionMapping()) {
            XMLCompositeCollectionMapping xmlMapping = (XMLCompositeCollectionMapping) nextMapping;
            Object value = xmlMapping.buildObjectFromNestedRow((AbstractRecord) next.getValue(), joinManager, sourceQuery, executionSession, isTargetProtected);
            value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller());
            getContainerPolicy().addInto(value, container, executionSession);
        } else if (nextMapping instanceof XMLCompositeDirectCollectionMapping) {
            XMLCompositeDirectCollectionMapping xmlMapping = (XMLCompositeDirectCollectionMapping) nextMapping;
            Object value = next.getValue();
            value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller());
            getContainerPolicy().addInto(value, container, executionSession);
        }
    }
    ArrayList<XMLMapping> processedMappings = new ArrayList<>();
    for (XMLMapping mapping : choiceElementMappings.values()) {
        if (((DatabaseMapping) mapping).isObjectReferenceMapping() && ((DatabaseMapping) mapping).isCollectionMapping() && !(processedMappings.contains(mapping))) {
            ((XMLCollectionReferenceMapping) mapping).readFromRowIntoObject(row, joinManager, ((XMLRecord) row).getCurrentObject(), cacheKey, sourceQuery, executionSession, isTargetProtected, container);
            processedMappings.add(mapping);
        }
    }
    return container;
}
Also used : DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) ArrayList(java.util.ArrayList) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLEntry(org.eclipse.persistence.oxm.record.XMLEntry) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Field(org.eclipse.persistence.internal.oxm.mappings.Field) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField)

Example 5 with XMLEntry

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

the class XPathEngine method replaceCollection.

public List<XMLEntry> replaceCollection(List<Field> xmlFields, List<XMLEntry> values, Node contextNode, DocumentPreservationPolicy docPresPolicy, Field lastUpdatedField, CoreAbstractSession session) {
    List<XMLEntry> oldNodes = unmarshalXPathEngine.selectNodes(contextNode, xmlFields, getNamespaceResolverForField(xmlFields.get(0)));
    if (oldNodes == null || oldNodes.size() == 0) {
        return oldNodes;
    }
    Iterator<XMLEntry> oldValues = oldNodes.iterator();
    // Remove all the old values, and then call create to add them back in.
    while (oldValues.hasNext()) {
        XMLEntry entry = oldValues.next();
        Node nextNode = (Node) entry.getValue();
        Node parent = nextNode.getParentNode();
        parent.removeChild(nextNode);
        while (parent != contextNode) {
            if (parent.getChildNodes().getLength() == 0) {
                nextNode = parent;
                parent = nextNode.getParentNode();
                parent.removeChild(nextNode);
            } else {
                break;
            }
        }
    }
    create(xmlFields, contextNode, values, lastUpdatedField, xmlBinderPolicy, session);
    return oldNodes;
}
Also used : Node(org.w3c.dom.Node) XMLEntry(org.eclipse.persistence.oxm.record.XMLEntry)

Aggregations

XMLEntry (org.eclipse.persistence.oxm.record.XMLEntry)5 ArrayList (java.util.ArrayList)3 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)2 List (java.util.List)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 NodeValue (org.eclipse.persistence.internal.oxm.NodeValue)1 Field (org.eclipse.persistence.internal.oxm.mappings.Field)1 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)1 XMLNodeList (org.eclipse.persistence.platform.xml.XMLNodeList)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1