001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developers of the Original Code are Angela Nicoara and Gerald Linhofer.
017: // All Rights Reserved.
018: //
019: // Contributor(s):
020: // $Id$
021: // =====================================================================
022: //
023: // (history at end)
024: //
025:
026: package ch.ethz.prose.engine;
027:
028: // used packages
029: import ch.ethz.jvmai.JoinPointKinds;
030:
031: /**
032: * Class ExceptionCatchRequest is a special kind of
033: * <code>JoinPointRequest</code> which, when inserted into a
034: * <code>JoinPointManager</code> will make the local virtual
035: * machine to stop when it encounters an exception object beeing catch
036: * denoted by this request. A corresponding
037: * <code>ExceptionCatchEvent</code> will be posted to the listeners
038: * registered in the join point manager.
039: *
040: * @version $Revision: 1.2 $
041: * @author Angela Nicoara
042: */
043: public class ExceptionCatchRequest extends JoinPointRequest implements
044: JoinPointKinds {
045:
046: private final Class exceptionClass;
047:
048: /**
049: * Constructor.
050: * @param cls Class of the Catch Exception.
051: * @param o Reference to the JoinPointManager to set and clear jvmai-watches.
052: */
053: public ExceptionCatchRequest(Class cls, JoinPointManager o)
054: throws ClassCastException {
055: super (o);
056:
057: try {
058: if (!(Class.forName("java.lang.Throwable")
059: .isAssignableFrom(cls)))
060: throw new ClassCastException(
061: "ClassCastException: Class must be of subtype 'Throwable'");
062: } catch (ClassNotFoundException e) {
063: System.err.println(e);
064: e.printStackTrace();
065: }
066:
067: exceptionClass = cls;
068: }
069:
070: public int getMask() {
071: return MASK_EXCEPTION_CATCH_ARGS_JP;
072: }
073:
074: public String getKind() {
075: return KIND_EXCEPTION_CATCH_ARGS_JP;
076: }
077:
078: public Class getExceptionClass() {
079: return exceptionClass;
080: }
081:
082: protected void setWatch(Object listeners) {
083: owner.getAspectInterface().setExceptionCatchWatch(
084: exceptionClass, listeners);
085: }
086:
087: protected void clearWatch() {
088: owner.getAspectInterface().clearExceptionCatchWatch(
089: exceptionClass);
090: }
091:
092: public boolean equals(Object other) {
093: ExceptionCatchRequest otherReq;
094: if (other instanceof ExceptionCatchRequest)
095: otherReq = (ExceptionCatchRequest) other;
096: else
097: return false;
098: return exceptionClass.equals(otherReq.getExceptionClass());
099: }
100:
101: public int hashCode() {
102: return exceptionClass.hashCode();
103: }
104:
105: public String toString() {
106: return "ExceptionCatchRequest on Class "
107: + exceptionClass.getName();
108: }
109:
110: }
111:
112: //======================================================================
113: //
114: // $Log$
115: //
|