* This method is called when the constructor is compiled in
* Stylesheet.compileConstructor() and not as the syntax tree is traversed.
*/
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
ConstantPoolGen cpg = classGen.getConstantPool();
InstructionList il = methodGen.getInstructionList();
// DecimalFormatSymbols.<init>();
final int init = cpg.addMethodref(DFS_CLASS, "<init>", "()V");
// Push the format name on the stack for call to addDecimalFormat()
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, _name.toString()));
// Manufacture a DecimalFormatSymbols on the stack
// for call to addDecimalFormat()
il.append(new NEW(cpg.addClass(DFS_CLASS)));
il.append(DUP);
il.append(new INVOKESPECIAL(init));
String tmp = getAttribute("NaN");
if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
int nan = cpg.addMethodref(DFS_CLASS,
"setNaN", "(Ljava/lang/String;)V");
il.append(DUP);
il.append(new PUSH(cpg, "NaN"));
il.append(new INVOKEVIRTUAL(nan));
}
tmp = getAttribute("infinity");
if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
int inf = cpg.addMethodref(DFS_CLASS,
"setInfinity",
"(Ljava/lang/String;)V");
il.append(DUP);
il.append(new PUSH(cpg, "Infinity"));
il.append(new INVOKEVIRTUAL(inf));
}
final int nAttributes = _attributes.getLength();
for (int i = 0; i < nAttributes; i++) {
final String name = _attributes.getQName(i);
final String value = _attributes.getValue(i);
boolean valid = true;
int method = 0;
if (name.equals("decimal-separator")) {
// DecimalFormatSymbols.setDecimalSeparator();
method = cpg.addMethodref(DFS_CLASS,
"setDecimalSeparator", "(C)V");
}
else if (name.equals("grouping-separator")) {
method = cpg.addMethodref(DFS_CLASS,
"setGroupingSeparator", "(C)V");
}
else if (name.equals("minus-sign")) {
method = cpg.addMethodref(DFS_CLASS,
"setMinusSign", "(C)V");
}
else if (name.equals("percent")) {
method = cpg.addMethodref(DFS_CLASS,
"setPercent", "(C)V");
}
else if (name.equals("per-mille")) {
method = cpg.addMethodref(DFS_CLASS,
"setPerMill", "(C)V");
}
else if (name.equals("zero-digit")) {
method = cpg.addMethodref(DFS_CLASS,
"setZeroDigit", "(C)V");
}
else if (name.equals("digit")) {
method = cpg.addMethodref(DFS_CLASS,
"setDigit", "(C)V");
}
else if (name.equals("pattern-separator")) {
method = cpg.addMethodref(DFS_CLASS,
"setPatternSeparator", "(C)V");
}
else if (name.equals("NaN")) {
method = cpg.addMethodref(DFS_CLASS,
"setNaN", "(Ljava/lang/String;)V");
il.append(DUP);
il.append(new PUSH(cpg, value));
il.append(new INVOKEVIRTUAL(method));
valid = false;
}
else if (name.equals("infinity")) {
method = cpg.addMethodref(DFS_CLASS,
"setInfinity",
"(Ljava/lang/String;)V");
il.append(DUP);
il.append(new PUSH(cpg, value));
il.append(new INVOKEVIRTUAL(method));
valid = false;
}
else {
valid = false;
}
if (valid) {
il.append(DUP);
il.append(new PUSH(cpg, value.charAt(0)));
il.append(new INVOKEVIRTUAL(method));
}
}
final int put = cpg.addMethodref(TRANSLET_CLASS,
"addDecimalFormat",
"("+STRING_SIG+DFS_SIG+")V");
il.append(new INVOKEVIRTUAL(put));
}