Ejemplo n.º 1
0
 @Override
 protected void fireFinished() {
   if (index == 0 && nodeSetListener != null) nodeSetListener.finished();
   super.fireFinished();
   if (stringEvaluations != null) {
     for (Evaluation stringEval : stringEvaluations) stringEval.removeListener(this);
   }
 }
Ejemplo n.º 2
0
 @Override
 @SuppressWarnings({"unchecked"})
 public void finished(Evaluation evaluation) {
   LongTreeMap.Entry<EvaluationInfo> entry = evaluations.getEntry(evaluation.order);
   assert entry.value.eval == evaluation;
   if (evaluation instanceof PredicateEvaluation) {
     PredicateEvaluation predicateEvaluation = (PredicateEvaluation) evaluation;
     if (predicateEvaluation.result != null) {
       if (predicateEvaluation.result instanceof Evaluation) {
         entry.value.eval = (Evaluation) predicateEvaluation.result;
         entry.value.eval.addListener(this);
         return;
       } else {
         entry.value.setResult(predicateEvaluation.result);
         entry.value.eval = null;
         pendingCount--;
       }
     } else {
       entry.value.doDiscards();
       evaluations.deleteEntry(entry);
       if (entry.value.eval != null) pendingCount--;
     }
   } else {
     entry.value.setResult(evaluation.getResult());
     entry.value.eval = null;
     pendingCount--;
   }
   tryToFinish();
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 @Override
 protected void dispose() {
   if (nodeSetListener != null) {
     for (LongTreeMap.Entry<Object> entry = result.firstEntry();
         entry != null;
         entry = entry.next()) nodeSetListener.discard(entry.getKey());
   }
   manuallyExpired = true;
   for (LinkableEvaluation pendingEval = pendingEvaluationHead;
       pendingEval != null;
       pendingEval = pendingEval.next) pendingEval.removeListener(this);
   pendingEvaluationHead = pendingEvaluationTail = null;
   if (predicateResult == null) predicateEvaluation.removeListener(this);
 }
Ejemplo n.º 5
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);
   }
 }
Ejemplo n.º 6
0
  @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);
  }
Ejemplo n.º 7
0
  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();
    }
  }
Ejemplo n.º 8
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());
    }
  }
Ejemplo n.º 9
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();
    }
  }