KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > ExceptAttr


1 /**
2  * This attribute is associated with a method, and indicates
3  * the set of exceptions (as classCP items) that can be thrown
4  * by the method.
5  *
6  * @author $Author: fqian $
7  * @version $Revision: 1.1 $
8  */

9
10 package jas;
11
12 import java.io.*;
13 import java.util.*;
14
15 public class ExceptAttr
16 {
17   static CP attr = new AsciiCP("Exceptions");
18
19   Vector cps;
20
21   public ExceptAttr() { cps = new Vector(); }
22   /**
23    * @param clazz Exception class to be added to attribute. This is
24    * typically a ClassCP
25    */

26   public void addException(CP cp)
27   { cps.addElement(cp); }
28
29   void resolve(ClassEnv e)
30   {
31     e.addCPItem(attr);
32     for (Enumeration en = cps.elements(); en.hasMoreElements();)
33       { e.addCPItem((CP)(en.nextElement())); }
34   }
35
36   void write(ClassEnv e, DataOutputStream out)
37     throws IOException, jasError
38   {
39     out.writeShort(e.getCPIndex(attr));
40     out.writeInt(cps.size()*2 + 2);
41     out.writeShort(cps.size());
42     for (Enumeration en = cps.elements(); en.hasMoreElements();)
43       { out.writeShort(e.getCPIndex((CP)(en.nextElement()))); }
44   }
45 }
46
Popular Tags