public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
StructuredQName sVarName = null;
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
if (step != null && !(step instanceof XCompoundStep)) {
throw XProcException.dynamicError(23);
}
try {
String lexicalQName = sequences[0].head().getStringValue();
sVarName = StructuredQName.fromLexicalQName(
lexicalQName,
false,
false,
xPathContext.getConfiguration().getNameChecker(),
staticContext.getNamespaceResolver());
} catch (XPathException e) {
// FIXME: bad formatting
throw new XProcException("Invalid variable/option name. " + e.getMessage() + "XTDE1390");
}
boolean failIfUnknown = true;
if (sequences.length > 1) {
failIfUnknown = ((BooleanValue) sequences[1].head()).effectiveBooleanValue();
}
boolean value = false;
QName varName = new QName(sVarName.getURI(), sVarName.getLocalPart());
value = step.hasInScopeVariableBinding(varName);
if (!value) {
if (failIfUnknown) {
throw XProcException.dynamicError(33);
}
} else {
value = step.hasInScopeVariableValue(varName);
}
return value ? BooleanValue.TRUE : BooleanValue.FALSE;
}