KickJava   Java API By Example, From Geeks To Geeks.

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


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: PointCutter.java,v 1.2 2003/07/17 13:11:08 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.filter;
28
29
30 import java.io.Serializable JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 import ch.ethz.jvmai.JoinPoint;
35 import ch.ethz.jvmai.CodeJoinPoint;
36
37 import ch.ethz.prose.engine.JoinPointRequest;
38
39 /**
40  * Class <code>PointCutter</code> is an abstract implementation of
41  * <code>PointFilter</code> which additionaly defines two operators
42  * <code>AND</code>, resp. <code>OR</code> that allow the construction
43  * of <code>PointFilter</code> objects via combination of existing
44  * specializer instances.
45  * <p>
46  * <h4> Expected Use </h4>
47  *
48  * the following construction should be legal:
49  *
50  * <blockquote><pre>
51  * PointFilter x = (new MethodEntries( ) ) .AND
52  * (new MethodNanmes("*Foo") )
53  *
54  * </pre></blockquote>
55  *
56  * Subclasses of <code>PointCutter</code> are mandated
57  * to implement a <code>toString</code> method of their own which
58  * describes in an executive way their name.
59  *
60  * @version $Revision: 1.2 $
61  * @author Andrei Popovici */
public abstract
62 class PointCutter extends CompositePointFilter implements Serializable JavaDoc {
63
64   public int acceptMask;
65   public int mayFilterStaticallyMask;
66   public int canFilterStaticallyMask;
67
68   /** Honours the contract of the <code>PointFilter</code> abstract class.
69    */

70
71
72   /**
73    * Subclasses of this class should, in conformance with the
74    * <code>PointFilter</code> abstract class, implement this method.
75    * <p>
76    * This method checks whether this PointCutter accepts the kind of
77    * requests of <code>evRec</code> (see <code>acceptMask</code>)
78    * . If it accepts such events, it
79    * calls the template method <code>doIsSpecialRequest</code> if
80    * <code>evRec</code> can be filtered statically (see <code>mayFilterStatically</code>).
81    */

82   public boolean isSpecialRequest(JoinPointRequest evRec)
83     {
84       if ( (acceptMask& evRec.getMask()) != 0)
85     {
86         // System.err.println("event is accepted:" + acceptMask);
87
if ((mayFilterStaticallyMask & evRec.getMask()) != 0)
88           {
89           return doIsSpecialRequest(evRec);
90           }
91       else
92         return true;
93     }
94       return
95     false;
96     }
97
98   /**
99    * Subclasses of this class should, in conformance with the
100    * <code>PointFilter</code> abstract class, implement this method.
101    * <p>
102    * This method checks whether this PointCutter accepts the kind of
103    * requests of <code>evRec</code> (see <code>acceptMask</code>)
104    * . If it accepts such events, it
105    * calls the template method <code>doIsSpecialRequest</code> if
106    * <code>evRec</code> can be filtered dynamically(see <code>canFilterStatically</code>).
107
108    */

109   public boolean isSpecialEvent(JoinPoint execEvent)
110     {
111
112       if ((execEvent.getMask() & acceptMask) != 0)
113     {
114       if ( (execEvent.getMask() & canFilterStaticallyMask) == 0)
115           {
116           // cannot filter statically
117
return doIsSpecialEvent((CodeJoinPoint)execEvent);
118           }
119       else
120           {
121           // we are fine the event was filtered statically
122
return true;
123           }
124     }
125       else
126       {
127           // unacceptable events are turned down
128
return false;
129       }
130     }
131
132   /** Template method, to be implemented by subclasses.
133    */

134   protected abstract boolean doIsSpecialEvent(CodeJoinPoint execEvent);
135
136   /** Template method, to be implemented by subclasses.
137    */

138   protected abstract boolean doIsSpecialRequest(JoinPointRequest req);
139
140   /** Default implementation of the <code>memberPointFilters</code> method.
141    * It returns this PointCutter.
142    */

143   public List JavaDoc memberPointFilters()
144     {
145       Vector JavaDoc result = new Vector JavaDoc();
146       result.add(this);
147       return result;
148     }
149
150   /**
151    * Return a new <code>PointCutter</code> such that:
152    *
153    * <ul>
154    * <li> An event <em>e</em> is considered special if both
155    * <code>this</code> PointCutter, as well as <code>other</code>
156    * consider <em>e</em> as special.
157    * <li> A request <em>r</em> is considered special if both
158    * <code>this</code> PointCutter, as well as <code>other</code>
159    * consider <em>r</em> as special.
160    * </ul>.
161    * This method is syntactic sugar.
162    */

163   public PointCutter AND(PointCutter other)
164       {
165     return new ANDingPointCutter(this,other);
166       }
167
168
169   /**
170    * Return a new <code>PointCutter</code> such that:
171    *
172    * <ul>
173    * <li> An event <em>e</em> is considered special if either
174    * <code>this</code> PointCutter, or <code>other</code> consider
175    * <em>e</em> as special, or both.
176    * <li> A request <em>r</em> is considered special if either
177    * <code>this</code> PointCutter, or <code>other</code> considers
178    * <em>r</em> as special, or both.
179    * </ul>.
180    * This method is syntactic sugar.
181    */

182   public PointCutter OR(PointCutter other)
183       {
184     return new ORingPointCutter(this,other);
185       }
186
187   /** This method sets the value of the String returned by <code>toString</code>.
188    */

189   String JavaDoc txt;
190   public void setToString(String JavaDoc txt)
191     {
192       this.txt = txt;
193     }
194
195   public String JavaDoc toString()
196     {
197       return txt;
198     }
199 }
200
201
202 //======================================================================
203
//
204
// $Log: PointCutter.java,v $
205
// Revision 1.2 2003/07/17 13:11:08 apopovic
206
// refactorization: from PointFilter.memberSpecializers to PointFilter.memberPointFilters;
207
// improved documentation (removed references to specializers)
208
//
209
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
210
// Imported from ETH Zurich
211
//
212
// Revision 1.4 2003/05/26 13:28:54 popovici
213
// Documentation Improvements
214
//
215
// Revision 1.3 2003/05/25 11:46:49 popovici
216
// Improved 'toString' presentation of aspects
217
//
218
// Revision 1.2 2003/05/05 17:46:56 popovici
219
// Refactorization step (runes->prose) cleanup
220
//
221
// Revision 1.1 2003/05/05 13:57:52 popovici
222
// renaming from runes to prose
223
//
224
// Revision 1.1 2003/04/27 13:08:51 popovici
225
// Specializers renamed to PointCutter
226
//
227
// Revision 1.8 2003/04/17 12:49:32 popovici
228
// Refactoring of the crosscut package
229
// ExceptionCut renamed to ThrowCut
230
// McutSignature is now SignaturePattern
231
//
232
// Revision 1.7 2003/04/17 08:47:24 popovici
233
// Important functionality additions
234
// - Cflow specializers
235
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
236
// - Transactional capabilities
237
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
238
// between static and dynamic specializers.
239
// - Functionality pulled up in abstract classes
240
// - Uniformization of advice methods patterns and names
241
//
242
// Revision 1.6 2003/03/04 18:36:28 popovici
243
// Organization of imprts
244
//
245
// Revision 1.5 2003/03/04 11:27:21 popovici
246
// Important refactorization step (march):
247
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
248
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
249
// structures
250
//
251
// Revision 1.4 2002/10/31 18:26:53 pschoch
252
// Capability of crosscutting Exceptions added to prose.
253
//
254
// Revision 1.3 2002/10/25 07:42:36 popovici
255
// Undo Chnages Phillippe
256
//
257
// Revision 1.1 2002/05/07 10:46:55 popovici
258
// Reorganization of the Specializer package. All specializer related classes
259
// moved to ch.ethz.inf.crossucut.spec; Classes ORingPointCutter, ANDspecializer and NOTspecializer is
260
// introduced, the static analysis of filtering simplified, because now specializers
261
// contain a field 'filterType' which is propagated to the root of composite specializers. junit packages updated accordingly
262
//
263
// Revision 1.4 2002/03/28 13:48:40 popovici
264
// Mozilla-ified
265
//
266
// Revision 1.3 2002/02/21 13:01:52 popovici
267
// Specializer inspection issues:
268
// - CompositeSpecialiers now allow specializer inspection - AbstractCrosscutSpecs are now composite
269
// - AbstractCrosscutSpecs define defaults for isSpecialEvent
270
// to allow inspection of subclasses (of those overrinding the
271
// defaults)
272
//
273
// Revision 1.2 2002/02/05 09:46:11 smarkwal
274
// JVMDI-specific code replaced by JVMAI. Prose-implementation classes and reflection package removed.
275
//
276
// Revision 1.1.1.1 2001/11/29 18:13:16 popovici
277
// Sources from runes
278
//
279
// Revision 1.1.2.5 2001/02/21 13:30:50 popovici
280
// - Methods 'toString' added in all inner classes that generate new specializer
281
// instances (AND,OR). The newly generated speacializers are now readable via
282
// 'toString'.
283
// - Abstract Crossscut is now serializable.
284
//
285
// Revision 1.1.2.4 2001/01/19 17:36:10 popovici
286
// Inner class 'HelpCrosscutSpecializer' removed
287
// Inner classes 'HelpCrossscutSpecializerAND' and 'HelpCrosscutSpecializerOR'
288
// added. Methods 'AND' and 'OR' reimplemented using the new HelpSpecializers.
289
// This reimplementation fixes a severe bug: a.and(b).and(c) used not to
290
// consider the 'b' specialzier.
291
//
292
// Revision 1.1.2.3 2000/11/28 17:02:22 groos
293
// minor documentation updates.
294
//
295
// Revision 1.1.2.2 2000/10/30 17:28:51 groos
296
// documentation updates
297
//
298
// Revision 1.1.2.1 2000/10/23 18:32:53 popovici
299
// Moved from ch.ethz.prose to ch.ethz.prose.crosscut;
300
// Renamed from 'PointFilter' to PointCutter;
301
// Reimplemented in order to be a real abstract class;
302
//
303
// Revision 1.1 2000/10/16 11:53:23 popovici
304
// Initial Revision
305
//
306
Popular Tags