1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 72 public final class ExceptionTable extends Attribute { 73 private int number_of_exceptions; private int[] exception_index_table; 76 80 public ExceptionTable(ExceptionTable c) { 81 this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), 82 c.getConstantPool()); 83 } 84 85 91 public ExceptionTable(int name_index, int length, 92 int[] exception_index_table, 93 ConstantPool constant_pool) 94 { 95 super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool); 96 setExceptionIndexTable(exception_index_table); 97 } 98 99 107 ExceptionTable(int name_index, int length, DataInputStream file, 108 ConstantPool constant_pool) throws IOException 109 { 110 this(name_index, length, (int[])null, constant_pool); 111 112 number_of_exceptions = file.readUnsignedShort(); 113 exception_index_table = new int[number_of_exceptions]; 114 115 for(int i=0; i < number_of_exceptions; i++) 116 exception_index_table[i] = file.readUnsignedShort(); 117 } 118 119 126 public void accept(Visitor v) { 127 v.visitExceptionTable(this); 128 } 129 130 136 public final void dump(DataOutputStream file) throws IOException 137 { 138 super.dump(file); 139 file.writeShort(number_of_exceptions); 140 for(int i=0; i < number_of_exceptions; i++) 141 file.writeShort(exception_index_table[i]); 142 } 143 144 147 public final int[] getExceptionIndexTable() {return exception_index_table;} 148 151 public final int getNumberOfExceptions() { return number_of_exceptions; } 152 153 156 public final String [] getExceptionNames() { 157 String [] names = new String [number_of_exceptions]; 158 for(int i=0; i < number_of_exceptions; i++) 159 names[i] = constant_pool.getConstantString(exception_index_table[i], 160 Constants.CONSTANT_Class). 161 replace('/', '.'); 162 return names; 163 } 164 165 169 public final void setExceptionIndexTable(int[] exception_index_table) { 170 this.exception_index_table = exception_index_table; 171 number_of_exceptions = (exception_index_table == null)? 0 : 172 exception_index_table.length; 173 } 174 177 public final String toString() { 178 StringBuffer buf = new StringBuffer (""); 179 String str; 180 181 for(int i=0; i < number_of_exceptions; i++) { 182 str = constant_pool.getConstantString(exception_index_table[i], 183 Constants.CONSTANT_Class); 184 buf.append(Utility.compactClassName(str, false)); 185 186 if(i < number_of_exceptions - 1) 187 buf.append(", "); 188 } 189 190 return buf.toString(); 191 } 192 193 196 public Attribute copy(ConstantPool constant_pool) { 197 ExceptionTable c = (ExceptionTable)clone(); 198 c.exception_index_table = (int[])exception_index_table.clone(); 199 c.constant_pool = constant_pool; 200 return c; 201 } 202 } 203 | Popular Tags |