KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > constants > ConstantClassInfo


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.constants;
9
10 import org.gjt.jclasslib.structures.CPInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Describes a <tt>CONSTANT_Class_info</tt> constant pool data structure.
17  
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.5 $ $Date: 2003/08/18 07:51:44 $
20 */

21 public class ConstantClassInfo extends CPInfo {
22
23     /** Length of the constant pool data structure in bytes. */
24     public static final int SIZE = 2;
25     
26     private int nameIndex;
27     
28     public byte getTag() {
29         return CONSTANT_CLASS;
30     }
31
32     public String JavaDoc getTagVerbose() {
33         return CONSTANT_CLASS_VERBOSE;
34     }
35     
36     public String JavaDoc getVerbose() throws InvalidByteCodeException {
37         return getName();
38     }
39     
40     /**
41         Get the index of the constant pool entry containing the name of the class.
42         @return the index
43      */

44     public int getNameIndex() {
45         return nameIndex;
46     }
47
48     /**
49         Set the index of the constant pool entry containing the name of the class.
50         @param nameIndex the index
51      */

52     public void setNameIndex(int nameIndex) {
53         this.nameIndex = nameIndex;
54     }
55     
56     /**
57         Get the name of the class.
58         @return the tag
59         @throws InvalidByteCodeException if the byte code is invalid
60      */

61     public String JavaDoc getName() throws InvalidByteCodeException {
62         return classFile.getConstantPoolUtf8Entry(nameIndex).getString();
63     }
64
65     public void read(DataInput in)
66         throws InvalidByteCodeException, IOException {
67             
68         nameIndex = in.readUnsignedShort();
69         if (debug) debug("read ");
70     }
71
72     public void write(DataOutput out)
73         throws InvalidByteCodeException, IOException {
74         
75         out.writeByte(CONSTANT_CLASS);
76         out.writeShort(nameIndex);
77         if (debug) debug("wrote ");
78     }
79     
80     public boolean equals(Object JavaDoc object) {
81         if (!(object instanceof ConstantClassInfo)) {
82             return false;
83         }
84         ConstantClassInfo constantClassInfo = (ConstantClassInfo)object;
85         return super.equals(object) && constantClassInfo.nameIndex == nameIndex;
86     }
87
88     public int hashCode() {
89         return super.hashCode() ^ nameIndex;
90     }
91     
92     protected void debug(String JavaDoc message) {
93         super.debug(message + getTagVerbose() + " with name_index " + nameIndex);
94     }
95     
96 }
97
Popular Tags