KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > filter > ExceptionTypeFilter


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: ExceptionTypeFilter.java,v 1.2 2004/05/12 09:41:55 anicoara Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.filter;
28
29 // used packages
30
import java.util.*;
31 import java.io.*;
32 import ch.ethz.jvmai.JoinPointKinds;
33 import ch.ethz.jvmai.JoinPoint;
34 import ch.ethz.jvmai.CodeJoinPoint;
35 import ch.ethz.prose.engine.ExceptionThrowRequest;
36 import ch.ethz.prose.engine.ExceptionCatchRequest;
37 import ch.ethz.prose.engine.JoinPointRequest;
38
39
40 /**
41  * Class FieldsInTypeFilter XXX
42  *
43  * @version $Revision: 1.2 $
44  * @author Andrei Popovici
45  * @author Angela Nicoara
46  */

47 public
48 class ExceptionTypeFilter extends PointCutter implements JoinPointKinds{
49
50   public final static int SUBCLASS_INHERITANCE = 1;
51   public final static int SUPERCLASS_INHERITANCE = 2;
52   public final static int NO_INHERITANCE = 3;
53
54   private int inheritanceType;
55   private Class JavaDoc subOrSuperClass;
56   /**
57    * XXX
58    * @param XXX XXX
59    */

60   public ExceptionTypeFilter(Class JavaDoc cls, int inhType)
61   {
62     this.inheritanceType = inhType;
63     this.subOrSuperClass = cls;
64
65     acceptMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP;
66     mayFilterStaticallyMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP;
67     canFilterStaticallyMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP;
68   }
69
70
71   protected boolean doIsSpecialRequest(JoinPointRequest jpr)
72     {
73       Class JavaDoc declaringClass;
74
75       switch (jpr.getMask() & (MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP))
76       {
77           case MASK_EXCEPTION_THROW_ARGS_JP:
78                 declaringClass = ((ExceptionThrowRequest)jpr).getExceptionClass();
79                 break;
80           case MASK_EXCEPTION_CATCH_ARGS_JP:
81                 declaringClass = ((ExceptionCatchRequest)jpr).getExceptionClass();
82                 break;
83           default:
84                 throw new Error JavaDoc("ExceptionTypeFilter.doIsSpecialRequest: unrequested request");
85       }
86
87
88       switch(inheritanceType)
89     {
90       case SUBCLASS_INHERITANCE:
91         return subOrSuperClass.isAssignableFrom(declaringClass);
92
93       case SUPERCLASS_INHERITANCE: return declaringClass.isAssignableFrom(subOrSuperClass);
94       case NO_INHERITANCE: return subOrSuperClass.equals(declaringClass);
95       default:
96         throw new Error JavaDoc("Illegal state Exception");
97     }
98     }
99
100   protected boolean doIsSpecialEvent(CodeJoinPoint jpr)
101     {
102       throw new Error JavaDoc("PointCutter did not fullfil its contract");
103     }
104
105
106
107 }
108
109
110 //======================================================================
111
//
112
// $Log: ExceptionTypeFilter.java,v $
113
// Revision 1.2 2004/05/12 09:41:55 anicoara
114
// Remove the README.RVM file
115
//
116
// Revision 1.1.1.1 2003/07/02 15:30:51 apopovic
117
// Imported from ETH Zurich
118
//
119
// Revision 1.3 2003/07/02 12:42:55 anicoara
120
// Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
121
//
122
// Revision 1.2 2003/05/06 15:51:35 popovici
123
// Mozilla-ification
124
//
125
// Revision 1.1 2003/05/05 13:57:45 popovici
126
// renaming from runes to prose
127
//
128
// Revision 1.3 2003/04/27 13:08:46 popovici
129
// Specializers renamed to PointCutter
130
//
131
// Revision 1.2 2003/04/17 12:49:35 popovici
132
// Refactoring of the crosscut package
133
// ExceptionCut renamed to ThrowCut
134
// McutSignature is now SignaturePattern
135
//
136
// Revision 1.1 2003/04/17 08:47:36 popovici
137
// Important functionality additions
138
// - Cflow specializers
139
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
140
// - Transactional capabilities
141
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
142
// between static and dynamic specializers.
143
// - Functionality pulled up in abstract classes
144
// - Uniformization of advice methods patterns and names
145
//
146
Popular Tags