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