Search in sources :

Example 11 with QNameValue

use of org.exist.xquery.value.QNameValue 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

QNameValue (org.exist.xquery.value.QNameValue)11 QName (org.exist.dom.QName)9 Sequence (org.exist.xquery.value.Sequence)9 XPathException (org.exist.xquery.XPathException)7 Item (org.exist.xquery.value.Item)5 AtomicValue (org.exist.xquery.value.AtomicValue)3 Collator (com.ibm.icu.text.Collator)2 NodeImpl (org.exist.dom.memtree.NodeImpl)2 ComputableValue (org.exist.xquery.value.ComputableValue)2 IntegerValue (org.exist.xquery.value.IntegerValue)2 NodeValue (org.exist.xquery.value.NodeValue)2 NumericValue (org.exist.xquery.value.NumericValue)2 SequenceIterator (org.exist.xquery.value.SequenceIterator)2 INode (org.exist.dom.INode)1 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)1 ElementImpl (org.exist.dom.persistent.ElementImpl)1 NodeProxy (org.exist.dom.persistent.NodeProxy)1 NodeSet (org.exist.dom.persistent.NodeSet)1 NativeValueIndex (org.exist.storage.NativeValueIndex)1 org.exist.xquery (org.exist.xquery)1