Search in sources :

Example 36 with NodeImpl

use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.

the class ValueSequence method getDescendantAttributes.

@Override
public Sequence getDescendantAttributes(final NodeTest test) throws XPathException {
    sortInDocumentOrder();
    final ValueSequence nodes = new ValueSequence(true);
    nodes.keepUnOrdered(keepUnOrdered);
    for (int i = 0; i <= size; i++) {
        final NodeImpl node = (NodeImpl) values[i];
        node.selectDescendantAttributes(test, nodes);
    }
    return nodes;
}
Also used : NodeImpl(org.exist.dom.memtree.NodeImpl)

Example 37 with NodeImpl

use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.

the class ValueSequence method getFollowingSiblings.

@Override
public Sequence getFollowingSiblings(final NodeTest test) throws XPathException {
    sortInDocumentOrder();
    final ValueSequence nodes = new ValueSequence(true);
    nodes.keepUnOrdered(keepUnOrdered);
    for (int i = 0; i <= size; i++) {
        final NodeImpl node = (NodeImpl) values[i];
        // if the context node is an attribute or namespace node, the following-sibling axis is empty
        if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
            node.selectFollowingSiblings(test, nodes);
        }
    }
    return nodes;
}
Also used : NodeImpl(org.exist.dom.memtree.NodeImpl)

Example 38 with NodeImpl

use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.

the class ValueSequence method getChildrenForParent.

@Override
public Sequence getChildrenForParent(final NodeImpl parent) {
    sortInDocumentOrder();
    final ValueSequence nodes = new ValueSequence(true);
    nodes.keepUnOrdered(keepUnOrdered);
    for (int i = 0; i <= size; i++) {
        final NodeImpl node = (NodeImpl) values[i];
        if (node.getNodeId().isChildOf(parent.getNodeId())) {
            nodes.add(node);
        }
    }
    return nodes;
}
Also used : NodeImpl(org.exist.dom.memtree.NodeImpl)

Example 39 with NodeImpl

use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.

the class OrderedValueSequence method toNodeSet.

@Override
public NodeSet toNodeSet() throws XPathException {
    // return early
    if (isEmpty()) {
        return NodeSet.EMPTY_SET;
    }
    // for this method to work, all items have to be nodes
    if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
        // Was ExtArrayNodeset() which orders the nodes in document order
        // The order seems to change between different invocations !!!
        final NodeSet set = new AVLTreeNodeSet();
        // NodeSet set = new ArraySet(100);
        for (int i = 0; i < count; i++) {
            NodeValue v = (NodeValue) items[i].item;
            if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
                // found an in-memory document
                final org.exist.dom.memtree.DocumentImpl doc = v.getType() == Type.DOCUMENT ? (org.exist.dom.memtree.DocumentImpl) v : ((NodeImpl) v).getOwnerDocument();
                if (doc == null) {
                    continue;
                }
                // make this document persistent: doc.makePersistent()
                // returns a map of all root node ids mapped to the corresponding
                // persistent node. We scan the current sequence and replace all
                // in-memory nodes with their new persistent node objects.
                final DocumentImpl expandedDoc = doc.expandRefs(null);
                final org.exist.dom.persistent.DocumentImpl newDoc = expandedDoc.makePersistent();
                if (newDoc != null) {
                    final NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
                    for (int j = i; j < count; j++) {
                        v = (NodeValue) items[j].item;
                        if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
                            NodeImpl node = (NodeImpl) v;
                            final Document nodeOwnerDoc = node.getNodeType() == Node.DOCUMENT_NODE ? (org.exist.dom.memtree.DocumentImpl) v : ((NodeImpl) v).getOwnerDocument();
                            if (nodeOwnerDoc == doc) {
                                node = expandedDoc.getNode(node.getNodeNumber());
                                NodeId nodeId = node.getNodeId();
                                if (nodeId == null) {
                                    throw new XPathException("Internal error: nodeId == null");
                                }
                                if (node.getNodeType() == Node.DOCUMENT_NODE) {
                                    nodeId = rootId;
                                } else {
                                    nodeId = rootId.append(nodeId);
                                }
                                final NodeProxy p = new NodeProxy(newDoc, nodeId, node.getNodeType());
                                if (p != null) {
                                    // replace the node by the NodeProxy
                                    items[j].item = p;
                                }
                            }
                        }
                    }
                }
                set.add((NodeProxy) items[i].item);
            } else {
                set.add((NodeProxy) v);
            }
        }
        return set;
    } else {
        throw new XPathException("Type error: the sequence cannot be converted into" + " a node set. Item type is " + Type.getTypeName(itemType));
    }
}
Also used : AVLTreeNodeSet(org.exist.dom.persistent.AVLTreeNodeSet) NodeSet(org.exist.dom.persistent.NodeSet) NodeImpl(org.exist.dom.memtree.NodeImpl) XPathException(org.exist.xquery.XPathException) AVLTreeNodeSet(org.exist.dom.persistent.AVLTreeNodeSet) Document(org.w3c.dom.Document) DocumentImpl(org.exist.dom.memtree.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy) NodeId(org.exist.numbering.NodeId) DocumentImpl(org.exist.dom.memtree.DocumentImpl)

Example 40 with NodeImpl

use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.

the class ValueSequence method selectChildren.

@Override
public Sequence selectChildren(final MemoryNodeSet children) {
    sortInDocumentOrder();
    final ValueSequence nodes = new ValueSequence(true);
    nodes.keepUnOrdered(keepUnOrdered);
    for (int i = 0; i <= size; i++) {
        final NodeImpl node = (NodeImpl) values[i];
        for (int j = 0; j < children.size(); j++) {
            final NodeImpl descendant = children.get(j);
            if (descendant.getNodeId().isChildOf(node.getNodeId())) {
                nodes.add(node);
            }
        }
    }
    return nodes;
}
Also used : NodeImpl(org.exist.dom.memtree.NodeImpl)

Aggregations

NodeImpl (org.exist.dom.memtree.NodeImpl)53 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)14 XPathException (org.exist.xquery.XPathException)9 DocumentImpl (org.exist.dom.memtree.DocumentImpl)8 Sequence (org.exist.xquery.value.Sequence)8 SAXException (org.xml.sax.SAXException)8 SAXAdapter (org.exist.dom.memtree.SAXAdapter)6 NodeProxy (org.exist.dom.persistent.NodeProxy)6 ValueSequence (org.exist.xquery.value.ValueSequence)6 IOException (java.io.IOException)5 Document (org.w3c.dom.Document)5 InputSource (org.xml.sax.InputSource)5 StringReader (java.io.StringReader)4 QName (org.exist.dom.QName)4 SequenceIterator (org.exist.xquery.value.SequenceIterator)4 XMLReader (org.xml.sax.XMLReader)4 DocumentBuilderReceiver (org.exist.dom.memtree.DocumentBuilderReceiver)3 NodeSet (org.exist.dom.persistent.NodeSet)3 NodeId (org.exist.numbering.NodeId)3 ValidationReport (org.exist.validation.ValidationReport)3