Search in sources :

Example 11 with Expression

use of org.exist.xquery.Expression in project exist by eXist-db.

the class FunNot method eval.

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;
    final Expression arg = getArgument(0);
    // the remaining set
    if (Type.subTypeOf(arg.returnsType(), Type.NODE) && (contextSequence == null || contextSequence.isPersistentSet()) && !Dependency.dependsOn(arg, Dependency.CONTEXT_ITEM)) {
        if (contextSequence == null || contextSequence.isEmpty()) {
            // TODO: special treatment if the context sequence is empty:
            // within a predicate, we just return the empty sequence
            // otherwise evaluate the argument and return a boolean result
            // if (inPredicate && !inWhereClause)
            // result = Sequence.EMPTY_SEQUENCE;
            // else
            result = evalBoolean(contextSequence, contextItem, arg);
        } else {
            result = contextSequence.toNodeSet().copy();
            if (inPredicate) {
                for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
                    final NodeProxy item = (NodeProxy) i.nextItem();
                    // item.addContextNode(getExpressionId(), item);
                    if (contextId != Expression.NO_CONTEXT_ID) {
                        item.addContextNode(contextId, item);
                    } else {
                        item.addContextNode(getExpressionId(), item);
                    }
                }
            }
            // evaluate argument expression
            final Sequence argSeq = arg.eval(result);
            NodeSet argSet;
            if (contextId != Expression.NO_CONTEXT_ID) {
                argSet = argSeq.toNodeSet().getContextNodes(contextId);
            } else {
                argSet = argSeq.toNodeSet().getContextNodes(getExpressionId());
            }
            result = ((NodeSet) result).except(argSet);
        }
    // case 2: simply invert the boolean value
    } else {
        return evalBoolean(contextSequence, contextItem, arg);
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) SequenceIterator(org.exist.xquery.value.SequenceIterator) Expression(org.exist.xquery.Expression) Sequence(org.exist.xquery.value.Sequence) NodeProxy(org.exist.dom.persistent.NodeProxy)

Example 12 with Expression

use of org.exist.xquery.Expression in project exist by eXist-db.

the class QNameIndexLookup method setArguments.

/**
 * Overwritten to disable automatic type checks. We check manually.
 *
 * @see org.exist.xquery.Function#setArguments(java.util.List)
 */
public void setArguments(List<Expression> arguments) throws XPathException {
    // wrap arguments into a cardinality check, so an error will be generated if
    // one of the arguments returns an empty sequence
    Expression arg = arguments.get(0);
    arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "1", getSignature()));
    steps.add(arg);
    arg = arguments.get(1);
    arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "2", getSignature()));
    steps.add(arg);
    if (arguments.size() == 3) {
        arg = arguments.get(2);
        arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "3", getSignature()));
        steps.add(arg);
    }
}
Also used : Expression(org.exist.xquery.Expression) DynamicCardinalityCheck(org.exist.xquery.DynamicCardinalityCheck) Error(org.exist.xquery.util.Error)

Aggregations

Expression (org.exist.xquery.Expression)12 Sequence (org.exist.xquery.value.Sequence)7 XPathException (org.exist.xquery.XPathException)3 SequenceIterator (org.exist.xquery.value.SequenceIterator)3 Collator (com.ibm.icu.text.Collator)2 NodeProxy (org.exist.dom.persistent.NodeProxy)2 NodeSet (org.exist.dom.persistent.NodeSet)2 DynamicCardinalityCheck (org.exist.xquery.DynamicCardinalityCheck)2 Error (org.exist.xquery.util.Error)2 NodeValue (org.exist.xquery.value.NodeValue)2 StringValue (org.exist.xquery.value.StringValue)2 ValueSequence (org.exist.xquery.value.ValueSequence)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1