KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > compiler > LiteralExpr


1
2 /*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 /*
18  * $Id: LiteralExpr.java,v 1.8 2004/02/16 22:24:29 minchau Exp $
19  */

20
21 package org.apache.xalan.xsltc.compiler;
22
23 import org.apache.bcel.generic.ConstantPoolGen;
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.MethodGenerator;
28 import org.apache.xalan.xsltc.compiler.util.Type;
29 import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
30
31 /**
32  * @author Jacek Ambroziak
33  * @author Santiago Pericas-Geertsen
34  */

35 final class LiteralExpr extends Expression {
36     private final String JavaDoc _value;
37     private final String JavaDoc _namespace;
38
39     /**
40      * Creates a new literal expression node.
41      * @param value the literal expression content/value.
42      */

43     public LiteralExpr(String JavaDoc value) {
44     _value = value;
45     _namespace = null;
46     }
47
48     /**
49      * Creates a new literal expression node.
50      * @param value the literal expression content/value.
51      * @param namespace the namespace in which the expression exists.
52      */

53     public LiteralExpr(String JavaDoc value, String JavaDoc namespace) {
54     _value = value;
55     _namespace = namespace.equals(Constants.EMPTYSTRING) ? null : namespace;
56     }
57
58     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
59     return _type = Type.String;
60     }
61
62     public String JavaDoc toString() {
63     return "literal-expr(" + _value + ')';
64     }
65
66     protected boolean contextDependent() {
67     return false;
68     }
69
70     protected String JavaDoc getValue() {
71     return _value;
72     }
73
74     protected String JavaDoc getNamespace() {
75     return _namespace;
76     }
77
78     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
79     final ConstantPoolGen cpg = classGen.getConstantPool();
80     final InstructionList il = methodGen.getInstructionList();
81     il.append(new PUSH(cpg, _value));
82     }
83 }
84
Popular Tags