KickJava   Java API By Example, From Geeks To Geeks.

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


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: ExecutionsInClassFilter.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.jvmai.ClassSpecific;
36 import ch.ethz.prose.engine.JoinPointRequest;
37
38 /**
39  * Class ExecutionsInClassFilter XXX
40  *
41  * @version $Revision: 1.2 $
42  * @author Andrei Popovici
43  * @author Angela Nicoara
44  */

45 public
46 class ExecutionsInClassFilter extends PointCutter implements JoinPointKinds
47 {
48   final public static int MATCH_CLASS_NAME_OPMODE = 1;
49   final public static int MATCH_PACKAGE_NAME_OPMODE = 2;
50   final public static int MATCH_QCLASS_NAME_OPMODE = 3;
51   private NameExpression regexp;
52   private int operationMode;
53
54   /** Create a <code>DeclarationS</code> object which allows joinpoints
55    * withing code executed inside classes whose name match <code>regexp</code>.
56    *
57    * @param regexp the regular expresion to match. The syntax of this expression
58    * conforms to the Perl 5 regular expressions.
59    * @exception IllegalArgumentException (runtimeException) thrown if
60    * the regexp is not correctly formatted or opMode is not one
61    * of the <code>MATCH_XXX_OPMODE constantns</code>
62    */

63   public ExecutionsInClassFilter(String JavaDoc regexp, int opMode)
64   {
65     if (opMode != MATCH_CLASS_NAME_OPMODE &&
66     opMode != MATCH_PACKAGE_NAME_OPMODE &&
67     opMode != MATCH_QCLASS_NAME_OPMODE)
68       throw new IllegalArgumentException JavaDoc("Illegal opMode value");
69     this.regexp = new NameExpression(regexp);
70     acceptMask = MASK_ALL_JP;
71     operationMode = opMode;
72     mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
73     canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
74   }
75
76   /** This method is executed if and only if the 'mayFilterStatically'
77    * and the current request match.
78    *
79    */

80     protected boolean doIsSpecialRequest(JoinPointRequest jpr)
81     {
82         try
83         {
84             //System.err.println("ExecutionsInClassFilter - doIsSpecialRequest -> checking whether " + ((ClassSpecific)jpr).getTargetClass() + " matches " + regexp); //angy test
85
Class JavaDoc targetClass;
86             boolean result;
87             targetClass = ((ClassSpecific)jpr).getTargetClass();
88             switch(operationMode)
89             {
90                 case MATCH_CLASS_NAME_OPMODE:
91                       result = regexp.classMatchesRegexp(targetClass);
92                       break;
93                 case MATCH_QCLASS_NAME_OPMODE:
94                       result = regexp.qualifiedClassMatchesRegexp(targetClass);
95                       break;
96                 case MATCH_PACKAGE_NAME_OPMODE:
97                       result = regexp.packageMatchesRegexp(targetClass);
98                       break;
99                 default: throw new Error JavaDoc("the opmode is illegal!");
100             }
101             //System.err.println("ExecutionsInClassFilter - doIsSpecialRequest ->>" + result); //angy test
102
return result;
103         }
104         catch (ClassCastException JavaDoc jprWasNotClassSpecific)
105         {
106             throw new Error JavaDoc("request was allowed in spite of mayFilterStaticallyMask");
107         }
108     }
109     
110     
111   /** The abstract crosscut mechanism ensures that this method
112    * is called only for NON-METHOD-ENTRY and NON-METHOD-EXIT events
113    *
114    */

115     protected boolean doIsSpecialEvent(CodeJoinPoint jp)
116     {
117         //System.err.println("ExecutionsInClassFilter - doIsSpecialRequest -> checking whether " + jp.getMethod().getDeclaringClass() + " matches " + regexp); //angy test
118
boolean result;
119         Class JavaDoc classDeclaringExecutedCode = jp.getMethod().getDeclaringClass();
120         switch (operationMode)
121         {
122             case MATCH_CLASS_NAME_OPMODE:
123                   result = regexp.classMatchesRegexp(classDeclaringExecutedCode);
124                   break;
125             case MATCH_QCLASS_NAME_OPMODE:
126                   result = regexp.qualifiedClassMatchesRegexp(classDeclaringExecutedCode);
127                   break;
128             case MATCH_PACKAGE_NAME_OPMODE:
129                   result = regexp.packageMatchesRegexp(classDeclaringExecutedCode);
130                   break;
131             default: throw new Error JavaDoc("the opmode is illegal!");
132         }
133         //System.err.println("ExecutionsInClassFilter - doIsSpecialRequest ->>" + result); //angy test
134
return result;
135     }
136
137 }
138
139
140 //======================================================================
141
//
142
// $Log: ExecutionsInClassFilter.java,v $
143
// Revision 1.2 2004/05/12 09:41:55 anicoara
144
// Remove the README.RVM file
145
//
146
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
147
// Imported from ETH Zurich
148
//
149
// Revision 1.5 2003/07/02 12:42:56 anicoara
150
// Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
151
//
152
// Revision 1.4 2003/05/25 11:46:48 popovici
153
// Improved 'toString' presentation of aspects
154
//
155
// Revision 1.3 2003/05/06 15:51:37 popovici
156
// Mozilla-ification
157
//
158
// Revision 1.2 2003/05/05 17:46:55 popovici
159
// Refactorization step (runes->prose) cleanup
160
//
161
// Revision 1.1 2003/05/05 13:57:49 popovici
162
// renaming from runes to prose
163
//
164
// Revision 1.3 2003/04/27 13:08:46 popovici
165
// Specializers renamed to PointCutter
166
//
167
// Revision 1.2 2003/04/17 12:49:32 popovici
168
// Refactoring of the crosscut package
169
// ExceptionCut renamed to ThrowCut
170
// McutSignature is now SignaturePattern
171
//
172
// Revision 1.1 2003/04/17 08:47:42 popovici
173
// Important functionality additions
174
// - Cflow specializers
175
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
176
// - Transactional capabilities
177
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
178
// between static and dynamic specializers.
179
// - Functionality pulled up in abstract classes
180
// - Uniformization of advice methods patterns and names
181
//
182
Popular Tags