KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 package ch.ethz.prose.filter;
28 import java.util.Collection JavaDoc;
29
30 // used packages
31

32 /**
33  * Class Target is a <em>dynamic</em> filter. A target is the object
34  * receiving a method call or the owner of a field being read or writen.
35  *
36  *
37  * @version $Revision: 1.2 $
38  * @author Andrei Popovici
39  */

40 public
41 class Target
42 {
43
44  /** Return a <code>PointCutter</code> that allows advice executions
45    * only for 'this' object that are contained in the specified
46    * collection. Note that according to the java.util.Collection interface,
47    * the comparison <code>this.equalsTo(oneOfTheObjectsInCol)</code>
48    * must return <code>true</code>
49    */

50   public static PointCutter inCollection(Collection JavaDoc col)
51     {
52       PointCutter t = new ObjectInCollectionFilter(ObjectFilter.TARGET_ARGS_OBJECT,col);
53       t.setToString("This.inCollection()");
54       return t;
55     }
56
57   /** Return a PointCutter that allows executions only at join-points where
58    * the 'target' object is equal to <code>obj</code>.
59    */

60   public static PointCutter equalsTo(Object JavaDoc obj)
61     {
62       PointCutter t =new ObjectEqualsToFilter(ObjectFilter.TARGET_ARGS_OBJECT,obj);
63       t.setToString("Target.equalsTo(" + obj.toString() + ")");
64       return t;
65     }
66
67   /** Return a <code>PointCutter</code> that allows executions at join-points
68    * where <code>target==obj</code>.
69    */

70   public static PointCutter isSameObject(Object JavaDoc obj)
71     {
72       PointCutter t =new ObjectIdenticalToFilter(ObjectFilter.TARGET_ARGS_OBJECT,obj);
73       t.setToString("Target.isSameObject(" + obj + ")");
74       return t;
75     }
76
77  /** Return a <code>PointCutter</code> that allows executions at join-points
78    * where <code>target instanceof cls</code>.
79    */

80   public static PointCutter subtypeOf(Class JavaDoc cls)
81     {
82       PointCutter t =new ObjectTypeFilter(ObjectFilter.TARGET_ARGS_OBJECT,cls,ObjectTypeFilter.SUBCLASS_INHERITANCE);
83       t.setToString("Target.subtypeOf(" + cls.getName() + ")");
84       return t;
85     }
86
87   /** Return a <code>PointCutter</code> that allows executions at join-points
88    * where <code>cls is a subclass/subinterface of target.getClass</code>
89    */

90   public static PointCutter supertypeOf(Class JavaDoc cls)
91     {
92       PointCutter t = new ObjectTypeFilter(ObjectFilter.THIS_OBJECT,cls,ObjectTypeFilter.SUPERCLASS_INHERITANCE);
93       t.setToString("Target.superTypeOf(" + cls.getName() + ")");
94       return t;
95     }
96
97  /** Return a <code>PointCutter</code> that allows executions at join-points
98    * with <em>target.class equals cls</em>.
99    */

100   public static PointCutter type(Class JavaDoc cls)
101     {
102       PointCutter t = new ObjectTypeFilter(ObjectFilter.THIS_OBJECT,cls,ObjectTypeFilter.NO_INHERITANCE);
103        t.setToString("Target.type(" + cls.getName() + ")");
104        return t;
105     }
106
107   /* Return a <code>PointCutter</code> that allows executions at join-points
108    * where the <em>unqualified</em> class name of the taget matches
109    * the regexp <code>classRegexp</code>
110    */

111   public static PointCutter type(String JavaDoc classRegexp)
112     {
113       PointCutter t = new ObjectInClassNameFilter(ObjectFilter.TARGET_ARGS_OBJECT,classRegexp);
114       t.setToString("Target.type(" + classRegexp+ ")");
115       return t;
116     }
117
118  /** Return a PointCutter that allows execution at join-points
119    * where the pacakge name of <code>target.class</code> matches
120    * the regular expression <code>packageRegexp</code>.
121    */

122   public static PointCutter inPackage(String JavaDoc packageRegexp)
123     {
124       PointCutter t = new ObjectInPackageFilter(ObjectFilter.TARGET_ARGS_OBJECT,packageRegexp);
125       t.setToString("Target.inPackage(" + packageRegexp + ")");
126       return t;
127     }
128
129
130 }
131 //======================================================================
132
//
133
// $Log: Target.java,v $
134
// Revision 1.2 2003/07/17 11:14:17 apopovic
135
// Added inCollection PointCutter. Improved Documentation
136
//
137
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
138
// Imported from ETH Zurich
139
//
140
// Revision 1.3 2003/05/25 11:46:49 popovici
141
// Improved 'toString' presentation of aspects
142
//
143
// Revision 1.2 2003/05/06 15:51:44 popovici
144
// Mozilla-ification
145
//
146
// Revision 1.1 2003/05/05 13:58:05 popovici
147
// renaming from runes to prose
148
//
149
// Revision 1.3 2003/04/27 13:08:52 popovici
150
// Specializers renamed to PointCutter
151
//
152
// Revision 1.2 2003/04/26 14:33:48 popovici
153
// subtypeOf, supertypeOf specializers addde to this and target
154
//
155
// Revision 1.1 2003/04/17 14:46:03 popovici
156
// ThiS renamed to This; additional method renamings
157
//
158
// Revision 1.8 2003/04/17 13:59:37 popovici
159
// This class and methods renamed
160
//
161
// Revision 1.7 2003/04/17 12:49:32 popovici
162
// Refactoring of the crosscut package
163
// ExceptionCut renamed to ThrowCut
164
// McutSignature is now SignaturePattern
165
//
166
// Revision 1.6 2003/04/17 08:47:53 popovici
167
// Important functionality additions
168
// - Cflow specializers
169
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
170
// - Transactional capabilities
171
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
172
// between static and dynamic specializers.
173
// - Functionality pulled up in abstract classes
174
// - Uniformization of advice methods patterns and names
175
//
176
// Revision 1.5 2003/03/04 18:24:15 popovici
177
// Refactoring of the specializer. De-obfuscation
178
// by exposing the inner classes of the factory methods
179
// The specializer implementations now end in 'filter',
180
// whereas the old factory methods 'xxxS' remain
181
// pure bootstrap objects.
182
//
183
// Revision 1.4 2003/03/04 11:27:24 popovici
184
// Important refactorization step (march):
185
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
186
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
187
// structures
188
//
189
// Revision 1.3 2002/10/25 07:42:36 popovici
190
// Undo Chnages Phillippe
191
//
192
// Revision 1.1 2002/05/16 09:18:31 popovici
193
// ClasseS and CFlow replaced with Target, This; the crosscut spec package is refactorized. Now all
194
// crosscuts are grouped (abstract definitions + concrete definitions). Crosscuts explicitely are dynamic and static, and
195
// or/Not/And combinations can be created.
196
//
197
Popular Tags