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
22package com.sun.org.apache.xalan.internal.xsltc.compiler;
23
24import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
25import com.sun.org.apache.bcel.internal.generic.InstructionList;
26import com.sun.org.apache.bcel.internal.generic.PUSH;
27import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
28import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
29import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
30import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
31
32/**
33 * @author Jacek Ambroziak
34 * @author Santiago Pericas-Geertsen
35 */
36final class SimpleAttributeValue extends AttributeValue {
37
38    private String _value; // The attributes value (literate string).
39
40    /**
41     * Creates a new simple attribute value.
42     * @param value the attribute value.
43     */
44    public SimpleAttributeValue(String value) {
45        _value = value;
46    }
47
48    /**
49     * Returns this attribute value's type (String).
50     * @param stable The compiler/parser's symbol table
51     */
52    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
53        return _type = Type.String;
54    }
55
56    public String toString() {
57        return _value;
58    }
59
60    protected boolean contextDependent() {
61        return false;
62    }
63
64    /**
65     * Translate this attribute value into JVM bytecodes that pushes the
66     * attribute value onto the JVM's stack.
67     * @param classGen BCEL Java class generator
68     * @param methodGen BCEL Java method generator
69     */
70    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
71        final ConstantPoolGen cpg = classGen.getConstantPool();
72        final InstructionList il = methodGen.getInstructionList();
73        il.append(new PUSH(cpg, _value));
74    }
75}
76