1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.INVOKEVIRTUAL; 24 import org.apache.bcel.generic.InstructionList; 25 import org.apache.bcel.generic.PUSH; 26 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 27 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 28 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 29 import org.apache.xalan.xsltc.compiler.util.StringType; 30 import org.apache.xalan.xsltc.compiler.util.Type; 31 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 32 import org.apache.xalan.xsltc.compiler.util.Util; 33 34 37 final class TransletOutput extends Instruction { 38 39 private Expression _filename; 40 private boolean _append; 41 42 45 public void display(int indent) { 46 indent(indent); 47 Util.println("TransletOutput: " + _filename); 48 } 49 50 54 public void parseContents(Parser parser) { 55 String filename = getAttribute("file"); 57 58 String append = getAttribute("append"); 61 62 if ((filename == null) || (filename.equals(EMPTYSTRING))) { 64 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "file"); 65 } 66 67 _filename = AttributeValue.create(this, filename, parser); 69 70 if (append != null && (append.toLowerCase().equals("yes") || 71 append.toLowerCase().equals("true"))) { 72 _append = true; 73 } 74 else 75 _append = false; 76 77 parseChildren(parser); 78 } 79 80 83 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 84 final Type type = _filename.typeCheck(stable); 85 if (type instanceof StringType == false) { 86 _filename = new CastExpr(_filename, Type.String); 87 } 88 typeCheckContents(stable); 89 return Type.Void; 90 } 91 92 96 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 97 final ConstantPoolGen cpg = classGen.getConstantPool(); 98 final InstructionList il = methodGen.getInstructionList(); 99 100 il.append(methodGen.loadHandler()); 102 103 final int open = cpg.addMethodref(TRANSLET_CLASS, 104 "openOutputHandler", 105 "(" + STRING_SIG + "Z)" + 106 TRANSLET_OUTPUT_SIG); 107 108 final int close = cpg.addMethodref(TRANSLET_CLASS, 109 "closeOutputHandler", 110 "("+TRANSLET_OUTPUT_SIG+")V"); 111 112 il.append(classGen.loadTranslet()); 114 _filename.translate(classGen, methodGen); 115 il.append(new PUSH(cpg, _append)); 116 il.append(new INVOKEVIRTUAL(open)); 117 118 il.append(methodGen.storeHandler()); 120 121 translateContents(classGen, methodGen); 123 124 il.append(classGen.loadTranslet()); 126 il.append(methodGen.loadHandler()); 127 il.append(new INVOKEVIRTUAL(close)); 128 129 il.append(methodGen.storeHandler()); 131 } 132 } 133 134 | Popular Tags |