コード例 #1
0
ファイル: PathExpression.java プロジェクト: Buzov/jlibs-1
 @Override
 public void start() {
   for (Expression context : expression.contexts) {
     Object result = event.evaluate(context);
     if (result == null) {
       Object eval = event.result(context);
       if (eval instanceof LocationEvaluation) ((LocationEvaluation) eval).nodeSetListener = this;
       else ((PathEvaluation) eval).nodeSetListener = this;
     } else throw new NotImplementedException();
   }
 }
コード例 #2
0
ファイル: PathExpression.java プロジェクト: Buzov/jlibs-1
 public PathEvaluation(PathExpression expression, Event event) {
   super(expression, event.order());
   this.event = event;
   contextsPending = expression.contexts.length;
   if (expression.union.predicateSet.hasPosition)
     positionTracker = new PositionTracker(expression.union.predicateSet.headPositionalPredicate);
 }
コード例 #3
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
 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();
 }
コード例 #4
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
 private void fireInstantResult(LongTreeMap<Object> result) {
   LongTreeMap.Entry<Object> entry = result.firstEntry();
   while (entry != null) {
     if (entry.value instanceof NodeItem) {
       event.onInstantResult(expression, (NodeItem) entry.value);
       entry.value = Event.DUMMY_VALUE;
     }
     entry = entry.next();
   }
   result.clear(); // to avoid memory leak
 }
コード例 #5
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
 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);
   }
 }
コード例 #6
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
  protected LocationEvaluation(
      LocationExpression expression, int stepIndex, Event event, EventID eventID) {
    super(expression, event.order());
    this.event = event;
    this.eventID = eventID;
    this.index = stepIndex;
    lastStep = index == expression.locationPath.steps.length - 1;

    if (expression instanceof Strings) stringEvaluations = new ArrayList<Evaluation>();

    currentStep = expression.locationPath.steps[stepIndex];
    exactPosition = currentStep.predicateSet.getPredicate() instanceof ExactPosition;
    if (currentStep.predicateSet.hasPosition)
      positionTracker = new PositionTracker(currentStep.predicateSet.headPositionalPredicate);
  }
コード例 #7
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
  @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);
  }
コード例 #8
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
  private void consumeChildEvaluation(long order, Object resultItem) {
    boolean prepareResult = false;
    if (expression.resultType == DataType.NUMBER) {
      if (resultItem instanceof Double && ((Double) resultItem).isNaN()) {
        result.clear();
        prepareResult = true;
      }
    }

    if (predicateChain == 0) {
      event.onInstantResult(expression, (NodeItem) resultItem);
      resultItem = Event.DUMMY_VALUE;
    }
    result.put(order, resultItem);
    consumedResult();

    if (prepareResult) resultPrepared();
  }
コード例 #9
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
  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();
    }
  }
コード例 #10
0
  @Override
  public void execute(
      final SesameDataSet dataset,
      final TriplesMap map,
      final RMLPerformer performer,
      InputStream input) {
    try {
      this.map = map;
      String reference = getReference(map.getLogicalSource());
      // Inititalize the XMLDog for processing XPath
      // an implementation of javax.xml.namespace.NamespaceContext
      // DefaultNamespaceContext dnc = new DefaultNamespaceContext();
      DefaultNamespaceContext dnc = get_namespaces();
      XMLDog dog = new XMLDog(dnc);

      // adding expression to the xpathprocessor
      dog.addXPath(reference);

      jlibs.xml.sax.dog.sniff.Event event = dog.createEvent();

      // event.setXMLBuilder(new DOMBuilder());
      // use XOM now
      event.setXMLBuilder(new XOMBuilder());

      event.setListener(
          new InstantEvaluationListener() {
            // When an XPath expression matches
            @Override
            public void onNodeHit(Expression expression, NodeItem nodeItem) {
              Node node = (Node) nodeItem.xml;
              // if(!nodeItem.namespaceURI.isEmpty())
              // log.info("namespace? " + nodeItem.namespaceURI);
              // else
              // log.info("no namespace.");
              // Let the performer do its thing
              performer.perform(node, dataset, map);
              // System.out.println("XPath: " + expression.getXPath() + " has hit: " +
              // node.getTextContent());
            }

            @Override
            public void finishedNodeSet(Expression expression) {
              // System.out.println("Finished Nodeset: " + expression.getXPath());
            }

            @Override
            public void onResult(Expression expression, Object result) {
              // this method is called only for xpaths which returns primitive result
              // i.e result will be one of String, Boolean, Double
              // System.out.println("XPath: " + expression.getXPath() + " result: " + result);
            }
          });
      // Execute the streaming

      // dog.sniff(event, new InputSource(new FileInputStream(fileName)));
      dog.sniff(event, new InputSource(input));
    } catch (SAXPathException ex) {
      Logger.getLogger(XPathProcessor.class.getName()).log(Level.SEVERE, null, ex);
    } catch (XPathException ex) {
      Logger.getLogger(XPathProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
コード例 #11
0
ファイル: LocationEvaluation.java プロジェクト: mleegwt/jlibs
  @Override
  public void onHit(EventID eventID) {
    assert !finished : "getting events even after finish";

    final LocationExpression expression = this.expression;
    if (!lastStep) {
      if (eventID.isEmpty(expression.locationPath.steps[index + 1].axis)) return;
    }

    final Event event = this.event;

    if (positionTracker != null) {
      event.positionTrackerStack.addFirst(positionTracker);
      positionTracker.addEvaluation(event);
    }
    LinkableEvaluation childEval = null;

    Expression predicate = currentStep.predicateSet.getPredicate();
    Object predicateResult = predicate == null ? Boolean.TRUE : event.evaluate(predicate);
    if (predicateResult == Boolean.TRUE) {
      if (lastStep) consume(event);
      else childEval = new LocationEvaluation(expression, index + 1, event, eventID);
    } else if (predicateResult == null) {
      Evaluation predicateEvaluation = event.evaluation;
      if (lastStep) {
        childEval =
            new PredicateEvaluation(
                expression,
                event.order(),
                expression.getResultItem(event),
                event,
                predicate,
                predicateEvaluation);
        if (nodeSetListener != null) nodeSetListener.mayHit();
      } else
        childEval =
            new LocationEvaluation(
                expression, index + 1, event, eventID, predicate, predicateEvaluation);
    }

    if (childEval != null) {
      if (childEval instanceof LocationEvaluation)
        ((LocationEvaluation) childEval).nodeSetListener = nodeSetListener;
      else ((PredicateEvaluation) childEval).nodeSetListener = nodeSetListener;

      childEval.addListener(this);
      if (pendingEvaluationTail != null) {
        pendingEvaluationTail.next = childEval;
        childEval.previous = pendingEvaluationTail;
        pendingEvaluationTail = childEval;
      } else pendingEvaluationHead = pendingEvaluationTail = childEval;
      childEval.start();
    }

    if (positionTracker != null) {
      positionTracker.startEvaluation();
      event.positionTrackerStack.pollFirst();
    }
    if (exactPosition && predicateResult == Boolean.TRUE) {
      manuallyExpired = true;
      expired();
    }
  }
コード例 #12
0
ファイル: PathExpression.java プロジェクト: Buzov/jlibs-1
 @Override
 public Object getResult(Event event) {
   PathEvaluation pathEvaluation = (PathEvaluation) event.result(pathExpression);
   return pathEvaluation.evaluations.get(event.order());
 }
コード例 #13
0
ファイル: PathExpression.java プロジェクト: Buzov/jlibs-1
 @Override
 public void mayHit() {
   mayHits.add(event.order());
   nodeSetListener.mayHit();
 }
コード例 #14
0
ファイル: PathExpression.java プロジェクト: Buzov/jlibs-1
  @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();
    }
  }