1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 23 import com.sun.org.apache.bcel.internal.generic.GETSTATIC; 24 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; 25 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 26 import com.sun.org.apache.bcel.internal.generic.InstructionList; 27 import com.sun.org.apache.bcel.internal.generic.NEW; 28 import com.sun.org.apache.bcel.internal.generic.PUSH; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 34 import com.sun.org.apache.xml.internal.utils.XMLChar; 35 36 41 final class DecimalFormatting extends TopLevelElement { 42 43 private static final String DFS_CLASS = "java.text.DecimalFormatSymbols"; 44 private static final String DFS_SIG = "Ljava/text/DecimalFormatSymbols;"; 45 46 private QName _name = null; 47 48 51 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 52 return Type.Void; 53 } 54 55 58 public void parseContents(Parser parser) { 59 final String name = getAttribute("name"); 61 if (name.length() > 0) { 62 if (!XMLChar.isValidQName(name)){ 63 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this); 64 parser.reportError(Constants.ERROR, err); 65 } 66 } 67 _name = parser.getQNameIgnoreDefaultNs(name); 68 if (_name == null) { 69 _name = parser.getQNameIgnoreDefaultNs(EMPTYSTRING); 70 } 71 72 SymbolTable stable = parser.getSymbolTable(); 74 if (stable.getDecimalFormatting(_name) != null) { 75 reportWarning(this, parser, ErrorMsg.SYMBOLS_REDEF_ERR, 76 _name.toString()); 77 } 78 else { 79 stable.addDecimalFormatting(_name, this); 80 } 81 } 82 83 87 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 88 89 ConstantPoolGen cpg = classGen.getConstantPool(); 90 InstructionList il = methodGen.getInstructionList(); 91 92 final int init = cpg.addMethodref(DFS_CLASS, "<init>", 95 "("+LOCALE_SIG+")V"); 96 97 il.append(classGen.loadTranslet()); 99 il.append(new PUSH(cpg, _name.toString())); 100 101 il.append(new NEW(cpg.addClass(DFS_CLASS))); 106 il.append(DUP); 107 il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", 108 LOCALE_SIG))); 109 il.append(new INVOKESPECIAL(init)); 110 111 String tmp = getAttribute("NaN"); 112 if ((tmp == null) || (tmp.equals(EMPTYSTRING))) { 113 int nan = cpg.addMethodref(DFS_CLASS, 114 "setNaN", "(Ljava/lang/String;)V"); 115 il.append(DUP); 116 il.append(new PUSH(cpg, "NaN")); 117 il.append(new INVOKEVIRTUAL(nan)); 118 } 119 120 tmp = getAttribute("infinity"); 121 if ((tmp == null) || (tmp.equals(EMPTYSTRING))) { 122 int inf = cpg.addMethodref(DFS_CLASS, 123 "setInfinity", 124 "(Ljava/lang/String;)V"); 125 il.append(DUP); 126 il.append(new PUSH(cpg, "Infinity")); 127 il.append(new INVOKEVIRTUAL(inf)); 128 } 129 130 final int nAttributes = _attributes.getLength(); 131 for (int i = 0; i < nAttributes; i++) { 132 final String name = _attributes.getQName(i); 133 final String value = _attributes.getValue(i); 134 135 boolean valid = true; 136 int method = 0; 137 138 if (name.equals("decimal-separator")) { 139 method = cpg.addMethodref(DFS_CLASS, 141 "setDecimalSeparator", "(C)V"); 142 } 143 else if (name.equals("grouping-separator")) { 144 method = cpg.addMethodref(DFS_CLASS, 145 "setGroupingSeparator", "(C)V"); 146 } 147 else if (name.equals("minus-sign")) { 148 method = cpg.addMethodref(DFS_CLASS, 149 "setMinusSign", "(C)V"); 150 } 151 else if (name.equals("percent")) { 152 method = cpg.addMethodref(DFS_CLASS, 153 "setPercent", "(C)V"); 154 } 155 else if (name.equals("per-mille")) { 156 method = cpg.addMethodref(DFS_CLASS, 157 "setPerMill", "(C)V"); 158 } 159 else if (name.equals("zero-digit")) { 160 method = cpg.addMethodref(DFS_CLASS, 161 "setZeroDigit", "(C)V"); 162 } 163 else if (name.equals("digit")) { 164 method = cpg.addMethodref(DFS_CLASS, 165 "setDigit", "(C)V"); 166 } 167 else if (name.equals("pattern-separator")) { 168 method = cpg.addMethodref(DFS_CLASS, 169 "setPatternSeparator", "(C)V"); 170 } 171 else if (name.equals("NaN")) { 172 method = cpg.addMethodref(DFS_CLASS, 173 "setNaN", "(Ljava/lang/String;)V"); 174 il.append(DUP); 175 il.append(new PUSH(cpg, value)); 176 il.append(new INVOKEVIRTUAL(method)); 177 valid = false; 178 } 179 else if (name.equals("infinity")) { 180 method = cpg.addMethodref(DFS_CLASS, 181 "setInfinity", 182 "(Ljava/lang/String;)V"); 183 il.append(DUP); 184 il.append(new PUSH(cpg, value)); 185 il.append(new INVOKEVIRTUAL(method)); 186 valid = false; 187 } 188 else { 189 valid = false; 190 } 191 192 if (valid) { 193 il.append(DUP); 194 il.append(new PUSH(cpg, value.charAt(0))); 195 il.append(new INVOKEVIRTUAL(method)); 196 } 197 198 } 199 200 final int put = cpg.addMethodref(TRANSLET_CLASS, 201 "addDecimalFormat", 202 "("+STRING_SIG+DFS_SIG+")V"); 203 il.append(new INVOKEVIRTUAL(put)); 204 } 205 206 212 public static void translateDefaultDFS(ClassGenerator classGen, 213 MethodGenerator methodGen) { 214 215 ConstantPoolGen cpg = classGen.getConstantPool(); 216 InstructionList il = methodGen.getInstructionList(); 217 final int init = cpg.addMethodref(DFS_CLASS, "<init>", 218 "("+LOCALE_SIG+")V"); 219 220 il.append(classGen.loadTranslet()); 223 il.append(new PUSH(cpg, EMPTYSTRING)); 224 225 il.append(new NEW(cpg.addClass(DFS_CLASS))); 231 il.append(DUP); 232 il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", 233 LOCALE_SIG))); 234 il.append(new INVOKESPECIAL(init)); 235 236 int nan = cpg.addMethodref(DFS_CLASS, 237 "setNaN", "(Ljava/lang/String;)V"); 238 il.append(DUP); 239 il.append(new PUSH(cpg, "NaN")); 240 il.append(new INVOKEVIRTUAL(nan)); 241 242 int inf = cpg.addMethodref(DFS_CLASS, 243 "setInfinity", 244 "(Ljava/lang/String;)V"); 245 il.append(DUP); 246 il.append(new PUSH(cpg, "Infinity")); 247 il.append(new INVOKEVIRTUAL(inf)); 248 249 final int put = cpg.addMethodref(TRANSLET_CLASS, 250 "addDecimalFormat", 251 "("+STRING_SIG+DFS_SIG+")V"); 252 il.append(new INVOKEVIRTUAL(put)); 253 } 254 } 255 | Popular Tags |