public boolean useGlobalParameter(int fingerprint, GlobalParam binding) throws XPathException {
if (globalParameters==null) {
return false;
}
Value val = globalParameters.get(fingerprint);
if (val==null) {
return false;
}
ItemType reqItemType = binding.getRequiredType().getPrimaryType();
if (val instanceof AtomicValue && reqItemType instanceof AtomicType) {
// If the parameter is an atomic value, typically a string supplied on
// the command line, we attempt to convert it to the required type. This
// will not always succeed.
val = ((AtomicValue)val).convert((AtomicType)reqItemType, null);
} else {
// For any other parameter value, we verify that if conforms to the
// required type. This must be precise conformance, we don't attempt to
// do atomization or to convert untypedAtomic values
if (!Type.isSubType(val.getItemType(), reqItemType)) {
DynamicError err = new DynamicError (
"Global parameter requires type " + reqItemType +
"; supplied value has type " + val.getItemType());
err.setIsTypeError(true);
throw err;
}
int reqCardinality = binding.getRequiredType().getCardinality();
if (!Cardinality.subsumes(reqCardinality, val.getCardinality())) {
DynamicError err = new DynamicError (
"Supplied value of external parameter does not match the required cardinality");
err.setIsTypeError(true);
throw err;
}