}
private static long longValue(AtomicValue value, long min, long max) throws XQException {
if (value instanceof NumericValue) {
if (value instanceof DoubleValue || value instanceof FloatValue) {
throw new XQException("Value is a double or float");
}
if (!((NumericValue)value).isWholeNumber()) {
throw new XQException("Value is not a whole number");
}
try {
long val = ((NumericValue)value).longValue();
if (val >= min && val <= max) {
return val;
} else {
throw new XQException("Value is out of range for requested type");
}
} catch (XPathException err) {
XQException xqe = new XQException(err.getMessage());
xqe.initCause(err);
throw xqe;
}
}
throw new XQException("Value is not numeric");
}