View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   
6   /*
7    * Copyright 2001-2004 The Apache Software Foundation.
8    *
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * 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   * $Id: LiteralExpr.java,v 1.2.4.1 2005/09/01 15:58:53 pvedula Exp $
23   */
24  
25  package com.sun.org.apache.xalan.internal.xsltc.compiler;
26  
27  import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
28  import com.sun.org.apache.bcel.internal.generic.InstructionList;
29  import com.sun.org.apache.bcel.internal.generic.PUSH;
30  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
31  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
32  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
33  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
34  
35  /**
36   * @author Jacek Ambroziak
37   * @author Santiago Pericas-Geertsen
38   */
39  final class LiteralExpr extends Expression {
40      private final String _value;
41      private final String _namespace;
42  
43      /**
44       * Creates a new literal expression node.
45       * @param value the literal expression content/value.
46       */
47      public LiteralExpr(String value) {
48          _value = value;
49          _namespace = null;
50      }
51  
52      /**
53       * Creates a new literal expression node.
54       * @param value the literal expression content/value.
55       * @param namespace the namespace in which the expression exists.
56       */
57      public LiteralExpr(String value, String namespace) {
58          _value = value;
59          _namespace = namespace.equals(Constants.EMPTYSTRING) ? null : namespace;
60      }
61  
62      public Type typeCheck(SymbolTable stable) throws TypeCheckError {
63          return _type = Type.String;
64      }
65  
66      public String toString() {
67          return "literal-expr(" + _value + ')';
68      }
69  
70      protected boolean contextDependent() {
71          return false;
72      }
73  
74      protected String getValue() {
75          return _value;
76      }
77  
78      protected String getNamespace() {
79          return _namespace;
80      }
81  
82      public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
83          final ConstantPoolGen cpg = classGen.getConstantPool();
84          final InstructionList il = methodGen.getInstructionList();
85          il.append(new PUSH(cpg, _value));
86      }
87  }