Search in sources :

Example 1 with RootNode

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;
}
Also used : RootNode(org.exist.xquery.RootNode) Item(org.exist.xquery.value.Item) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) QNameValue(org.exist.xquery.value.QNameValue) AtomicValue(org.exist.xquery.value.AtomicValue) NativeValueIndex(org.exist.storage.NativeValueIndex) Sequence(org.exist.xquery.value.Sequence)

Aggregations

QName (org.exist.dom.QName)1 NativeValueIndex (org.exist.storage.NativeValueIndex)1 RootNode (org.exist.xquery.RootNode)1 XPathException (org.exist.xquery.XPathException)1 AtomicValue (org.exist.xquery.value.AtomicValue)1 Item (org.exist.xquery.value.Item)1 QNameValue (org.exist.xquery.value.QNameValue)1 Sequence (org.exist.xquery.value.Sequence)1