KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > DefaultAspect


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: DefaultAspect.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose;
28
29 // used packages
30
import java.lang.reflect.Field JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Vector JavaDoc;
35
36 import ch.ethz.prose.crosscut.Crosscut;
37 import ch.ethz.inf.util.Logger;
38
39
40 /**
41  * Class DefaultAspect provides a declarative way to define
42  * an extension. For example, the following code
43  * <blockquote><pre>
44  * class MyExtension extends DefaultAspect
45  * {
46  * Crosscut c1 = new MethodCut()
47  * {
48  * public void METHOD_ARGS(ANY thisO,REST params) {}
49  * }
50  * Crosscut c2 = new MethodCut{}
51  * {
52  * public void adviceMethod(Object thisO, Object[] parms){}
53  * }.specializeWith( ( MethodS.BEFORE1) .AND
54  * ( MethodS.named("Foo")) );
55  *
56  * }
57  *
58  * </pre></blockquote>
59  * would produce an extension which returns a list of two crosscuts
60  * <code>c1</code> and <code>c2</code>.
61  *
62  *
63  * @version $Revision: 1.1.1.1 $
64  * @author Andrei Popovici
65  */

66 public abstract
67 class DefaultAspect extends Aspect {
68
69
70
71
72     protected Crosscut[] crosscuts()
73     {
74     Vector JavaDoc theCrosscuts = null;
75     try
76         {
77         theCrosscuts = new Vector JavaDoc();
78         Field JavaDoc[] declFields = getClass().getDeclaredFields();
79         for (int i=0; i < declFields.length; i++)
80             {
81             if ( Crosscut.class.isAssignableFrom(declFields[i].getType()) &&
82                  (declFields[i].get(this) != null)
83                  )
84                 theCrosscuts.add(declFields[i].get(this));
85             }
86         }
87     catch (IllegalAccessException JavaDoc probablyPrivate)
88         {
89         Logger.error("Probably private definition:",probablyPrivate);
90         throw new IllegalAspectException(" Probably private crosscut definitions:" + probablyPrivate.toString());
91         }
92
93     return (Crosscut[])(theCrosscuts.toArray(new Crosscut[]{}));
94     }
95
96
97
98
99
100
101 }
102
103
104 //======================================================================
105
//
106
// $Log: DefaultAspect.java,v $
107
// Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
108
// Imported from ETH Zurich
109
//
110
// Revision 1.2 2003/05/26 13:28:49 popovici
111
// Documentation Improvements
112
//
113
// Revision 1.1 2003/05/05 13:58:31 popovici
114
// renaming from runes to prose
115
//
116
// Revision 1.4 2003/04/29 12:41:04 popovici
117
// Feature added:
118
// - the 'setPriority' in class insertable allows now Aspects and Crosscuts to have a priority.
119
// Notitification is done from low int priorities to high int priorities.
120
// - the 'setAspectID' introduced to replace constuctor; used to be cumberstone for subclasses
121
//
122
// Revision 1.3 2003/04/27 13:21:32 popovici
123
// Aspects now have identities. Equality is based
124
// either on an ad-hoc identity, or on a specific
125
// name given by the user
126
//
127
// Revision 1.2 2003/04/17 15:43:45 popovici
128
// crosscuts renamed to 'getCrosscuts'
129
// createCrosscuts renamed to 'crosscuts'
130
//
131
// Revision 1.1 2003/04/17 15:15:12 popovici
132
// Extension->Aspect renaming
133
//
134
// Revision 1.8 2003/04/17 13:54:35 popovici
135
// Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
136
// Method names refer now to 'types'
137
//
138
// Revision 1.7 2003/04/17 12:49:41 popovici
139
// Refactoring of the crosscut package
140
// ExceptionCut renamed to ThrowCut
141
// McutSignature is now SignaturePattern
142
//
143
// Revision 1.6 2003/04/17 08:47:12 popovici
144
// Important functionality additions
145
// - Cflow specializers
146
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
147
// - Transactional capabilities
148
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
149
// between static and dynamic specializers.
150
// - Functionality pulled up in abstract classes
151
// - Uniformization of advice methods patterns and names
152
//
153
// Revision 1.5 2003/03/04 18:36:37 popovici
154
// Organization of imprts
155
//
156
// Revision 1.4 2002/06/07 15:30:49 popovici
157
// Documentation updates of FunctionalCrosscut/ClasseS refactorings
158
//
159
// Revision 1.3 2002/03/28 13:48:33 popovici
160
// Mozilla-ified
161
//
162
// Revision 1.2 2002/02/05 10:17:22 smarkwal
163
// JVMDI-specific code replaced by JVMAI. Implementation-classes and reflection-package removed.
164
//
165
// Revision 1.1.1.1 2001/11/29 18:13:14 popovici
166
// Sources from runes
167
//
168
// Revision 1.1.2.7 2001/06/01 11:29:04 popovici
169
// Generation of birthdaykookie changed, in order to avoid collsions of
170
// extensions created one after the other. A sequence number is now
171
// included in the cookie.
172
//
173
// Revision 1.1.2.6 2001/02/21 16:43:46 popovici
174
// Methods 'equals' and 'hashCode' added.
175
//
176
// Revision 1.1.2.5 2001/02/21 13:24:25 popovici
177
// Logging messages added.
178
//
179
// Revision 1.1.2.4 2001/02/15 10:21:55 popovici
180
// The mapping threads to maps is now transient.
181
//
182
// Revision 1.1.2.3 2001/02/07 11:46:31 popovici
183
// Void method 'insertionAction' and 'withdrawalAction' added.
184
//
185
// Revision 1.1.2.2 2000/11/13 19:00:20 popovici
186
// More explicit IllegalExtension exception
187
//
188
// Revision 1.1.2.1 2000/10/24 17:47:59 popovici
189
// Initial Revision
190
//
191
Popular Tags