KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > javaguard > classfile > InnerClassesInfo


1 /**
2  * JavaGuard -- an obfuscation package for Java classfiles.
3  *
4  * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * The author may be contacted at theit@gmx.de.
22  *
23  *
24  * $Id: InnerClassesInfo.java,v 1.3 2002/05/11 22:48:15 glurk Exp $
25  */

26 package net.sf.javaguard.classfile;
27
28 import java.io.*;
29
30
31 /** Representation of an inner class table entry.
32  *
33  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
34  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
35  */

36 public class InnerClassesInfo {
37   /** The index of the inner class info. */
38   private int innerClassInfoIndex;
39   /** The index of the outer class info. */
40   private int outerClassInfoIndex;
41   /** The index of the inner name. */
42   private int innerNameIndex;
43   /** The inner class access flags. */
44   private int innerClassAccessFlags;
45   
46   
47   
48   
49   /** Creates a new InnerClassesInfo object from the given input stream.
50    * @param din the input stream
51    * @return the InnerClassesInfo object created from the input stream
52    * @throws IOException if an I/O error occurs
53    */

54   public static InnerClassesInfo create(DataInput din)
55   throws IOException {
56     InnerClassesInfo ici = new InnerClassesInfo();
57     ici.read(din);
58     return ici;
59   }
60   
61   
62   
63   
64   /** Private constructor that creates a new InnerClassesInfo object.
65    */

66   private InnerClassesInfo() {
67   }
68   
69   
70   
71   
72   /** Sets the index of the inner class info.
73    * @param index the index of the inner class info
74    * @see #getInnerClassInfoIndex
75    */

76   protected void setInnerClassInfoIndex(int index) {
77     innerClassInfoIndex = index;
78   }
79   
80   
81   /** Returns the index of the inner class info.
82    * @return index of the inner class info
83    * @see #setInnerClassInfoIndex
84    */

85   protected int getInnerClassInfoIndex() {
86     return innerClassInfoIndex;
87   }
88   
89   
90   
91   
92   /** Sets the index of the outer class info.
93    * @param index the index of the outer class info
94    * @see #getOuterClassInfoIndex
95    */

96   protected void setOuterClassInfoIndex(int index) {
97     outerClassInfoIndex = index;
98   }
99   
100   
101   /** Returns the index of the outer class info.
102    * @return index of the outer class info
103    * @see #setOuterClassInfoIndex
104    */

105   protected int getOuterClassInfoIndex() {
106     return outerClassInfoIndex;
107   }
108   
109   
110   
111   
112   /** Sets the index of the inner name.
113    * @param index the index of the inner name
114    * @see #getInnerNameIndex
115    */

116   protected void setInnerNameIndex(int index) {
117     innerNameIndex = index;
118   }
119   
120   
121   /** Returns the index of the inner name.
122    * @return index of the inner name
123    * @see #setInnerNameIndex
124    */

125   protected int getInnerNameIndex() {
126     return innerNameIndex;
127   }
128   
129   
130   
131   
132   /** Sets the inner class access flags.
133    * @param flags the inner class access flags
134    * @see #getInnerClassAccessFlags
135    */

136   protected void setInnerClassAccessFlags(int flags) {
137     innerClassAccessFlags = flags;
138   }
139   
140   
141   /** Returns the inner class access flags.
142    * @return the inner class access flags
143    * @see #setInnerClassAccessFlags
144    */

145   protected int getInnerClassAccessFlags() {
146     return innerClassAccessFlags;
147   }
148   
149   
150   
151   
152   /** Check for Utf8 references to constant pool and mark them.
153    * @param pool the constant pool the element belongs to
154    */

155   protected void markUtf8Refs(ConstantPool pool) {
156     // BUGFIX: a Swing1.1beta3 class has name index of zero - this is valid
157
if (0 != getInnerNameIndex()) {
158       pool.incRefCount(getInnerNameIndex());
159     }
160   }
161   
162   
163   
164   
165   /** Read the data following the header.
166    * @param din the input stream
167    * @throws IOException if an I/O error occurs
168    */

169   private void read(DataInput din)
170   throws IOException {
171     setInnerClassInfoIndex(din.readUnsignedShort());
172     setOuterClassInfoIndex(din.readUnsignedShort());
173     setInnerNameIndex(din.readUnsignedShort());
174     setInnerClassAccessFlags(din.readUnsignedShort());
175   }
176   
177   
178   /** Export data following the header to a DataOutput stream. Should be
179    * overwritten in subclasses.
180    * @param dout the output stream
181    * @throws IOException if an I/O error occurs
182    */

183   public void write(DataOutput dout)
184   throws IOException {
185     dout.writeShort(getInnerClassInfoIndex());
186     dout.writeShort(getOuterClassInfoIndex());
187     dout.writeShort(getInnerNameIndex());
188     dout.writeShort(getInnerClassAccessFlags());
189   }
190   
191   
192   
193   
194   /** Dump the content of the entry to the specified file (used for debugging).
195    * @param pw the print writer
196    * @param cf the class file the element belongs to
197    */

198   public void dump(PrintWriter pw, ClassFile cf) {
199     pw.print("Inner class info index: ");
200     pw.print(getInnerClassInfoIndex());
201     pw.print(" -> ");
202     pw.println(cf.toName(getInnerClassInfoIndex()));
203     pw.print("Outer class info index: ");
204     pw.print(getOuterClassInfoIndex());
205     pw.print(" -> ");
206     if (getOuterClassInfoIndex() > 0) {
207       pw.println(cf.toName(getOuterClassInfoIndex()));
208     } else {
209       pw.println("<null>");
210     }
211     pw.print("Inner name index: ");
212     pw.print(getInnerNameIndex());
213     pw.print(" -> ");
214     if (getInnerNameIndex() > 0) {
215       pw.println( ((Utf8CpInfo) cf.getCpEntry(getInnerNameIndex())).getString());
216     } else {
217       pw.println("<null>");
218     }
219     pw.print("Inner class access flags: ");
220     pw.println(getInnerClassAccessFlags());
221   }
222 }
223
Popular Tags