Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ConstantString.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /** 
00007  * This class is derived from the abstract 
00008  * <A HREF="de.fub.bytecode.classfile.Constant.html">Constant</A> class 
00009  * and represents a reference to a String object.
00010  *
00011  * @version $Id: ConstantString.java,v 1.1.1.1 2002/01/24 03:41:37 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     Constant
00014  */
00015 public final class ConstantString extends Constant {
00016   private int string_index; // Identical to ConstantClass except for this name
00017 
00018   /**
00019    * @param string_index Index of Constant_Utf8 in constant pool
00020    */
00021   public ConstantString(int string_index)
00022   {    
00023     super(Constants.CONSTANT_String);
00024     this.string_index = string_index;
00025   }  
00026   /**
00027    * Initialize from another object.
00028    */
00029   public ConstantString(ConstantString c) {
00030     this(c.getStringIndex());
00031   }  
00032   /** 
00033    * Initialize instance from file data.
00034    *
00035    * @param file Input stream
00036    * @throw IOException
00037    */
00038   ConstantString(DataInputStream file) throws IOException
00039   {    
00040     this((int)file.readUnsignedShort());
00041   }  
00042   /**
00043    * Called by objects that are traversing the nodes of the tree implicitely
00044    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00045    * fields, attributes, etc. spawns a tree of objects.
00046    *
00047    * @param v Visitor object
00048    */
00049   public void accept(Visitor v) {
00050     v.visitConstantString(this);
00051   }  
00052   /**
00053    * Dump constant field reference to file stream in binary format.
00054    *
00055    * @param file Output file stream
00056    * @throw IOException
00057    */ 
00058   public final void dump(DataOutputStream file) throws IOException
00059   {
00060     file.writeByte(tag);
00061     file.writeShort(string_index);
00062   }  
00063   /**
00064    * @return Index in constant pool of the string (ConstantUtf8).
00065    */  
00066   public final int getStringIndex() { return string_index; }  
00067   /**
00068    * @param string_index.
00069    */
00070   public final void setStringIndex(int string_index) {
00071     this.string_index = string_index;
00072   }  
00073   /**
00074    * @return String representation.
00075    */
00076   public final String toString()
00077   {
00078     return super.toString() + "(string_index = " + string_index + ")";
00079   }  
00080 }

Generated at Thu Feb 7 06:43:05 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001