00001 package de.fub.bytecode.classfile;
00002
00003 import de.fub.bytecode.Constants;
00004 import java.io.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 public final class ExceptionTable extends Attribute {
00017 private int number_of_exceptions;
00018 private int[] exception_index_table;
00019
00020
00021
00022
00023
00024
00025
00026 public ExceptionTable(int name_index, int length,
00027 int[] exception_index_table,
00028 ConstantPool constant_pool)
00029 {
00030 super(ATTR_EXCEPTIONS, name_index, length, constant_pool);
00031 setExceptionIndexTable(exception_index_table);
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041 ExceptionTable(int name_index, int length, DataInputStream file,
00042 ConstantPool constant_pool) throws IOException
00043 {
00044 this(name_index, length, (int[])null, constant_pool);
00045
00046 number_of_exceptions = file.readUnsignedShort();
00047 exception_index_table = new int[number_of_exceptions];
00048
00049 for(int i=0; i < number_of_exceptions; i++)
00050 exception_index_table[i] = file.readUnsignedShort();
00051 }
00052
00053
00054
00055
00056 public ExceptionTable(ExceptionTable c) {
00057 this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(),
00058 c.getConstantPool());
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 public void accept(Visitor v) {
00068 v.visitExceptionTable(this);
00069 }
00070
00071
00072
00073 public Attribute copy(ConstantPool constant_pool) {
00074 ExceptionTable c = (ExceptionTable)clone();
00075 c.exception_index_table = (int[])exception_index_table.clone();
00076 c.constant_pool = constant_pool;
00077 return c;
00078 }
00079
00080
00081
00082
00083
00084
00085 public final void dump(DataOutputStream file) throws IOException
00086 {
00087 super.dump(file);
00088 file.writeShort(number_of_exceptions);
00089 for(int i=0; i < number_of_exceptions; i++)
00090 file.writeShort(exception_index_table[i]);
00091 }
00092
00093
00094
00095 public final int[] getExceptionIndexTable() {return exception_index_table;}
00096
00097
00098
00099 public final String[] getExceptionNames() {
00100 String[] names = new String[number_of_exceptions];
00101 for(int i=0; i < number_of_exceptions; i++)
00102 names[i] = constant_pool.getConstantString(exception_index_table[i], CONSTANT_Class).
00103 replace('/', '.');
00104 return names;
00105 }
00106
00107
00108
00109 public final int getNumberOfExceptions() { return number_of_exceptions; }
00110
00111
00112
00113
00114 public final void setExceptionIndexTable(int[] exception_index_table) {
00115 this.exception_index_table = exception_index_table;
00116 number_of_exceptions = (exception_index_table == null)? 0 :
00117 exception_index_table.length;
00118 }
00119
00120
00121
00122 public final String toString() {
00123 StringBuffer buf = new StringBuffer("");
00124 String str;
00125
00126 for(int i=0; i < number_of_exceptions; i++) {
00127 str = constant_pool.getConstantString(exception_index_table[i],
00128 CONSTANT_Class);
00129 buf.append(Utility.compactClassName(str));
00130
00131 if(i < number_of_exceptions - 1)
00132 buf.append(", ");
00133 }
00134
00135 return buf.toString();
00136 }
00137 }