1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 36 public final class ExceptionTable extends Attribute { 37 38 private int number_of_exceptions; private int[] exception_index_table; 41 42 46 public ExceptionTable(ExceptionTable c) { 47 this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), c.getConstantPool()); 48 } 49 50 51 57 public ExceptionTable(int name_index, int length, int[] exception_index_table, 58 ConstantPool constant_pool) { 59 super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool); 60 setExceptionIndexTable(exception_index_table); 61 } 62 63 64 72 ExceptionTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) 73 throws IOException { 74 this(name_index, length, (int[]) null, constant_pool); 75 number_of_exceptions = file.readUnsignedShort(); 76 exception_index_table = new int[number_of_exceptions]; 77 for (int i = 0; i < number_of_exceptions; i++) { 78 exception_index_table[i] = file.readUnsignedShort(); 79 } 80 } 81 82 83 90 public void accept( Visitor v ) { 91 v.visitExceptionTable(this); 92 } 93 94 95 101 public final void dump( DataOutputStream file ) throws IOException { 102 super.dump(file); 103 file.writeShort(number_of_exceptions); 104 for (int i = 0; i < number_of_exceptions; i++) { 105 file.writeShort(exception_index_table[i]); 106 } 107 } 108 109 110 113 public final int[] getExceptionIndexTable() { 114 return exception_index_table; 115 } 116 117 118 121 public final int getNumberOfExceptions() { 122 return number_of_exceptions; 123 } 124 125 126 129 public final String [] getExceptionNames() { 130 String [] names = new String [number_of_exceptions]; 131 for (int i = 0; i < number_of_exceptions; i++) { 132 names[i] = constant_pool.getConstantString(exception_index_table[i], 133 Constants.CONSTANT_Class).replace('/', '.'); 134 } 135 return names; 136 } 137 138 139 143 public final void setExceptionIndexTable( int[] exception_index_table ) { 144 this.exception_index_table = exception_index_table; 145 number_of_exceptions = (exception_index_table == null) ? 0 : exception_index_table.length; 146 } 147 148 149 152 public final String toString() { 153 StringBuffer buf = new StringBuffer (""); 154 String str; 155 for (int i = 0; i < number_of_exceptions; i++) { 156 str = constant_pool.getConstantString(exception_index_table[i], 157 Constants.CONSTANT_Class); 158 buf.append(Utility.compactClassName(str, false)); 159 if (i < number_of_exceptions - 1) { 160 buf.append(", "); 161 } 162 } 163 return buf.toString(); 164 } 165 166 167 170 public Attribute copy( ConstantPool _constant_pool ) { 171 ExceptionTable c = (ExceptionTable) clone(); 172 if (exception_index_table != null) { 173 c.exception_index_table = new int[exception_index_table.length]; 174 System.arraycopy(exception_index_table, 0, c.exception_index_table, 0, 175 exception_index_table.length); 176 } 177 c.constant_pool = _constant_pool; 178 return c; 179 } 180 } 181 | Popular Tags |