{throw new XPathException(this, ErrorCodes.XPTY0004, "The first operand must have at most one item", startSeq);}
else if (endSeq.hasMany())
{throw new XPathException(this, ErrorCodes.XPTY0004, "The second operand must have at most one item", endSeq);}
else {
if (context.isBackwardsCompatible()) {
NumericValue valueStart;
try {
//Currently breaks 1e3 to 3
valueStart = (NumericValue)startSeq.itemAt(0).convertTo(Type.NUMBER);
} catch (final XPathException e) {
throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(startSeq.itemAt(0).getType()) + "(" +
startSeq.itemAt(0).getStringValue() + ")'", startSeq);
}
NumericValue valueEnd;
try {
//Currently breaks 3 to 1e3
valueEnd = (NumericValue)endSeq.itemAt(0).convertTo(Type.NUMBER);
} catch (final XPathException e) {
throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(endSeq.itemAt(0).getType()) + "(" +
endSeq.itemAt(0).getStringValue() + ")'", endSeq);
}
//Implied by previous conversion
if (valueStart.hasFractionalPart()) {
throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(startSeq.itemAt(0).getType()) + "(" +
startSeq.itemAt(0).getStringValue() + ")'", startSeq);
}
//Implied by previous conversion
if (valueEnd.hasFractionalPart()) {
throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(endSeq.itemAt(0).getType()) + "(" +
startSeq.itemAt(0).getStringValue() + ")'", endSeq);
}
// result = new ValueSequence();
// for(long i = ((IntegerValue)valueStart.convertTo(Type.INTEGER)).getLong();
// i <= ((IntegerValue)valueEnd.convertTo(Type.INTEGER)).getLong(); i++) {
// result.add(new IntegerValue(i));
// }
result = new RangeSequence((IntegerValue)valueStart.convertTo(Type.INTEGER),
(IntegerValue)valueEnd.convertTo(Type.INTEGER));
} else {
//Quite unusual test : we accept integers but no other *typed* type
if (!Type.subTypeOf(startSeq.itemAt(0).atomize().getType(), Type.INTEGER) &&
!Type.subTypeOf(startSeq.itemAt(0).atomize().getType(), Type.UNTYPED_ATOMIC))
{throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +