use of org.exist.xquery.RootNode in project exist by eXist-db.
the class QNameIndexLookup method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (contextSequence == null || contextSequence.isEmpty()) {
// if the context sequence is empty, we create a default context
final RootNode rootNode = new RootNode(context);
contextSequence = rootNode.eval(null, null);
}
final Sequence[] args = getArguments(null, null);
final Item item = args[0].itemAt(0);
final QNameValue qval;
try {
// attempt to convert the first argument to a QName
qval = (QNameValue) item.convertTo(Type.QNAME);
} catch (final XPathException e) {
// wrong type: generate a diagnostic error
throw new XPathException(this, Messages.formatMessage(Error.FUNC_PARAM_TYPE, new Object[] { "1", getSignature().toString(), null, Type.getTypeName(Type.QNAME), Type.getTypeName(item.getType()) }));
}
QName qname = qval.getQName();
if (args.length == 3 && !(args[2].itemAt(0).toJavaObject(boolean.class))) {
qname = new QName(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix(), ElementValue.ATTRIBUTE);
}
final AtomicValue comparisonCriterion = args[1].itemAt(0).atomize();
final NativeValueIndex valueIndex = context.getBroker().getValueIndex();
final Sequence result = valueIndex.find(context.getWatchDog(), Comparison.EQ, contextSequence.getDocumentSet(), null, NodeSet.ANCESTOR, qname, comparisonCriterion);
return result;
}
Aggregations