Source code: com/chaoswg/xtc4y/classdesc/ClassCPEntry.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/ClassCPEntry.java,v 1.1.1.1 2003/08/07 13:40:30 toggm Exp $
2 /******************************************************************************
3 * XTC4y - eXtreme Testing Collection 4 you *
4 * -------------------------------------------------------------------------- *
5 * URL: http://www.chaoswg.com/xtc4y *
6 * Author: Mike Toggweiler (2.dog@gmx.ch) *
7 * *
8 * Last Updated: $Date: 2003/08/07 13:40:30 $, by $Author: toggm $ *
9 * Version: $Revision: 1.1.1.1 $ *
10 * -------------------------------------------------------------------------- *
11 * COPYRIGHT: (c) 2003 by Mike Toggweiler *
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 *****************************************************************************/
18 package com.chaoswg.xtc4y.classdesc;
19
20 import java.io.DataInputStream;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 /**
25 * this class represent a Class constant pool entry
26 * @author Mike Toggweiler
27 **/
28 public final class ClassCPEntry extends ConstantPoolEntry {
29 /**
30 * The tag identifying a Class cp entry
31 **/
32 public static final byte TAG = 7;
33 private String fqn;
34 private short nameIndex;
35
36 /**
37 * Creates a new Class contantpool entry and initalizes it from a
38 * DataInputStream
39 * @param dis the DataInputStream to read from
40 **/
41 protected ClassCPEntry(DataInputStream dis)
42 throws IOException {
43 super(TAG);
44 //name_index
45 nameIndex = (short)dis.readUnsignedShort();
46 }
47
48 /**
49 * Resolve the internal stored indices thorugh the Constantpool
50 * @param cp the constantpool to resolve indices
51 **/
52 protected void resolve(ConstantPool cp) {
53 UTF8CPEntry utf = (UTF8CPEntry)cp.getCPEntryAt(nameIndex);
54 fqn = utf.getString();
55 }
56
57 /**
58 * Create a class constanpool entry with a name_index
59 * @param fqn the fqn of this class
60 **/
61 public ClassCPEntry(String fqn) {
62 super(TAG);
63 this.fqn = fqn;
64 }
65
66 /**
67 * Write the type specific constant pool entry information onto a
68 * DataOutputStream
69 * @param dos the DataOutputStream to write on
70 * @param cp the constantpool entry used to register names
71 **/
72 protected void writeCPEntry(DataOutputStream dos, ConstantPool cp)
73 throws IOException {
74 dos.writeShort(cp.addCPEntry(new UTF8CPEntry(fqn)));
75 }
76
77 /**
78 * @return the fqn
79 **/
80 public String getFQN() {
81 return fqn;
82 }
83
84 /**
85 * Checks if another ClassCPEntry is equal to this.
86 **/
87 public boolean equals(Object obj) {
88 if (!(obj instanceof ClassCPEntry)) {
89 return false;
90 }
91 ClassCPEntry other = (ClassCPEntry)obj;
92 return (this.fqn == null && other.fqn == null ||
93 this.fqn != null && this.fqn.equals(other.fqn));
94 }
95
96 /**
97 * print in a readable way
98 **/
99 public String toString() {
100 return getClass().getName()+":"+hashCode()+":"+fqn;
101 }
102 }