예제 #1
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);
 }
예제 #2
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);
 }
예제 #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;
  }
예제 #4
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);
 }
예제 #5
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;
 }
예제 #6
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);
 }
예제 #7
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);
  }
예제 #8
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);
 }