if (suppliedItemType == null) {
suppliedItemType = exp.getItemType(th);
}
if (suppliedCard==StaticProperty.EMPTY && ((reqCard & StaticProperty.ALLOWS_ZERO) == 0) ) {
XPathException err = new XPathException("An empty sequence is not allowed as the " + role.getMessage(), supplied.getSourceLocator());
err.setErrorCode(role.getErrorCode());
err.setIsTypeError(true);
err.setLocator(exp.getSourceLocator());
throw err;
}
// Try a static type check. We only throw it out if the call cannot possibly succeed.
int relation = th.relationship(suppliedItemType, reqItemType);
if (relation == TypeHierarchy.DISJOINT) {
// The item types may be disjoint, but if both the supplied and required types permit
// an empty sequence, we can't raise a static error. Raise a warning instead.
if (Cardinality.allowsZero(suppliedCard) &&
Cardinality.allowsZero(reqCard)) {
if (suppliedCard != StaticProperty.EMPTY) {
String msg = "Required item type of " + role.getMessage() +
" is " + reqItemType.toString(env.getNamePool()) +
"; supplied value has item type " +
suppliedItemType.toString(env.getNamePool()) +
". The expression can succeed only if the supplied value is an empty sequence.";
env.issueWarning(msg, supplied.getSourceLocator());
}
} else {
XPathException err = new XPathException("Required item type of " + role.getMessage() +
" is " + reqItemType.toString(env.getNamePool()) +
"; supplied value has item type " +
suppliedItemType.toString(env.getNamePool()), supplied.getSourceLocator());
err.setErrorCode(role.getErrorCode());
err.setIsTypeError(true);
throw err;
}
}
// Unless the type is guaranteed to match, add a dynamic type check,
// unless the value is already known in which case we might as well report
// the error now.
if (!(relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY)) {
Expression cexp = new ItemChecker(exp, reqItemType, role);
cexp.adoptChildExpression(exp);
exp = cexp;
}
if (!cardOK) {
if (exp instanceof Literal) {
XPathException err = new XPathException("Required cardinality of " + role.getMessage() +
" is " + Cardinality.toString(reqCard) +
"; supplied value has cardinality " +
Cardinality.toString(suppliedCard), supplied.getSourceLocator());
err.setIsTypeError(true);
err.setErrorCode(role.getErrorCode());
throw err;
} else {
Expression cexp = CardinalityChecker.makeCardinalityChecker(exp, reqCard, role);
cexp.adoptChildExpression(exp);
exp = cexp;