use of org.exist.xquery.value.MemoryNodeSet in project exist by eXist-db.
the class SimpleStep method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
Sequence result = Sequence.EMPTY_SEQUENCE;
final Sequence set = expression.eval(contextSequence);
if (!set.isEmpty()) {
if (set.isPersistentSet()) {
final NodeSet nodeSet = set.toNodeSet();
switch(axis) {
case Constants.DESCENDANT_SELF_AXIS:
result = nodeSet.selectAncestorDescendant(contextSequence.toNodeSet(), NodeSet.DESCENDANT, true, contextId, true);
break;
case Constants.CHILD_AXIS:
result = nodeSet.selectParentChild(contextSequence.toNodeSet(), NodeSet.DESCENDANT, contextId);
break;
default:
throw new XPathException(this, "Wrong axis specified");
}
} else {
final MemoryNodeSet ctxNodes = contextSequence.toMemNodeSet();
final MemoryNodeSet nodes = set.toMemNodeSet();
switch(axis) {
case Constants.DESCENDANT_SELF_AXIS:
result = ctxNodes.selectDescendants(nodes);
break;
case Constants.CHILD_AXIS:
result = ctxNodes.selectChildren(nodes);
break;
}
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations