1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter.classfile;
11
12 import java.io.DataInput;
13 import java.io.IOException;
14
15 /***
16 * A ConstantString <br>
17 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
18 * University of Technology </a>, the Netherlands. <br>
19 * See for project information <a
20 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22 * License (GPL) </a>, no warranty <br>
23 *
24 * @version 1.0 Jan 9, 2004 <br>
25 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
26 * Jacobs </a>
27 */
28 public class ConstantString extends Constant
29 {
30 /*** gets the name index */
31 private int stringIndex;
32
33 /***
34 * constructs a new ConstantString
35 *
36 * @param constantPool the constantPool it is part of
37 * @param inputStream the inputstream to read from
38 * @throws IOException on failure
39 */
40 public ConstantString(final Constant[] constantPool,
41 final DataInput inputStream) throws IOException
42 {
43 this(constantPool, inputStream.readUnsignedShort());
44 }
45
46 /***
47 * constructs a new ConstantString
48 *
49 * @param constantPool the constantPool it is part of
50 * @param stringIndex the stringIndex
51 */
52 public ConstantString(final Constant[] constantPool, final int stringIndex)
53 {
54 super(constantPool);
55 this.stringIndex = stringIndex;
56 }
57
58 /***
59 * @see nl.tudelft.simulation.dsol.interpreter.classfile.Constant#getTag()
60 */
61 public int getTag()
62 {
63 return 8;
64 }
65
66 /***
67 * returns the name index
68 *
69 * @return stringIndex
70 */
71 public int getStringIndex()
72 {
73 return this.stringIndex;
74 }
75
76 /***
77 * returns the className of this constant
78 *
79 * @return String the className
80 */
81 public String getValue()
82 {
83 return ((ConstantUTF8) super.constantPool[this.stringIndex]).getValue();
84 }
85
86 /***
87 * @see java.lang.Object#toString()
88 */
89 public String toString()
90 {
91 return "ConstantString[index=" + this.stringIndex + "]";
92 }
93 }