Example #1
0
 /**
  * Checks if an exception yields one of the specified error codes.
  *
  * @param ex exception
  * @param error expected errors
  */
 protected static void check(final QueryException ex, final Err... error) {
   if (error.length == 0) Util.notexpected("No error code specified");
   final String msg = ex.getMessage();
   boolean found = false;
   for (final Err e : error) found |= msg.contains(e.code());
   if (!found) {
     fail("'" + error[0].code() + "' not contained in '" + msg + "'.");
   }
 }
Example #2
0
 /**
  * Assures that the given (non-{@code null}) item is a map.
  *
  * @param it item to check
  * @return the map
  * @throws QueryException if the item is not a map
  */
 public Map checkMap(final Item it) throws QueryException {
   if (it instanceof Map) return (Map) it;
   throw Err.type(this, SeqType.ANY_MAP, it);
 }
Example #3
0
  /**
   * Checks the data type and throws an exception, if necessary.
   *
   * @param it item to be checked
   * @param t type to be checked
   * @return specified item
   * @throws QueryException query exception
   */
  public final Item checkType(final Item it, final Type t) throws QueryException {

    if (!checkEmpty(it).type.instance(t)) Err.type(this, t, it);
    return it;
  }
Example #4
0
 /**
  * Checks if the specified item is a string or an empty sequence. Returns a token representation
  * or an exception.
  *
  * @param it item to be checked
  * @return item
  * @throws QueryException query exception
  */
 public final byte[] checkEStr(final Item it) throws QueryException {
   if (it == null) return EMPTY;
   if (!it.str() && !it.unt()) Err.type(this, AtomType.STR, it);
   return it.atom(input);
 }
Example #5
0
 /**
  * Checks if the specified expression yields a string. 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[] checkStr(final Expr e, final QueryContext ctx) throws QueryException {
   final Item it = checkItem(e, ctx);
   if (!it.str() && !it.unt()) Err.type(this, AtomType.STR, it);
   return it.atom(input);
 }
Example #6
0
 /**
  * Checks if the specified expression is a node. Returns the node or an exception.
  *
  * @param it item to be checked
  * @return item
  * @throws QueryException query exception
  */
 public final ANode checkNode(final Item it) throws QueryException {
   if (!it.node()) Err.type(this, NodeType.NOD, it);
   return (ANode) it;
 }
Example #7
0
 /**
  * Checks if the specified item is a number. Returns a token representation or an exception.
  *
  * @param it item to be checked
  * @return item
  * @throws QueryException query exception
  */
 public final long checkItr(final Item it) throws QueryException {
   if (!it.unt() && !it.type.instance(AtomType.ITR)) Err.type(this, AtomType.ITR, it);
   return it.itr(input);
 }
Example #8
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);
  }
Example #9
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);
  }
Example #10
0
 /**
  * Returns a type error.
  *
  * @param ii input info
  * @param t expected type
  * @param it item
  * @throws QueryException query exception
  */
 final void errType(final InputInfo ii, final Type t, final Item it) throws QueryException {
   Err.type(ii, info(), t, it);
 }