Beispiel #1
0
 /**
  * Returns the new target type, or {@code null} if conversion is not necessary.
  *
  * @param curr old item
  * @param it new item
  * @return result (or {@code null})
  * @throws QueryException query exception
  */
 private AtomType numType(final Item curr, final Item it) throws QueryException {
   final Type ti = it.type;
   if (ti.isUntyped()) return DBL;
   final Type tc = curr.type;
   if (!(it instanceof ANum)) throw EXPTYPE_X_X_X.get(info, tc, ti, it);
   return tc == ti ? null : tc == DBL || ti == DBL ? DBL : tc == FLT || ti == FLT ? FLT : null;
 }
Beispiel #2
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);
 }
Beispiel #3
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);
 }
Beispiel #4
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);
 }