Beispiel #1
0
 private LocationEvaluation(
     LocationExpression expression,
     int stepIndex,
     Event event,
     EventID eventID,
     Expression predicate,
     Evaluation predicateEvaluation) {
   this(expression, stepIndex, event, eventID);
   predicateResult = null;
   if (predicateEvaluation == null) this.predicateEvaluation = event.addListener(predicate, this);
   else {
     this.predicateEvaluation = predicateEvaluation;
     predicateEvaluation.addListener(this);
   }
 }
Beispiel #2
0
 private void consume(Event event) {
   assert lastStep;
   Object resultItem = expression.getResultItem(event);
   if (resultItem instanceof Evaluation) {
     Evaluation eval = (Evaluation) resultItem;
     stringEvaluations.add(eval);
     eval.addListener(this);
     eval.start();
   } else if (predicateChain == 0) {
     event.onInstantResult(expression, (NodeItem) resultItem);
     resultItem = Event.DUMMY_VALUE;
   }
   assert resultItem != null : "ResultItem should be non-null";
   result.put(event.order(), resultItem);
   consumedResult();
   if (nodeSetListener != null) nodeSetListener.mayHit();
 }
Beispiel #3
0
  @Override
  public final void finished(Evaluation evaluation) {
    assert !finished : "can't consume evaluation result after finish";

    if (evaluation == predicateEvaluation) {
      predicateResult = (Boolean) evaluation.getResult();
      assert predicateResult != null : "evaluation result should be non-null";
      if (predicateResult == Boolean.FALSE) {
        if (nodeSetListener != null) {
          for (LongTreeMap.Entry<Object> entry = result.firstEntry();
              entry != null;
              entry = entry.next()) nodeSetListener.discard(entry.getKey());
        }
        result.clear();
        if (stringEvaluations != null) {
          for (Evaluation stringEval : stringEvaluations) stringEval.removeListener(this);
          stringEvaluations = null;
        }
        resultPrepared();
      } else {
        if (predicateChain != -1) decreasePredicateChain();
        if (resultPrepared) finished();
      }
    } else if (evaluation instanceof PredicateEvaluation) {
      PredicateEvaluation predicateEvaluation = (PredicateEvaluation) evaluation;
      remove(predicateEvaluation);

      if (predicateEvaluation.result != null) {
        Object resultItem = predicateEvaluation.result;
        if (resultItem instanceof Evaluation) {
          Evaluation stringEval = (Evaluation) resultItem;
          stringEvaluations.add(stringEval);
          stringEval.addListener(this);
        }
        consumeChildEvaluation(predicateEvaluation.order, resultItem);
      } else {
        if (nodeSetListener != null) nodeSetListener.discard(predicateEvaluation.order);
        consumedResult();
      }
    } else if (evaluation instanceof LocationEvaluation) {
      LocationEvaluation locEval = (LocationEvaluation) evaluation;
      remove(locEval);

      if (locEval.stringEvaluations != null) {
        for (Evaluation stringEval : locEval.stringEvaluations) stringEval.addListener(this);
        stringEvaluations.addAll(locEval.stringEvaluations);
      }
      boolean wasExpired = expired;
      consumeChildEvaluation(locEval.result);
      if (!wasExpired && expired) {
        assert !finished;
        LinkableEvaluation eval = locEval.next;
        while (eval != null) {
          eval.removeListener(this);
          remove(eval);
          eval = eval.next;
        }
        if (pendingEvaluationHead == null) resultPrepared();
      }
    } else {
      stringEvaluations.remove(evaluation);
      consumeChildEvaluation(evaluation.order, evaluation.getResult());
    }
  }
Beispiel #4
0
  @Override
  public void mayHit() {
    long order = event.order();
    EvaluationInfo evalInfo = evaluations.get(order);
    if (evalInfo == null) {
      evaluations.put(
          order,
          evalInfo =
              new EvaluationInfo(event, expression.union.hitExpression, order, nodeSetListener));

      if (positionTracker != null) {
        event.positionTrackerStack.addFirst(positionTracker);
        positionTracker.addEvaluation(event);
      }
      Expression predicate = expression.union.predicateSet.getPredicate();
      Object predicateResult = predicate == null ? Boolean.TRUE : event.evaluate(predicate);
      if (predicateResult == Boolean.TRUE) {
        Object r = event.evaluate(expression.relativeExpression);
        if (r == null) {
          event.evaluation.addListener(this);
          event.evaluation.start();
          evalInfo.eval = event.evaluation;
          pendingCount++;
          if (nodeSetListener != null) {
            if (event.evaluation instanceof LocationEvaluation)
              ((LocationEvaluation) event.evaluation).nodeSetListener = evalInfo;
            else ((PathEvaluation) event.evaluation).nodeSetListener = evalInfo;
          }
        } else {
          if (nodeSetListener != null) nodeSetListener.mayHit();
          evalInfo.setResult(r);
        }
      } else if (predicateResult == null) {
        Evaluation predicateEvaluation = event.evaluation;
        Object resultItem = expression.relativeExpression.getResult(event);
        if (nodeSetListener != null
            && !(nodeSetListener
                instanceof Event)) { // nodeSetListener will be event if xmlBuilder is set
          if (resultItem instanceof LocationEvaluation)
            ((LocationEvaluation) resultItem).nodeSetListener = evalInfo;
          else ((PathEvaluation) resultItem).nodeSetListener = evalInfo;
        }
        Evaluation childEval =
            new PredicateEvaluation(
                expression.relativeExpression,
                event.order(),
                resultItem,
                event,
                predicate,
                predicateEvaluation);
        childEval.addListener(this);
        childEval.start();
        evalInfo.eval = childEval;
        pendingCount++;
      } else throw new ImpossibleException();
    }
    evalInfo.hitCount++;

    if (evalInfo.hitCount == 1 && positionTracker != null) {
      positionTracker.startEvaluation();
      event.positionTrackerStack.pollFirst();
    }
  }