1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.*;
21 import java.util.Vector;
22 import java.util.Enumeration;
23
24 /***
25 * Represents the LocalVariableTable attribute within a
26 * method in a class file.
27 */
28 public class LocalVariableTableAttribute extends ClassAttribute {
29
30 public static final String expectedAttrName = "LocalVariableTable";
31
32
33 private Vector localTable;
34
35
36
37 /***
38 * Returns an enumeration of the local variables in the table
39 * Each element is a LocalVariable
40 */
41 Enumeration variables() {
42 return localTable.elements();
43 }
44
45 /***
46 * Constructor for a local variable table
47 */
48 public LocalVariableTableAttribute(
49 ConstUtf8 nameAttr, Vector lvarTable) {
50 super(nameAttr);
51 localTable = lvarTable;
52 }
53
54 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
55
56 static LocalVariableTableAttribute read(
57 ConstUtf8 attrName, DataInputStream data, CodeEnv env)
58 throws IOException {
59 int nVars = data.readUnsignedShort();
60 Vector lvarTable = new Vector();
61 while (nVars-- > 0) {
62 lvarTable.addElement(LocalVariable.read(data, env));
63 }
64
65 return new LocalVariableTableAttribute(attrName, lvarTable);
66 }
67
68 void write(DataOutputStream out) throws IOException {
69 out.writeShort(attrName().getIndex());
70 ByteArrayOutputStream baos = new ByteArrayOutputStream();
71 DataOutputStream tmp_out = new DataOutputStream(baos);
72 tmp_out.writeShort(localTable.size());
73 for (int i=0; i<localTable.size(); i++)
74 ((LocalVariable) localTable.elementAt(i)).write(tmp_out);
75
76 tmp_out.flush();
77 byte tmp_bytes[] = baos.toByteArray();
78 out.writeInt(tmp_bytes.length);
79 out.write(tmp_bytes, 0, tmp_bytes.length);
80 }
81
82 void print(PrintStream out, int indent) {
83 ClassPrint.spaces(out, indent);
84 out.println("LocalVariables: ");
85 for (int i=0; i<localTable.size(); i++) {
86 ((LocalVariable) localTable.elementAt(i)).print(out, indent+2);
87 }
88 }
89 }
90