*/
public TailCall processLeavingTail(XPathContext context) throws XPathException
{
Controller controller = context.getController();
SequenceReceiver out = context.getReceiver();
int opt = getOptions();
int ann = getAnnotation();
// we may need to change the namespace prefix if the one we chose is
// already in use with a different namespace URI: this is done behind the scenes
// by the Outputter
CharSequence value = expandChildren(context);
SimpleType schemaType = getSchemaType();
int validationAction = getValidationAction();
if (schemaType != null) {
// test whether the value actually conforms to the given type
ValidationFailure err = schemaType.validateContent(
value, DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker());
if (err != null) {
ValidationException verr = new ValidationException(
"Attribute value " + Err.wrap(value, Err.VALUE) +
" does not the match the required type " +
schemaType.getDescription() + ". " + err.getMessage());
verr.setErrorCode("XTTE1540");
verr.setLocator((SourceLocator)this);
throw verr;
}
} else if (validationAction==Validation.STRICT || validationAction==Validation.LAX) {
// TODO: attempt compile-time validation where possible, as with type=x.
try {
ann = controller.getConfiguration().validateAttribute(
nameCode, value, validationAction);
} catch (ValidationException e) {
XPathException err = XPathException.makeXPathException(e);
//String errorCode = e.getErrorCodeLocalPart();
//if (errorCode == null) {
// errorCode = (validationAction==Validation.STRICT ? "XTTE1510" : "XTTE1515");
//}
err.setErrorCode(validationAction==Validation.STRICT ? "XTTE1510" : "XTTE1515");
err.setXPathContext(context);
err.setLocator(this);
err.setIsTypeError(true);
throw err;
}
}
try {
out.attribute(nameCode, ann, value, locationId, opt);
} catch (XPathException err) {
throw dynamicError(this, err, context);
}
return null;