Пример #1
0
  /* (non-Javadoc)
   * @see org.exist.xquery.Expression#eval(org.exist.xquery.StaticContext, org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
   */
  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());
    }

    Sequence result = atomize(expression.eval(contextSequence, contextItem));

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }
Пример #2
0
 public String toString() {
   StringBuffer result = new StringBuffer();
   result.append("atomize[");
   result.append(expression.toString());
   result.append("]");
   return result.toString();
 }
Пример #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[],
   *      org.exist.xquery.value.Sequence)
   */
  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());
    }

    Expression arg1 = getArgument(0);
    Sequence s1 = arg1.eval(contextSequence, contextItem);

    Expression arg2 = getArgument(1);
    context.pushDocumentContext();
    Sequence s2 = arg2.eval(contextSequence, contextItem);
    context.popDocumentContext();

    if (s1.isEmpty()) {
      return BooleanValue.valueOf(s2.isEmpty());
    } else if (s2.isEmpty()) {
      return BooleanValue.valueOf(s1.isEmpty());
    }

    Sequence result = null;
    StringBuffer v1 = new StringBuffer();
    StringBuffer v2 = new StringBuffer();
    try {
      if (s1.hasMany()) {
        for (int i = 0; i < s1.getItemCount(); i++) {
          v1.append(serialize((NodeValue) s1.itemAt(i)));
        }
      } else {
        v1.append(serialize((NodeValue) s1.itemAt(0)));
      }
      if (s2.hasMany()) {
        for (int i = 0; i < s2.getItemCount(); i++) {
          v2.append(serialize((NodeValue) s2.itemAt(i)));
        }
      } else {
        v2.append(serialize((NodeValue) s2.itemAt(0)));
      }
      Diff d = new Diff(v1.toString(), v2.toString());
      boolean identical = d.identical();
      if (!identical) {
        logger.warn("Diff result: " + d.toString());
      }
      result = new BooleanValue(identical);
    } catch (Exception e) {
      throw new XPathException(
          this,
          "An exception occurred while serializing node " + "for comparison: " + e.getMessage(),
          e);
    }

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }
Пример #4
0
 /* (non-Javadoc)
  * @see org.exist.xquery.Expression#dump(org.exist.xquery.util.ExpressionDumper)
  */
 public void dump(ExpressionDumper dumper) {
   if (dumper.verbosity() > 1) dumper.display("atomize[");
   expression.dump(dumper);
   if (dumper.verbosity() > 1) dumper.display("]");
 }
Пример #5
0
 /* (non-Javadoc)
  * @see org.exist.xquery.Expression#analyze(org.exist.xquery.Expression)
  */
 public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
   contextInfo.setParent(this);
   expression.analyze(contextInfo);
 }
Пример #6
0
 /* (non-Javadoc)
  * @see org.exist.xquery.AbstractExpression#getASTNode()
  */
 public XQueryAST getASTNode() {
   return expression.getASTNode();
 }
Пример #7
0
 /* (non-Javadoc)
  * @see org.exist.xquery.AbstractExpression#resetState()
  */
 public void resetState(boolean postOptimization) {
   super.resetState(postOptimization);
   expression.resetState(postOptimization);
 }
Пример #8
0
 public void setContextDocSet(DocumentSet contextSet) {
   super.setContextDocSet(contextSet);
   expression.setContextDocSet(contextSet);
 }
Пример #9
0
 /* (non-Javadoc)
  * @see org.exist.xquery.AbstractExpression#getDependencies()
  */
 public int getDependencies() {
   return expression.getDependencies();
 }
Пример #10
0
 public void accept(ExpressionVisitor visitor) {
   expression.accept(visitor);
 }