KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > definition > AspectDefinition


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.definition;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.codehaus.aspectwerkz.reflect.ClassInfo;
17 import org.codehaus.aspectwerkz.DeploymentModel;
18 import org.codehaus.aspectwerkz.DeploymentModel;
19 import org.codehaus.aspectwerkz.aspect.DefaultAspectContainerStrategy;
20
21 /**
22  * Holds the meta-data for the aspect.
23  *
24  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
25  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
26  */

27 public class AspectDefinition {
28
29     private final static String JavaDoc DEFAULT_ASPECTCONTAINER_CLASSNAME = DefaultAspectContainerStrategy.class.getName();
30
31     /**
32      * The default aspectwerkz aspect model type id.
33      */

34     public static final String JavaDoc ASPECTWERKZ_ASPECT_MODEL_TYPE = "aspectwerkz";
35
36     /**
37      * The name of the aspect (nickname).
38      */

39     private String JavaDoc m_name;
40
41     /**
42      * The nickname of the aspect prefixed by the <system uuid>/
43      */

44     private String JavaDoc m_qualifiedName;
45
46     /**
47      * The aspect class info.
48      */

49     private final ClassInfo m_classInfo;
50
51     /**
52      * The deployment model for the aspect.
53      */

54     private DeploymentModel m_deploymentModel = DeploymentModel.PER_JVM;
55
56     /**
57      * The around advices.
58      */

59     private final List JavaDoc m_aroundAdviceDefinitions = new ArrayList JavaDoc();
60
61     /**
62      * The before advices.
63      */

64     private final List JavaDoc m_beforeAdviceDefinitions = new ArrayList JavaDoc();
65
66     /**
67      * The after advices.
68      */

69     private final List JavaDoc m_afterAdviceDefinitions = new ArrayList JavaDoc();
70
71     /**
72      * The interface introductions (pure interfaces)
73      */

74     private final List JavaDoc m_interfaceIntroductionDefinitions = new ArrayList JavaDoc();
75
76     /**
77      * The pointcuts.
78      */

79     private final List JavaDoc m_pointcutDefinitions = new ArrayList JavaDoc();
80
81     /**
82      * The parameters passed to the aspect at definition time.
83      */

84     private Map JavaDoc m_parameters = new HashMap JavaDoc();
85
86     /**
87      * The container implementation class name.
88      */

89     private String JavaDoc m_containerClassName;
90
91     /**
92      * The system definition.
93      */

94     private SystemDefinition m_systemDefinition;
95
96     /**
97      * The aspect model.
98      */

99     private String JavaDoc m_aspectModelType = ASPECTWERKZ_ASPECT_MODEL_TYPE;
100
101     /**
102      * Creates a new aspect meta-data instance.
103      *
104      * @param name the name of the aspect
105      * @param classInfo the class info for the aspect
106      * @param systemDefinition
107      */

108     public AspectDefinition(final String JavaDoc name, final ClassInfo classInfo, final SystemDefinition systemDefinition) {
109         if (name == null) {
110             throw new IllegalArgumentException JavaDoc("aspect name can not be null");
111         }
112         if (classInfo == null) {
113             throw new IllegalArgumentException JavaDoc("aspect class info can not be null");
114         }
115         m_name = name;
116         m_classInfo = classInfo;
117         m_systemDefinition = systemDefinition;
118         m_qualifiedName = systemDefinition.getUuid() + '/' + name;
119
120         // default container
121
setContainerClassName(DEFAULT_ASPECTCONTAINER_CLASSNAME);
122     }
123
124     /**
125      * Returns the name for the advice
126      *
127      * @return the name
128      */

129     public String JavaDoc getName() {
130         return m_name;
131     }
132
133     /**
134      * Sets the name for the aspect.
135      *
136      * @param name the name
137      */

138     public void setName(final String JavaDoc name) {
139         m_name = name.trim();
140     }
141
142     /**
143      * Returns the fully qualified name for the advice
144      *
145      * @return the fully qualified name
146      */

147     public String JavaDoc getQualifiedName() {
148         return m_qualifiedName;
149     }
150
151     /**
152      * Returns the system definition.
153      *
154      * @return
155      */

156     public SystemDefinition getSystemDefinition() {
157         return m_systemDefinition;
158     }
159
160     /**
161      * Returns the class name.
162      *
163      * @return the class name
164      */

165     public String JavaDoc getClassName() {
166         return m_classInfo.getName();
167     }
168
169     /**
170      * Returns the class info.
171      *
172      * @return the class info
173      */

174     public ClassInfo getClassInfo() {
175         return m_classInfo;
176     }
177
178     /**
179      * Returns the aspect model.
180      *
181      * @return the aspect model
182      */

183     public String JavaDoc getAspectModel() {
184         return m_aspectModelType;
185     }
186
187     /**
188      * Checks if the aspect defined is an AspectWerkz aspect.
189      *
190      * @return
191      */

192     public boolean isAspectWerkzAspect() {
193         return m_aspectModelType.equals(ASPECTWERKZ_ASPECT_MODEL_TYPE);
194     }
195
196     /**
197      * Sets the aspect model.
198      *
199      * @param aspectModelType the aspect model
200      */

201     public void setAspectModel(final String JavaDoc aspectModelType) {
202         m_aspectModelType = aspectModelType;
203     }
204
205     /**
206      * Sets the deployment model.
207      *
208      * @param deploymentModel the deployment model
209      */

210     public void setDeploymentModel(final DeploymentModel deploymentModel) {
211         m_deploymentModel = deploymentModel;
212     }
213
214     /**
215      * Returns the deployment model.
216      *
217      * @return the deployment model
218      */

219     public DeploymentModel getDeploymentModel() {
220         return m_deploymentModel;
221     }
222
223     /**
224      * Adds a new around advice.
225      *
226      * @param adviceDef the around advice
227      */

228     public void addAroundAdviceDefinition(final AdviceDefinition adviceDef) {
229         if (!m_aroundAdviceDefinitions.contains(adviceDef)) {
230             m_aroundAdviceDefinitions.add(adviceDef);
231         }
232     }
233
234     /**
235      * Returns the around advices.
236      *
237      * @return the around advices
238      */

239     public List JavaDoc getAroundAdviceDefinitions() {
240         return m_aroundAdviceDefinitions;
241     }
242
243     /**
244      * Adds a new before advice.
245      *
246      * @param adviceDef the before advice
247      */

248     public void addBeforeAdviceDefinition(final AdviceDefinition adviceDef) {
249         if (!m_beforeAdviceDefinitions.contains(adviceDef)) {
250             m_beforeAdviceDefinitions.add(adviceDef);
251         }
252     }
253
254     /**
255      * Returns the before advices.
256      *
257      * @return the before advices
258      */

259     public List JavaDoc getBeforeAdviceDefinitions() {
260         return m_beforeAdviceDefinitions;
261     }
262
263     /**
264      * Adds a new after advice.
265      *
266      * @param adviceDef the after advice
267      */

268     public void addAfterAdviceDefinition(final AdviceDefinition adviceDef) {
269         if (!m_afterAdviceDefinitions.contains(adviceDef)) {
270             m_afterAdviceDefinitions.add(adviceDef);
271         }
272     }
273
274     /**
275      * Returns the after advices.
276      *
277      * @return the after advices
278      */

279     public List JavaDoc getAfterAdviceDefinitions() {
280         return m_afterAdviceDefinitions;
281     }
282
283     /**
284      * Adds a new pure interface introduction.
285      *
286      * @param interfaceIntroDef the introduction
287      */

288     public void addInterfaceIntroductionDefinition(final InterfaceIntroductionDefinition interfaceIntroDef) {
289         m_interfaceIntroductionDefinitions.add(interfaceIntroDef);
290     }
291
292     /**
293      * Returns the interface introductions.
294      *
295      * @return the introductions
296      */

297     public List JavaDoc getInterfaceIntroductionDefinitions() {
298         return m_interfaceIntroductionDefinitions;
299     }
300
301     /**
302      * Adds a new pointcut definition.
303      *
304      * @param pointcutDef the pointcut definition
305      */

306     public void addPointcutDefinition(final PointcutDefinition pointcutDef) {
307         m_pointcutDefinitions.add(pointcutDef);
308     }
309
310     /**
311      * Returns the pointcuts.
312      *
313      * @return the pointcuts
314      */

315     public Collection JavaDoc getPointcutDefinitions() {
316         return m_pointcutDefinitions;
317     }
318
319     /**
320      * Adds a new parameter to the advice.
321      *
322      * @param name the name of the parameter
323      * @param value the value for the parameter
324      */

325     public void addParameter(final String JavaDoc name, final String JavaDoc value) {
326         m_parameters.put(name, value);
327     }
328
329     /**
330      * Returns the parameters as a Map.
331      *
332      * @return the parameters
333      */

334     public Map JavaDoc getParameters() {
335         return m_parameters;
336     }
337
338     /**
339      * Sets the name of the container implementation class.
340      *
341      * @param containerClassName the container class name
342      */

343     public void setContainerClassName(final String JavaDoc containerClassName) {
344         if (containerClassName != null) {
345             m_containerClassName = containerClassName.replace('/', '.');
346         }
347     }
348
349     /**
350      * Returns the name of the container implementation class.
351      *
352      * @return the container class name
353      */

354     public String JavaDoc getContainerClassName() {
355         return m_containerClassName;
356     }
357
358     /**
359      * Returns all the advices for this aspect.
360      *
361      * @return all the advices
362      */

363     public List JavaDoc getAdviceDefinitions() {
364         final List JavaDoc allAdvices = new ArrayList JavaDoc();
365         allAdvices.addAll(m_aroundAdviceDefinitions);
366         allAdvices.addAll(m_beforeAdviceDefinitions);
367         allAdvices.addAll(m_afterAdviceDefinitions);
368         return allAdvices;
369     }
370 }
Popular Tags