Exemplo n.º 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());
   }
 }
Exemplo n.º 2
0
 @Override
 public String toString() {
   final TokenBuilder tb = new TokenBuilder("map { ");
   boolean key = true;
   for (final Expr e : expr) {
     tb.add(key ? tb.size() > 6 ? ", " : "" : ":=").add(e.toString());
     key ^= true;
   }
   return tb.add(" }").toString();
 }
Exemplo n.º 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;
   }
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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));
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
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));
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
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());
 }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
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));
 }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
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);
 }