示例#1
0
 /**
  * Ensures that none of the specified expressions performs an update. Otherwise, throws an
  * exception.
  *
  * @param exprs expressions (may be {@code null}, and may contain {@code null} references)
  * @throws QueryException query exception
  */
 protected final void checkNoneUp(final Expr... exprs) throws QueryException {
   if (exprs == null) return;
   checkAllUp(exprs);
   for (final Expr expr : exprs) {
     if (expr != null && expr.has(Flag.UPD)) throw UPNOT_X.get(info, description());
   }
 }
示例#2
0
  /**
   * Tests if the specified expressions are updating or vacuous.
   *
   * @param ctx query context
   * @param expr expression array
   * @throws QueryException query exception
   */
  public void checkUp(final QueryContext ctx, final Expr... expr) throws QueryException {

    if (!ctx.updating) return;
    int s = 0;
    for (final Expr e : expr) {
      if (e.vacuous()) continue;
      final boolean u = e.uses(Use.UPD);
      if (u && s == 2 || !u && s == 1) UPNOT.thrw(input, desc());
      s = u ? 1 : 2;
    }
  }
示例#3
0
 /**
  * Ensures that all specified expressions are vacuous or either updating or non-updating.
  * Otherwise, throws an exception.
  *
  * @param exprs expressions to be checked
  * @throws QueryException query exception
  */
 void checkAllUp(final Expr... exprs) throws QueryException {
   // updating state: 0 = initial state, 1 = updating, -1 = non-updating
   int s = 0;
   for (final Expr expr : exprs) {
     expr.checkUp();
     if (expr.isVacuous()) continue;
     final boolean u = expr.has(Flag.UPD);
     if (u && s == -1 || !u && s == 1) throw UPALL.get(info, description());
     s = u ? 1 : -1;
   }
 }
示例#4
0
 /**
  * Checks if the specified expression yields a float. Returns the float or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return float
  * @throws QueryException query exception
  */
 protected final float toFloat(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.atomItem(qc, info);
   if (checkNoEmpty(it, AtomType.FLT).type.isNumberOrUntyped()) return it.flt(info);
   throw numberError(this, it);
 }
示例#5
0
 /**
  * Checks if the specified expression yields a node. Returns the boolean or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return node
  * @throws QueryException query exception
  */
 protected final ANode toNode(final Expr ex, final QueryContext qc) throws QueryException {
   return toNode(checkNoEmpty(ex.item(qc, info), NodeType.NOD));
 }
示例#6
0
 /**
  * Checks if the specified expression yields a double. Returns the double or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return double
  * @throws QueryException query exception
  */
 protected final double toDouble(final Expr ex, final QueryContext qc) throws QueryException {
   return toDouble(ex.atomItem(qc, info));
 }
示例#7
0
 /**
  * Checks if the specified expression yields a number or {@code null}. Returns the number, {@code
  * null}, or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return double
  * @throws QueryException query exception
  */
 protected final ANum toNumber(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.atomItem(qc, info);
   return it == null ? null : toNumber(it);
 }
示例#8
0
 /**
  * Checks if the specified expression yields a QName. Returns the item or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @param empty allow empty result
  * @return QNm item
  * @throws QueryException query exception
  */
 protected final QNm toQNm(final Expr ex, final QueryContext qc, final boolean empty)
     throws QueryException {
   return toQNm(ex.atomItem(qc, info), empty);
 }
示例#9
0
 /**
  * Checks if the specified expressions is no updating expression.
  *
  * @param e expression
  * @param ctx query context
  * @return the specified expression
  * @throws QueryException query exception
  */
 public final Expr checkUp(final Expr e, final QueryContext ctx) throws QueryException {
   if (e != null && ctx.updating && e.uses(Use.UPD)) UPNOT.thrw(input, desc());
   return e;
 }
示例#10
0
 /**
  * Checks if the evaluated expression yields a non-empty item. Returns the atomized item or throws
  * an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return atomized item
  * @throws QueryException query exception
  */
 protected final Item toAtomItem(final Expr ex, final QueryContext qc) throws QueryException {
   return checkNoEmpty(ex.atomItem(qc, info));
 }
示例#11
0
  /**
   * Checks if the specified expression yields a double. Returns the double or throws an exception.
   *
   * @param e expression to be checked
   * @param ctx query context
   * @return double
   * @throws QueryException query exception
   */
  public final double checkDbl(final Expr e, final QueryContext ctx) throws QueryException {

    final Item it = checkNoEmpty(e.item(ctx, input), AtomType.DBL);
    if (!it.unt() && !it.num()) Err.number(this, it);
    return it.dbl(input);
  }
示例#12
0
 /**
  * Returns a boolean equivalent for the specified expression. If the specified expression yields a
  * boolean value anyway, it will be returned as is. Otherwise, it will be wrapped into a boolean
  * function.
  *
  * @param ex expression to be rewritten
  * @param info input info
  * @param sc static context
  * @return expression
  */
 protected static Expr compBln(final Expr ex, final InputInfo info, final StaticContext sc) {
   return ex.seqType().eq(SeqType.BLN) ? ex : Function.BOOLEAN.get(sc, info, ex);
 }
示例#13
0
 /**
  * Ensures that the specified expression performs no updates. Otherwise, throws an exception.
  *
  * @param expr expression (may be {@code null})
  * @throws QueryException query exception
  */
 protected void checkNoUp(final Expr expr) throws QueryException {
   if (expr == null) return;
   expr.checkUp();
   if (expr.has(Flag.UPD)) throw UPNOT_X.get(info, description());
 }
示例#14
0
 /**
  * Checks if the specified expression yields a string or empty sequence. Returns a token
  * representation or an exception.
  *
  * @param e expression to be evaluated
  * @param ctx query context
  * @return item
  * @throws QueryException query exception
  */
 public final byte[] checkEStr(final Expr e, final QueryContext ctx) throws QueryException {
   return checkEStr(e.item(ctx, input));
 }
示例#15
0
 /**
  * Checks if the specified expression yields a non-empty item.
  *
  * @param e expression to be evaluated
  * @param ctx query context
  * @return item
  * @throws QueryException query exception
  */
 public final Item checkItem(final Expr e, final QueryContext ctx) throws QueryException {
   return checkEmpty(e.item(ctx, input));
 }
示例#16
0
 /**
  * Checks if the specified expression is an integer. Returns a token representation or an
  * exception.
  *
  * @param e expression to be checked
  * @param ctx query context
  * @return integer value
  * @throws QueryException query exception
  */
 public final long checkItr(final Expr e, final QueryContext ctx) throws QueryException {
   return checkItr(checkNoEmpty(e.item(ctx, input), AtomType.ITR));
 }
示例#17
0
 /**
  * Checks if the specified expression yields a node or {@code null}. Returns the node, {@code
  * null}, or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return node or {@code null}
  * @throws QueryException query exception
  */
 protected final ANode toEmptyNode(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.item(qc, info);
   return it == null ? null : toNode(it);
 }
示例#18
0
 /**
  * Checks if the specified expression yields a binary item. Returns the binary item or throws an
  * exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return binary item
  * @throws QueryException query exception
  */
 protected final Bin toBin(final Expr ex, final QueryContext qc) throws QueryException {
   return toBin(ex.atomItem(qc, info));
 }
示例#19
0
 /**
  * Checks if the specified expression yields a non-empty item. Returns the item or throws an
  * exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @param type expected type
  * @return item
  * @throws QueryException query exception
  */
 private Item toItem(final Expr ex, final QueryContext qc, final Type type) throws QueryException {
   return checkNoEmpty(ex.item(qc, info), type);
 }
示例#20
0
  /**
   * Checks if the specified expression yields a boolean. Returns the boolean or throws an
   * exception.
   *
   * @param e expression to be checked
   * @param ctx query context
   * @return boolean
   * @throws QueryException query exception
   */
  public final boolean checkBln(final Expr e, final QueryContext ctx) throws QueryException {

    final Item it = checkNoEmpty(e.item(ctx, input), AtomType.BLN);
    if (!it.unt() && it.type != AtomType.BLN) Err.type(this, AtomType.BLN, it);
    return it.bool(input);
  }
示例#21
0
 /**
  * Checks if the specified expression yields an element. Returns the element or throws an
  * exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return binary item
  * @throws QueryException query exception
  */
 protected final ANode toElem(final Expr ex, final QueryContext qc) throws QueryException {
   return (ANode) checkType(ex.item(qc, info), NodeType.ELM);
 }
示例#22
0
 /**
  * Checks if the specified expression yields a string. Returns a value as token or throws an
  * exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return token
  * @throws QueryException query exception
  */
 protected final byte[] toToken(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.atomItem(qc, info);
   if (it == null) throw EMPTYFOUND_X.get(info, AtomType.STR);
   return toToken(it);
 }
示例#23
0
 /**
  * Checks if the specified expression yields a string or binary item.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return byte array
  * @throws QueryException query exception
  */
 protected final byte[] toBytes(final Expr ex, final QueryContext qc) throws QueryException {
   return toBytes(ex.atomItem(qc, info));
 }
示例#24
0
 /**
  * Checks if the specified expression yields a string or an empty sequence. Returns a value as
  * token or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return token (empty string if result is an empty sequence)
  * @throws QueryException query exception
  */
 protected final byte[] toEmptyToken(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.atomItem(qc, info);
   return it == null ? EMPTY : toToken(it);
 }
示例#25
0
 /**
  * Checks if the specified expression yields an item of the specified atomic type. Returns the
  * item or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @param type type to be checked
  * @return item
  * @throws QueryException query exception
  */
 protected Item checkAtomic(final Expr ex, final QueryContext qc, final Type type)
     throws QueryException {
   return checkType(ex.atomItem(qc, info), type);
 }
示例#26
0
 /**
  * Returns a boolean equivalent for the specified expression. If the specified expression yields a
  * boolean value anyway, it will be returned as is. Otherwise, it will be wrapped into a boolean
  * function.
  *
  * @param e expression to be rewritten
  * @return expression
  */
 protected final Expr compBln(final Expr e) {
   return e.type().eq(SeqType.BLN) ? e : Function.BOOLEAN.get(input, e);
 }