1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22
23package com.sun.org.apache.xalan.internal.xsltc.compiler;
24
25import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
26import com.sun.org.apache.bcel.internal.generic.InstructionList;
27import com.sun.org.apache.bcel.internal.generic.PUSH;
28import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
29import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
30import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
31import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
32
33/**
34 * @author Jacek Ambroziak
35 * @author Santiago Pericas-Geertsen
36 */
37final class LiteralExpr extends Expression {
38    private final String _value;
39    private final String _namespace;
40
41    /**
42     * Creates a new literal expression node.
43     * @param value the literal expression content/value.
44     */
45    public LiteralExpr(String value) {
46        _value = value;
47        _namespace = null;
48    }
49
50    /**
51     * Creates a new literal expression node.
52     * @param value the literal expression content/value.
53     * @param namespace the namespace in which the expression exists.
54     */
55    public LiteralExpr(String value, String namespace) {
56        _value = value;
57        _namespace = namespace.equals(Constants.EMPTYSTRING) ? null : namespace;
58    }
59
60    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
61        return _type = Type.String;
62    }
63
64    public String toString() {
65        return "literal-expr(" + _value + ')';
66    }
67
68    protected boolean contextDependent() {
69        return false;
70    }
71
72    protected String getValue() {
73        return _value;
74    }
75
76    protected String getNamespace() {
77        return _namespace;
78    }
79
80    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
81        final ConstantPoolGen cpg = classGen.getConstantPool();
82        final InstructionList il = methodGen.getInstructionList();
83        il.append(new PUSH(cpg, _value));
84    }
85}
86