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.Stack;
23 import java.util.Vector;
24 import java.util.Enumeration;
25
26 /***
27 * ExceptionTable represents the exception handlers within the code
28 * of a method.
29 */
30 public class ExceptionTable {
31
32
33 private Vector handlers = new Vector();
34
35
36
37 /***
38 * Return an enumeration of the exception handlers
39 * Each element in the enumeration is an ExceptionRange
40 */
41 public Enumeration handlers() {
42 return handlers.elements();
43 }
44
45 /***
46 * Add an exception handler to the list
47 */
48 public void addElement(ExceptionRange range) {
49 handlers.addElement(range);
50 }
51
52 public ExceptionTable() { }
53
54 /***
55 * Compares this instance with another for structural equality.
56 */
57
58 public boolean isEqual(Stack msg, Object obj) {
59 if (!(obj instanceof ExceptionTable)) {
60 msg.push("obj/obj.getClass() = "
61 + (obj == null ? null : obj.getClass()));
62 msg.push("this.getClass() = "
63 + this.getClass());
64 return false;
65 }
66 ExceptionTable other = (ExceptionTable)obj;
67
68 if (this.handlers.size() != other.handlers.size()) {
69 msg.push("handlers.size() "
70 + String.valueOf(other.handlers.size()));
71 msg.push("handlers.size() "
72 + String.valueOf(this.handlers.size()));
73 return false;
74 }
75
76 for (int i = 0; i < handlers.size(); i++) {
77 ClassAttribute h1 = (ClassAttribute)this.handlers.get(i);
78 ClassAttribute h2 = (ClassAttribute)other.handlers.get(i);
79 if (!h1.isEqual(msg, h2)) {
80 msg.push("handlers[" + i + "] = "
81 + String.valueOf(h2));
82 msg.push("handlers[" + i + "] = "
83 + String.valueOf(h1));
84 return false;
85 }
86 }
87 return true;
88 }
89
90 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
91
92 static ExceptionTable read(DataInputStream data, CodeEnv env)
93 throws IOException {
94 ExceptionTable excTable = new ExceptionTable();
95 int nExcepts = data.readUnsignedShort();
96 while (nExcepts-- > 0) {
97 excTable.addElement(ExceptionRange.read(data, env));
98 }
99 return excTable;
100 }
101
102 void write(DataOutputStream out) throws IOException {
103 out.writeShort(handlers.size());
104 for (int i=0; i<handlers.size(); i++)
105 ((ExceptionRange) handlers.elementAt(i)).write(out);
106 }
107
108 void print(PrintStream out, int indent) {
109 ClassPrint.spaces(out, indent);
110 out.println("Exception Table: ");
111 for (int i=0; i<handlers.size(); i++)
112 ((ExceptionRange) handlers.elementAt(i)).print(out, indent+2);
113 }
114 }