1 28 29 package com.caucho.bytecode; 30 31 import com.caucho.log.Log; 32 import com.caucho.vfs.TempBuffer; 33 import com.caucho.vfs.TempStream; 34 import com.caucho.vfs.WriteStream; 35 36 import java.io.IOException ; 37 import java.util.ArrayList ; 38 import java.util.logging.Logger ; 39 40 43 public class ExceptionsAttribute extends Attribute { 44 static private final Logger log = Log.open(ExceptionsAttribute.class); 45 46 private ArrayList <String > _exceptions = new ArrayList <String >(); 47 48 ExceptionsAttribute(String name) 49 { 50 super(name); 51 } 52 53 56 public void addException(String exn) 57 { 58 _exceptions.add(exn); 59 } 60 61 64 public ArrayList <String > getExceptionList() 65 { 66 return _exceptions; 67 } 68 69 72 public void read(ByteCodeParser in) 73 throws IOException 74 { 75 int length = in.readInt(); 76 77 int exnCount = in.readShort(); 78 79 for (int i = 0; i < exnCount; i++) { 80 int index = in.readShort(); 81 82 if (index == 0) 83 _exceptions.add(null); 84 85 _exceptions.add(in.getConstantPool().getClass(index).getName()); 86 } 87 } 88 89 92 public void write(ByteCodeWriter out) 93 throws IOException 94 { 95 out.writeUTF8Const(getName()); 96 97 TempStream ts = new TempStream(); 98 ts.openWrite(); 99 WriteStream ws = new WriteStream(ts); 100 ByteCodeWriter o2 = new ByteCodeWriter(ws, out.getJavaClass()); 101 102 o2.writeShort(_exceptions.size()); 103 for (int i = 0; i < _exceptions.size(); i++) { 104 String exn = _exceptions.get(i); 105 106 o2.writeClass(exn); 107 } 108 109 ws.close(); 110 111 out.writeInt(ts.getLength()); 112 113 TempBuffer ptr = ts.getHead(); 114 115 for (; ptr != null; ptr = ptr.getNext()) 116 out.write(ptr.getBuffer(), 0, ptr.getLength()); 117 118 ts.destroy(); 119 } 120 121 124 public Attribute export(JavaClass cl, JavaClass target) 125 { 126 ConstantPool cp = target.getConstantPool(); 127 128 cp.addUTF8(getName()); 129 130 ExceptionsAttribute attr = new ExceptionsAttribute(getName()); 131 132 for (int i = 0; i < _exceptions.size(); i++) { 133 String exn = _exceptions.get(i); 134 135 cp.addClass(exn); 136 137 attr.addException(exn); 138 } 139 140 return attr; 141 } 142 143 public String toString() 144 { 145 return "ExceptionsAttribute[" + getName() + "]"; 146 } 147 } 148 | Popular Tags |