When.java revision 286
0N/A/*
2362N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 2001-2004 The Apache Software Foundation.
2362N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
2362N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A */
0N/A/*
2362N/A * $Id: When.java,v 1.2.4.1 2005/09/05 09:36:58 pvedula Exp $
2362N/A */
2362N/A
0N/Apackage com.sun.org.apache.xalan.internal.xsltc.compiler;
0N/A
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
0N/Aimport com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
0N/A
0N/A/**
0N/A * @author Jacek Ambroziak
0N/A * @author Santiago Pericas-Geertsen
0N/A * @author Morten Jorgensen
0N/A */
0N/Afinal class When extends Instruction {
0N/A
0N/A private Expression _test;
0N/A private boolean _ignore = false;
0N/A
0N/A public void display(int indent) {
0N/A indent(indent);
0N/A Util.println("When");
0N/A indent(indent + IndentIncrement);
0N/A System.out.print("test ");
0N/A Util.println(_test.toString());
0N/A displayContents(indent + IndentIncrement);
0N/A }
0N/A
0N/A public Expression getTest() {
0N/A return _test;
0N/A }
0N/A
0N/A public boolean ignore() {
0N/A return(_ignore);
0N/A }
0N/A
0N/A public void parseContents(Parser parser) {
0N/A _test = parser.parseExpression(this, "test", null);
0N/A
0N/A // Ignore xsl:if when test is false (function-available() and
0N/A // element-available())
0N/A Object result = _test.evaluateAtCompileTime();
0N/A if (result != null && result instanceof Boolean) {
0N/A _ignore = !((Boolean) result).booleanValue();
0N/A }
0N/A
0N/A parseChildren(parser);
0N/A
0N/A // Make sure required attribute(s) have been set
0N/A if (_test.isDummy()) {
0N/A reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "test");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Type-check this when element. The test should always be type checked,
0N/A * while we do not bother with the contents if we know the test fails.
0N/A * This is important in cases where the "test" expression tests for
0N/A * the support of a non-available element, and the <xsl:when> body contains
0N/A * this non-available element.
0N/A */
0N/A public Type typeCheck(SymbolTable stable) throws TypeCheckError {
0N/A // Type-check the test expression
0N/A if (_test.typeCheck(stable) instanceof BooleanType == false) {
0N/A _test = new CastExpr(_test, Type.Boolean);
0N/A }
0N/A // Type-check the contents (if necessary)
0N/A if (!_ignore) {
0N/A typeCheckContents(stable);
0N/A }
0N/A
0N/A return Type.Void;
0N/A }
0N/A
0N/A /**
0N/A * This method should never be called. An Otherwise object will explicitly
0N/A * translate the "test" expression and and contents of this element.
0N/A */
0N/A public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
0N/A final ErrorMsg msg = new ErrorMsg(ErrorMsg.STRAY_WHEN_ERR, this);
0N/A getParser().reportError(Constants.ERROR, msg);
0N/A }
0N/A}
0N/A