KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > InnerClassesAttribute


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.attributes;
9
10 import org.gjt.jclasslib.structures.AttributeInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Describes an <tt>InnerClasses</tt> attribute structure.
17
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.4 $ $Date: 2003/08/18 07:52:05 $
20 */

21 public class InnerClassesAttribute extends AttributeInfo {
22
23     /** Name of the attribute as in the corresponding constant pool entry. */
24     public static final String JavaDoc ATTRIBUTE_NAME = "InnerClasses";
25
26     private static final int INITIAL_LENGTH = 2;
27     
28     private InnerClassesEntry[] classes;
29     
30     /**
31         Get the list of inner classes of the parent <tt>ClassFile</tt> structure
32         as an array of <tt>InnerClassesEntry</tt> structures.
33         @return the array
34      */

35       public InnerClassesEntry[] getClasses() {
36         return classes;
37     }
38
39     /**
40         Set the list of inner classes of the parent <tt>ClassFile</tt> structure
41         as an array of <tt>InnerClassesEntry</tt> structures.
42         @param classes the array
43      */

44     public void setClasses(InnerClassesEntry[] classes) {
45         this.classes = classes;
46     }
47     
48     public void read(DataInput in)
49         throws InvalidByteCodeException, IOException {
50             
51         int numberOfClasses = in.readUnsignedShort();
52         classes = new InnerClassesEntry[numberOfClasses];
53         
54         for (int i = 0; i < numberOfClasses; i++) {
55             classes[i] = InnerClassesEntry.create(in, classFile);
56         }
57
58         if (debug) debug("read ");
59     }
60
61     public void write(DataOutput out)
62         throws InvalidByteCodeException, IOException {
63         
64         super.write(out);
65
66         int numberOfClasses = getLength(classes);
67         
68         out.writeShort(numberOfClasses);
69         for (int i = 0 ; i < numberOfClasses; i++) {
70             classes[i].write(out);
71         }
72         if (debug) debug("wrote ");
73     }
74
75     public int getAttributeLength() {
76         return INITIAL_LENGTH + getLength(classes) * InnerClassesEntry.LENGTH;
77     }
78
79     protected void debug(String JavaDoc message) {
80         super.debug(message + "InnerClasses attribute with " + getLength(classes) + " classes");
81     }
82
83 }
84
Popular Tags