}
// fast path for the simple case
if (vec == null && format == null && gpsize == 0 && lang == null) {
return new StringValue("" + value);
}
// Use the numberer decided at compile time if possible; otherwise try to get it from
// a table of numberers indexed by language; if not there, load the relevant class and
// add it to the table.
Numberer numb = numberer;
if (numb == null) {
String language = lang.evaluateAsString(context);
if (nationalNumberers == null) {
nationalNumberers = new HashMap(4);
}
numb = (Numberer)nationalNumberers.get(language);
if (numb == null) {
numb = makeNumberer(language);
nationalNumberers.put(language, numb);
}
}
if (letterValue == null) {
letterVal = "";
} else {
letterVal = letterValue.evaluateAsString(context);
if (!("alphabetic".equals(letterVal) || "traditional".equals(letterVal))) {
DynamicError e = new DynamicError("letter-value must be \"traditional\" or \"alphabetic\"");
e.setXPathContext(context);
e.setErrorCode("XT0030");
throw e;
}
}
if (vec == null) {
vec = new ArrayList(1);
vec.add(new Long(value));
}
NumberFormatter nf;
if (formatter == null) { // format not known until run-time
nf = new NumberFormatter();
nf.prepare(format.evaluateAsString(context));
} else {
nf = formatter;
}
String s = nf.format(vec, gpsize, gpseparator, letterVal, ordinalVal, numb);
return new StringValue(s);
}