@Override public void endPredicate() { predicateDepth--; Object predicate = pop(); Predicated predicated = (Predicated) peek(); Expression predicateExpr; if (predicate instanceof Expression) { predicateExpr = (Expression) predicate; if (predicateExpr.resultType == DataType.NUMBER) { if (predicate instanceof Literal) { Double d = (Double) predicateExpr.getResult(); int pos = d.intValue(); if (d != pos) predicateExpr = new Literal(Boolean.FALSE, DataType.BOOLEAN); else { Step step = predicated instanceof Step ? (Step) predicated : null; if (step != null && (step.axis == Axis.SELF || ((step.axis == Axis.ATTRIBUTE || step.axis == Axis.NAMESPACE) && step.constraint instanceof QName) || step.predicateSet.getPredicate() instanceof ExactPosition)) predicateExpr = new Literal(pos == 1, DataType.BOOLEAN); else predicateExpr = new ExactPosition(pos); } } else { FunctionCall equals = new FunctionCall(Functions.NUMBER_EQUALS_NUMBER); equals.addValidMember(new Position(), 0); equals.addValidMember(predicateExpr, 1); predicateExpr = equals; } } else predicateExpr = Functions.typeCast(predicateExpr, DataType.BOOLEAN); } else predicateExpr = Functions.typeCast(predicate, DataType.BOOLEAN); if (predicated instanceof LocationPath) { LocationPath path = (LocationPath) predicated; if (path.contexts.size() == 0) { LocationPath newPath = new LocationPath(Scope.LOCAL, 0); newPath.contexts.add(path); pop(); push(newPath); predicated = newPath; } } predicated.addPredicate(predicateExpr); }
@Override public void start() { assert predicateResult != Boolean.FALSE; assert !finished; if (event.hasInstantListener(expression)) { if (listener instanceof LocationEvaluation) predicateChain = ((LocationEvaluation) listener).predicateChain; else predicateChain = 0; if (predicateEvaluation != null) predicateChain++; } if (predicateEvaluation != null) { Expression predicate = predicateEvaluation.expression; if (predicate.scope() != Scope.DOCUMENT) predicateEvaluation.start(); } eventID.addListener(event, currentStep, this); }
private void resultPrepared() { if (!resultPrepared) { manuallyExpired = true; resultPrepared = true; for (LinkableEvaluation pendingEval = pendingEvaluationHead; pendingEval != null; pendingEval = pendingEval.next) pendingEval.removeListener(this); pendingEvaluationHead = pendingEvaluationTail = null; } if (predicateResult != null && (index != 0 || (stringEvaluations == null || stringEvaluations.size() == 0))) finished(); else if (result.size() == 0 && predicateResult == null) { // when result is empty, there is no need to wait for predicateEvaluation to // finish Expression predicate = predicateEvaluation.expression; if (predicate.scope() != Scope.DOCUMENT) predicateEvaluation.removeListener(this); else event.removeListener(predicate, this); finished(); } }
public PathExpression(LocationPath union, Expression relativeExpression, boolean forEach) { super(Scope.DOCUMENT, relativeExpression.resultType); assert relativeExpression.scope() != Scope.DOCUMENT; this.union = union; contexts = new Expression[union.contexts.size()]; for (int i = 0; i < contexts.length; i++) contexts[i] = union.contexts.get(i).typeCast(DataType.NODESET); this.relativeExpression = relativeExpression; if (relativeExpression instanceof LocationExpression) ((LocationExpression) relativeExpression).rawResult = true; else ((Literal) relativeExpression).rawResultRequired(); this.forEach = forEach; if (union.hitExpression != null) union.hitExpression.pathExpression = this; }