KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > elementvalues > ArrayElementValue


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 package org.gjt.jclasslib.structures.elementvalues;
8
9 import org.gjt.jclasslib.structures.InvalidByteCodeException;
10
11 import java.io.*;
12
13 /**
14  * Describes an <tt>ArrayElementValue</tt> attribute structure.
15  *
16  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
17  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:32 $
18  */

19 public class ArrayElementValue extends ElementValue {
20
21     public final static String JavaDoc ENTRY_NAME = "ArrayElement";
22
23     private static final int INITIAL_LENGTH = 2;
24     private ElementValue[] elementValueEntries;
25
26
27     protected ArrayElementValue() {
28         super(ARRAY_TAG);
29     }
30
31     /**
32      * Get the list of element values associations of the this array
33      * element value entry.
34      *
35      * @return the array
36      */

37     public ElementValue[] getElementValueEntries() {
38         return this.elementValueEntries;
39     }
40
41     /**
42      * Set the list of element values associations of this array
43      * element value entry.
44      *
45      * @param elementValueEntries the array
46      */

47     public void setConstValueIndex(ElementValue[] elementValueEntries) {
48         this.elementValueEntries = elementValueEntries;
49     }
50
51     protected int getSpecificLength() {
52         int length = INITIAL_LENGTH;
53         for (int i = 0; i < elementValueEntries.length; i++) {
54             length += elementValueEntries[i].getLength();
55         }
56         return length;
57     }
58
59     public void read(DataInput in) throws InvalidByteCodeException, IOException {
60         super.read(in);
61
62         int elementValueEntriesLength = in.readUnsignedShort();
63         elementValueEntries = new ElementValue[elementValueEntriesLength];
64         for (int i = 0; i < elementValueEntries.length; i++) {
65             elementValueEntries[i] = ElementValue.create(in, classFile);
66         }
67
68         if (debug) debug("read ");
69     }
70
71     public void write(DataOutput out) throws InvalidByteCodeException, IOException {
72         super.write(out);
73
74         int elementValueEntriesLength = getLength(elementValueEntries);
75
76         out.writeShort(elementValueEntriesLength);
77         for (int i = 0; i < elementValueEntriesLength; i++) {
78             elementValueEntries[i].write(out);
79         }
80
81         if (debug) debug("wrote ");
82     }
83
84     protected void debug(String JavaDoc message) {
85         super.debug(message +
86                 "ArrayElementValue with " +
87                 getLength(elementValueEntries) + " entries");
88     }
89
90     public String JavaDoc getEntryName() {
91         return ENTRY_NAME;
92     }
93
94 }
95
Popular Tags