KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > engine > ExceptionCatchRequest


1
2 package ch.ethz.prose.engine;
3
4 // used packages
5
import ch.ethz.jvmai.JVMAspectInterface;
6 import ch.ethz.jvmai.JoinPointKinds;
7
8
9 /**
10  * Class ExceptionCatchRequest is a special kind of
11  * <code>JoinPointRequest</code> which, when inserted into a
12  * <code>JoinPointManager</code> will make the local virtual
13  * machine to stop when it encounters an exception object beeing catch
14  * denoted by this request. A corresponding
15  * <code>ExceptionCatchEvent</code> will be posted to the listeners
16  * registered in the join point manager.
17  * @version $Revision: 1.2 $
18  * @author Angela Nicoara
19  */

20 public
21 class ExceptionCatchRequest extends JoinPointRequest implements JoinPointKinds {
22
23   private final Class JavaDoc exceptionClass;
24
25   /**
26    * Constructor.
27    * @param exceptionClass Class of the Catch Exception.
28    * @param ai Reference to the aspect-interface to set and clear jvmai-watches.
29    * @param ii Reference to the info-interface to query additional information from
30    * the jvmai-system.
31    */

32   public ExceptionCatchRequest(Class JavaDoc cls, JoinPointManager o)
33     throws ClassCastException JavaDoc
34   {
35     super(o);
36
37     try {
38             if (!(Class.forName("java.lang.Throwable").isAssignableFrom(cls)))
39                 throw new ClassCastException JavaDoc("ClassCastException: Class must be of subtype 'Throwable'");
40     }
41     catch (ClassNotFoundException JavaDoc e)
42         {
43         System.err.println(e);
44         e.printStackTrace();
45     }
46
47     exceptionClass = cls;
48   }
49
50   public int getMask()
51   {
52       return MASK_EXCEPTION_CATCH_ARGS_JP;
53   }
54
55   public String JavaDoc getKind()
56   {
57   return KIND_EXCEPTION_CATCH_ARGS_JP;
58   }
59
60   public Class JavaDoc getExceptionClass()
61   {
62       return exceptionClass;
63   }
64
65   protected void setWatch(Object JavaDoc listeners)
66   {
67       owner.getAspectInterface().setExceptionCatchWatch(exceptionClass, listeners);
68   }
69
70   protected void clearWatch()
71   {
72       owner.getAspectInterface().clearExceptionCatchWatch(exceptionClass);
73   }
74
75   public boolean equals(Object JavaDoc other)
76   {
77       ExceptionCatchRequest otherReq;
78       if (other instanceof ExceptionCatchRequest)
79             otherReq = (ExceptionCatchRequest)other;
80       else
81             return false;
82       return exceptionClass.equals(otherReq.getExceptionClass());
83   }
84
85   public int hashCode()
86   {
87       return exceptionClass.hashCode();
88   }
89
90   public String JavaDoc toString()
91   {
92       return "ExceptionCatchRequest on Class " + exceptionClass.getName();
93   }
94
95 }
96
Popular Tags