예제 #1
0
파일: Transform.java 프로젝트: nikhi/basex
  @Override
  public Value value(final QueryContext ctx) throws QueryException {
    final int o = (int) ctx.resources.output.size();
    final Updates updates = ctx.resources.updates();
    final ContextModifier tmp = updates.mod;
    final TransformModifier pu = new TransformModifier();
    updates.mod = pu;

    try {
      for (final Let fo : copies) {
        final Iter ir = ctx.iter(fo.expr);
        Item i = ir.next();
        if (!(i instanceof ANode) || ir.next() != null) throw UPCOPYMULT.get(fo.info, fo.var.name);

        // copy node to main memory data instance
        i = ((ANode) i).dbCopy(ctx.context.options);
        // add resulting node to variable
        ctx.set(fo.var, i, info);
        pu.addData(i.data());
      }
      final Value v = ctx.value(expr[0]);
      if (!v.isEmpty()) throw BASEX_MOD.get(info);

      updates.prepare();
      updates.apply();
      return ctx.value(expr[1]);
    } finally {
      ctx.resources.output.size(o);
      updates.mod = tmp;
    }
  }
예제 #2
0
파일: FNUnit.java 프로젝트: nikhi/basex
 /**
  * Performs the test-uris function.
  *
  * @param ctx query context
  * @return resulting value
  * @throws QueryException query exception
  */
 private Item testUris(final QueryContext ctx) throws QueryException {
   checkCreate(ctx);
   final ArrayList<IO> inputs = new ArrayList<>();
   final Iter ir = ctx.iter(expr[0]);
   for (Item it; (it = ir.next()) != null; ) inputs.add(checkPath(it, ctx));
   return new Suite(ctx, info).test(inputs);
 }
예제 #3
0
파일: FNUnit.java 프로젝트: nikhi/basex
 /**
  * Performs the assert-equals function.
  *
  * @param ctx query context
  * @return resulting value
  * @throws QueryException query exception
  */
 private Item assertEquals(final QueryContext ctx) throws QueryException {
   final byte[] str = expr.length < 3 ? null : checkStr(expr[2], ctx);
   final Iter iter1 = ctx.iter(expr[0]), iter2 = ctx.iter(expr[1]);
   final Compare comp = new Compare(info);
   Item it1, it2;
   int c = 1;
   while (true) {
     it1 = iter1.next();
     it2 = iter2.next();
     final boolean empty1 = it1 == null, empty2 = it2 == null;
     if (empty1 && empty2) return null;
     if (empty1 || empty2 || !comp.deep(it1.iter(), it2.iter())) break;
     c++;
   }
   if (str != null) throw UNIT_MESSAGE.get(info, str);
   throw new UnitException(info, UNIT_ASSERT_EQUALS, it1, it2, c);
 }
예제 #4
0
파일: FNUnit.java 프로젝트: nikhi/basex
  /**
   * Performs the test function.
   *
   * @param ctx query context
   * @return resulting value
   * @throws QueryException query exception
   */
  private Item test(final QueryContext ctx) throws QueryException {
    final Unit unit = new Unit(ctx, info);
    if (expr.length == 0) return unit.test(sc);

    final ArrayList<StaticFunc> funcs = new ArrayList<>();
    final Iter ir = ctx.iter(expr[0]);
    for (Item it; (it = ir.next()) != null; ) {
      final FItem fi = checkFunc(it, ctx);
      if (fi.funcName() != null) {
        final StaticFunc sf = ctx.funcs.get(fi.funcName(), fi.arity(), null, true);
        if (sf != null) funcs.add(sf);
      }
    }
    return unit.test(sc, funcs);
  }
예제 #5
0
파일: Except.java 프로젝트: james-jw/basex
  @Override
  protected ANodeList eval(final Iter[] iter) throws QueryException {
    final ANodeList list = new ANodeList().check();

    for (Item it; (it = iter[0].next()) != null; ) list.add(toNode(it));
    final boolean db = list.dbnodes();

    final int el = exprs.length;
    for (int e = 1; e < el && !list.isEmpty(); e++) {
      final Iter ir = iter[e];
      for (Item it; (it = ir.next()) != null; ) {
        final int i = list.indexOf(toNode(it), db);
        if (i != -1) list.delete(i);
      }
    }
    return list;
  }
예제 #6
0
파일: FTWords.java 프로젝트: jefferya/basex
 /**
  * Returns the next token of the specified iterator or {@code null}.
  *
  * @param iter iterator to be checked
  * @return item
  * @throws QueryException query exception
  */
 private byte[] nextToken(final Iter iter) throws QueryException {
   final Item it = iter.next();
   return it == null ? null : toToken(it);
 }