use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ValueSequence method getPreceding.
@Override
public Sequence getPreceding(final NodeTest test, final int position) 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.selectPreceding(test, nodes, position);
}
return nodes;
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ValueSequence method getAttributes.
/* Methods of MemoryNodeSet */
@Override
public Sequence getAttributes(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.selectAttributes(test, nodes);
}
return nodes;
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ValueSequence method getFollowing.
@Override
public Sequence getFollowing(final NodeTest test, final int position) 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.selectFollowing(test, nodes, position);
}
return nodes;
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ValueSequence method getChildren.
@Override
public Sequence getChildren(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.selectChildren(test, nodes);
}
return nodes;
}
use of org.exist.dom.memtree.NodeImpl in project exist by eXist-db.
the class ValueSequence method toNodeSet.
/**
* Makes all in-memory nodes in this sequence persistent,
* so they can be handled like other node sets.
*
* @see org.exist.xquery.value.Sequence#toNodeSet()
*/
@Override
public NodeSet toNodeSet() throws XPathException {
if (size == UNSET_SIZE) {
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)) {
final NodeSet set = new NewArrayNodeSet();
for (int i = 0; i <= size; i++) {
NodeValue v = (NodeValue) values[i];
if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
// found an in-memory document
final DocumentImpl doc;
if (v.getType() == Type.DOCUMENT) {
doc = (DocumentImpl) v;
} else {
doc = ((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) {
NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
for (int j = i; j <= size; j++) {
v = (NodeValue) values[j];
if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
NodeImpl node = (NodeImpl) v;
final Document nodeOwnerDoc;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
nodeOwnerDoc = (Document) node;
} else {
nodeOwnerDoc = node.getOwnerDocument();
}
if (nodeOwnerDoc == doc) {
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
node = expandedDoc.getAttribute(node.getNodeNumber());
} else {
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());
// replace the node by the NodeProxy
values[j] = p;
}
}
}
set.add((NodeProxy) values[i]);
}
} else {
set.add((NodeProxy) v);
}
}
if (holderVar != null) {
holderVar.setValue(set);
}
return set;
} else {
throw new XPathException("Type error: the sequence cannot be converted into" + " a node set. Item type is " + Type.getTypeName(itemType));
}
}
Aggregations