1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 import java.io.*; 28 import java.util.Vector ; 29 import java.util.Enumeration ; 30 31 35 36 public class ExceptionsAttribute extends ClassAttribute { 37 public final static String expectedAttrName = "Exceptions"; 39 40 private Vector exceptionTable; 41 42 43 44 47 public Enumeration exceptions() { 48 return exceptionTable.elements(); 49 } 50 51 54 public ExceptionsAttribute(ConstUtf8 attrName, Vector excTable) { 55 super(attrName); 56 exceptionTable = excTable; 57 } 58 59 62 public ExceptionsAttribute(ConstUtf8 attrName, ConstClass exc) { 63 super(attrName); 64 exceptionTable = new Vector (1); 65 exceptionTable.addElement(exc); 66 } 67 68 69 70 static ExceptionsAttribute read(ConstUtf8 attrName, 71 DataInputStream data, ConstantPool pool) 72 throws IOException { 73 int nExcepts = data.readUnsignedShort(); 74 Vector excTable = new Vector (); 75 while (nExcepts-- > 0) { 76 int excIndex = data.readUnsignedShort(); 77 ConstClass exc_class = null; 78 if (excIndex != 0) 79 exc_class = (ConstClass) pool.constantAt(excIndex); 80 excTable.addElement(exc_class); 81 } 82 83 return new ExceptionsAttribute(attrName, excTable); 84 } 85 86 void write(DataOutputStream out) throws IOException { 87 out.writeShort(attrName().getIndex()); 88 out.writeInt(2+2*exceptionTable.size()); 89 out.writeShort(exceptionTable.size()); 90 for (int i=0; i<exceptionTable.size(); i++) 91 out.writeShort(((ConstClass) exceptionTable.elementAt(i)).getIndex()); 92 } 93 94 void print(PrintStream out, int indent) { 95 ClassPrint.spaces(out, indent); 96 out.print("Exceptions:"); for (int i=0; i<exceptionTable.size(); i++) 98 out.print(" " + ((ConstClass) exceptionTable.elementAt(i)).asString()); out.println(); 100 } 101 102 } 103 104 | Popular Tags |