01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.satsa.jcrmic.classfile.attributes;
28:
29: import java.io.DataInputStream;
30: import java.io.IOException;
31: import java.io.PrintWriter;
32:
33: import com.sun.satsa.jcrmic.classfile.constants.JConstantPool;
34:
35: /**
36: * This class represents Exceptions attribute in the method_info structure.
37: * The Exception attribute indicates which checked exceptions a method
38: * may throw
39: */
40:
41: public class JExceptionsAttr extends JAttribute {
42:
43: /**
44: * Indexes of exception class names.
45: */
46: private int[] index_table;
47:
48: /**
49: * Exception class names.
50: */
51: private String[] exceptions;
52:
53: /**
54: * Returns exception class names.
55: * @return exception class names
56: */
57: public String[] getExceptions() {
58: return exceptions;
59: }
60:
61: /**
62: * Constructor.
63: * @param cp constant pool reference.
64: */
65: public JExceptionsAttr(JConstantPool cp) {
66: super (cp);
67: }
68:
69: /**
70: * Parses the attribute definition.
71: * @param input input stream
72: * @throws IOException if I/O exception occurs
73: */
74: public void parse(DataInputStream input) throws IOException {
75:
76: int length = input.readInt();
77: index_table = new int[input.readUnsignedShort()];
78: for (int i = 0; i < index_table.length; i++) {
79: index_table[i] = input.readUnsignedShort();
80: }
81: }
82:
83: /**
84: * Resolves the attribute.
85: */
86: public void resolve() {
87: exceptions = new String[index_table.length];
88: for (int i = 0; i < index_table.length; i++) {
89: exceptions[i] = cp.getConstantClass(index_table[i])
90: .getClassName();
91: }
92: }
93: }
|