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

ConstantClass.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 (external) class.
00010  *
00011  * @version $Id: ConstantClass.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 ConstantClass extends Constant {
00016   private int name_index; // Identical to ConstantString except for the name
00017 
00018   /**
00019    * @param name_index Name index in constant pool
00020    */
00021   public ConstantClass(int name_index) {
00022     super(Constants.CONSTANT_Class);
00023     this.name_index = name_index;
00024   }  
00025   /**
00026    * Initialize from another object.
00027    */
00028   public ConstantClass(ConstantClass c) {
00029     this(c.getNameIndex());
00030   }  
00031   /**
00032    * Initialize instance from file data.
00033    *
00034    * @param file Input stream
00035    * @throw IOException
00036    */
00037   ConstantClass(DataInputStream file) throws IOException
00038   {    
00039     this(file.readUnsignedShort());
00040   }  
00041   /**
00042    * Called by objects that are traversing the nodes of the tree implicitely
00043    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00044    * fields, attributes, etc. spawns a tree of objects.
00045    *
00046    * @param v Visitor object
00047    */
00048   public void accept(Visitor v) {
00049     v.visitConstantClass(this);
00050   }  
00051   /** 
00052    * Dump constant class to file stream in binary format.
00053    *
00054    * @param file Output file stream
00055    * @throw IOException
00056    */ 
00057   public final void dump(DataOutputStream file) throws IOException
00058   {
00059     file.writeByte(tag);
00060     file.writeShort(name_index);
00061   }  
00062   /**
00063    * @return Name index in constant pool of class name.
00064    */  
00065   public final int getNameIndex() { return name_index; }  
00066   /**
00067    * @param name_index.
00068    */
00069   public final void setNameIndex(int name_index) {
00070     this.name_index = name_index;
00071   }  
00072   /**
00073    * @return String representation.
00074    */
00075   public final String toString() {
00076     return super.toString() + "(name_index = " + name_index + ")";
00077   }  
00078 }

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