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;
}
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);
}
}
Aggregations