}
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
// Define default values
ErrorCode errorCode = DEFAULT_ERROR;
String errorDesc = DEFAULT_DESCRIPTION;
Sequence errorVal = Sequence.EMPTY_SEQUENCE;
// Enter if one or more parameters are supplied
if (args.length > 0) {
// If there are 2 arguments or more supplied
// use 2nd argument for error description
if (args.length > 1) {
errorDesc = args[1].getStringValue();
}
// If first argument is not empty, get qname from argument
// and construct error code
if (!args[0].isEmpty()) {
final QName errorQName = ((QNameValue) args[0].itemAt(0)).getQName();
String prefix = errorQName.getPrefix();
if (prefix==null){
final String ns = errorQName.getNamespaceURI();
prefix = getContext().getPrefixForURI(ns);
errorQName.setPrefix(prefix);
}
errorCode = new ErrorCode(errorQName, errorDesc);
}
// If there is a third argument, use it.
if (args.length == 3) {
errorVal = args[2];
}
}
logger.error(errorDesc + ": " + errorCode.toString());
throw new XPathException(this, errorCode, errorDesc, errorVal);
}