Source code: com/chaoswg/xtc4y/classdesc/InnerClassesAttribute.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/CodeAttribute.java,v 1.3 2003/08/26 12:46:53 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/26 12:46:53 $, by $Author: toggm $ *
9 * Version: $Revision: 1.3 $ *
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.util.Vector;
21
22 import java.io.DataInputStream;
23 import java.io.DataOutputStream;
24 import java.io.IOException;
25
26 import com.chaoswg.xtc4y.classdesc.code.Code;
27
28 /**
29 * This class describes the innerclass attribute
30 * @author Mike Toggweiler
31 **/
32 public class InnerClassesAttribute extends Attribute {
33
34 private Vector innerClassInfos;
35
36 public static final String NAME = "InnerClasses";
37
38 /**
39 * Creates a CodeAttribute and initializes it from a DataInputStream
40 * The attribute name and length
41 * of the attribute information was already read.
42 * @param dis the DataInputStream to read from
43 * @param cp the constant pool to resolve indices
44 * @param length the length of the attribute information provided
45 * on the DataInputStream
46 **/
47 protected InnerClassesAttribute(DataInputStream dis, ConstantPool cp,
48 int length)
49 throws IOException {
50 super(dis, cp, length);
51
52 if (!getName().equals(NAME)) {
53 throw new ClassFormatError("Attribute name does not match");
54 }
55
56 innerClassInfos = new Vector();
57 int infoLength = dis.readUnsignedShort();
58 for (int i=0; i<infoLength; ++i) {
59 innerClassInfos.add(new InnerClassInfo(dis, cp));
60 }
61 }
62
63 /**
64 * Construct a new code attribute with default values except the code
65 * part. The exceptions and attributes are initializes to be empty
66 * @param code the instructions as code
67 **/
68 public InnerClassesAttribute() {
69 innerClassInfos = new Vector();
70 }
71
72 /**
73 * Write the attribute information onto the DataOutputStream, using the
74 * constant pool to register variables. The Attribute name and the
75 * length of the information will already be written. A specific
76 * attribute implementation should overwrite this method.
77 * @param dos the DataOutputStream to write on
78 * @param cp The constant pool to register variables
79 **/
80 protected void writeAttribute(DataOutputStream dos, ConstantPool cp)
81 throws IOException {
82
83 dos.writeShort(innerClassInfos.size());
84 for (int i=0; i<innerClassInfos.size(); ++i) {
85 ((InnerClassInfo)innerClassInfos.elementAt(i)).write(dos, cp);
86 }
87 }
88
89 /**
90 * Add a innerclassinfo to the inner class
91 * @param info the innerclass info to add
92 **/
93 public void addInnerClassInfo(InnerClassInfo info) {
94 innerClassInfos.add(info);
95 }
96
97 /**
98 * Remove a innerclassinfo
99 * @param info the innerclass info to remove
100 **/
101 public void removeInnerClassInfo(InnerClassInfo info) {
102 innerClassInfos.remove(info);
103 }
104
105 /**
106 * clear the innerclass info
107 **/
108 public void clearInnerClassInfo() {
109 innerClassInfos.clear();
110 }
111
112 /**
113 * @return an array of innerclassinfos
114 **/
115 public InnerClassInfo[] getInnerClassInfos() {
116 return (InnerClassInfo[])
117 innerClassInfos.toArray(new
118 InnerClassInfo[innerClassInfos.size()]);
119 }
120
121 /**
122 * @return the name of the attribute
123 **/
124 public String getName() {
125 return NAME;
126 }
127 }