Ejemplo n.º 1
0
 /**
  * Checks if the specified item is a QName. Returns the item or throws an exception.
  *
  * @param it item
  * @param empty allow empty result
  * @return QNm item
  * @throws QueryException query exception
  */
 protected final QNm toQNm(final Item it, final boolean empty) throws QueryException {
   if (empty && it == null) return null;
   final Type ip = checkNoEmpty(it, AtomType.QNM).type;
   if (ip == AtomType.QNM) return (QNm) it;
   if (ip.isUntyped()) throw NSSENS_X_X.get(info, ip, AtomType.QNM);
   throw castError(it, AtomType.QNM, info);
 }
Ejemplo n.º 2
0
 @Override
 public Expr optimize(final QueryContext ctx, final VarScope scp) throws QueryException {
   final SeqType s0 = expr[0].type();
   final SeqType s1 = expr[1].type();
   final Type t0 = s0.type;
   final Type t1 = s1.type;
   if (t0.isNumberOrUntyped() && t1.isNumberOrUntyped()) {
     final Occ occ = s0.one() && s1.one() ? Occ.ONE : Occ.ZERO_ONE;
     type = SeqType.get(Calc.type(t0, t1), occ);
   } else if (s0.one() && s1.one()) {
     type = SeqType.ITEM;
   }
   return optPre(oneIsEmpty() ? null : allAreValues() ? item(ctx, info) : this, ctx);
 }
Ejemplo n.º 3
0
 @Override
 public Type union(final Type t) {
   if (instanceOf(t)) return t;
   if (t instanceof ArrayType) {
     final ArrayType mt = (ArrayType) t;
     return mt.instanceOf(this) ? this : get(retType.union(mt.retType));
   }
   return t instanceof MapType ? ANY_FUN : t instanceof FuncType ? t.union(this) : AtomType.ITEM;
 }
Ejemplo n.º 4
0
 /**
  * Checks if the specified item is a number. Returns a token representation or throws an
  * exception.
  *
  * @param it item to be checked
  * @return number
  * @throws QueryException query exception
  */
 protected final long toLong(final Item it) throws QueryException {
   final Type ip = checkNoEmpty(it, AtomType.ITR).type;
   if (ip.instanceOf(AtomType.ITR) || ip.isUntyped()) return it.itr(info);
   throw castError(it, AtomType.ITR, info);
 }
Ejemplo n.º 5
0
 /**
  * Checks if the specified item is a boolean. Returns the boolean or throws an exception.
  *
  * @param it item be checked
  * @return boolean
  * @throws QueryException query exception
  */
 protected final boolean toBoolean(final Item it) throws QueryException {
   final Type ip = checkNoEmpty(it, AtomType.BLN).type;
   if (ip == AtomType.BLN) return it.bool(info);
   if (ip.isUntyped()) return Bln.parse(it.string(info), info);
   throw castError(it, AtomType.BLN, info);
 }
Ejemplo n.º 6
0
 /**
  * Checks if the specified non-empty item is a string. Returns its value as token or throws an
  * exception.
  *
  * @param it item to be checked
  * @return token
  * @throws QueryException query exception
  */
 protected final byte[] toToken(final Item it) throws QueryException {
   final Type ip = it.type;
   if (ip.isStringOrUntyped()) return it.string(info);
   throw it instanceof FItem ? FIATOM_X.get(info, it.type) : castError(it, AtomType.STR, info);
 }