1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Vector ; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.PUSH; 26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 31 32 36 final class ElementAvailableCall extends FunctionCall { 37 38 public ElementAvailableCall(QName fname, Vector arguments) { 39 super(fname, arguments); 40 } 41 42 45 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 46 if (argument() instanceof LiteralExpr) { 47 return _type = Type.Boolean; 48 } 49 ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR, 50 "element-available", this); 51 throw new TypeCheckError(err); 52 } 53 54 59 public Object evaluateAtCompileTime() { 60 return getResult() ? Boolean.TRUE : Boolean.FALSE; 61 } 62 63 66 public boolean getResult() { 67 try { 68 final LiteralExpr arg = (LiteralExpr) argument(); 69 final String qname = arg.getValue(); 70 final int index = qname.indexOf(':'); 71 final String localName = (index > 0) ? 72 qname.substring(index + 1) : qname; 73 return getParser().elementSupported(arg.getNamespace(), 74 localName); 75 } 76 catch (ClassCastException e) { 77 return false; 78 } 79 } 80 81 86 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 87 final ConstantPoolGen cpg = classGen.getConstantPool(); 88 final boolean result = getResult(); 89 methodGen.getInstructionList().append(new PUSH(cpg, result)); 90 } 91 } 92 | Popular Tags |