001
002 /*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019 /*
020 * $Id: LiteralExpr.java 468650 2006-10-28 07:03:30Z minchau $
021 */
022
023 package org.apache.xalan.xsltc.compiler;
024
025 import org.apache.bcel.generic.ConstantPoolGen;
026 import org.apache.bcel.generic.InstructionList;
027 import org.apache.bcel.generic.PUSH;
028 import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
029 import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
030 import org.apache.xalan.xsltc.compiler.util.Type;
031 import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
032
033 /**
034 * @author Jacek Ambroziak
035 * @author Santiago Pericas-Geertsen
036 */
037 final class LiteralExpr extends Expression {
038 private final String _value;
039 private final String _namespace;
040
041 /**
042 * Creates a new literal expression node.
043 * @param value the literal expression content/value.
044 */
045 public LiteralExpr(String value) {
046 _value = value;
047 _namespace = null;
048 }
049
050 /**
051 * Creates a new literal expression node.
052 * @param value the literal expression content/value.
053 * @param namespace the namespace in which the expression exists.
054 */
055 public LiteralExpr(String value, String namespace) {
056 _value = value;
057 _namespace = namespace.equals(Constants.EMPTYSTRING) ? null : namespace;
058 }
059
060 public Type typeCheck(SymbolTable stable) throws TypeCheckError {
061 return _type = Type.String;
062 }
063
064 public String toString() {
065 return "literal-expr(" + _value + ')';
066 }
067
068 protected boolean contextDependent() {
069 return false;
070 }
071
072 protected String getValue() {
073 return _value;
074 }
075
076 protected String getNamespace() {
077 return _namespace;
078 }
079
080 public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
081 final ConstantPoolGen cpg = classGen.getConstantPool();
082 final InstructionList il = methodGen.getInstructionList();
083 il.append(new PUSH(cpg, _value));
084 }
085 }