public GroupedValueSequence(
     GroupSpec groupSpecs[], int size, Sequence keySequence, XQueryContext aContext) {
   this.groupSpecs = groupSpecs;
   this.items = new Entry[size];
   this.groupKey = keySequence;
   //        this.context = aContext; //UNDERSTAND: do we need context here??? -shabanovd
   this.groupKeyLength = groupKey.getItemCount();
 }
 public Entry(Item item) throws XPathException {
   this.item = item;
   values = new AtomicValue[groupSpecs.length];
   for (int i = 0; i < groupSpecs.length; i++) {
     final Sequence seq = groupSpecs[i].getGroupExpression().eval(null);
     values[i] = AtomicValue.EMPTY_VALUE;
     // TODO : get rid of getLength()
     if (seq.hasOne()) {
       values[i] = seq.itemAt(0).atomize();
     } else if (seq.hasMany()) {
       throw new XPathException(
           "expected a single value for group by expression "
               + ExpressionDumper.dump(groupSpecs[i].getGroupExpression())
               + " ; found: "
               + seq.getItemCount());
     }
   }
 }
Beispiel #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;
  }