KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > aop > dynaop > InterceptorComponentAspect


1 /*****************************************************************************
2  * Copyright (c) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Idea by Rachel Davies, Original code by various *
9  *****************************************************************************/

10 package org.nanocontainer.aop.dynaop;
11
12 import dynaop.Aspects;
13 import dynaop.Interceptor;
14 import dynaop.InterceptorFactory;
15 import dynaop.MethodPointcut;
16 import dynaop.Pointcuts;
17 import org.nanocontainer.aop.ComponentPointcut;
18
19 /**
20  * Interceptor aspect that is applied to the components that match a component
21  * pointcut.
22  *
23  * @author Stephen Molitor
24  * @version $Revision: 3144 $
25  */

26 class InterceptorComponentAspect extends ComponentAspect {
27
28     private MethodPointcut methodPointcut;
29     private Interceptor interceptor;
30     private InterceptorFactory interceptorFactory;
31
32     /**
33      * Creates a new <code>InterceptorComponentAspect</code> from a given
34      * interceptor advice object.
35      *
36      * @param componentPointcut the components to apply the interceptor to.
37      * @param methodPointcut the methods to intercept.
38      * @param interceptor the interceptor advice object to apply.
39      */

40     InterceptorComponentAspect(ComponentPointcut componentPointcut, MethodPointcut methodPointcut,
41                                Interceptor interceptor) {
42         super(componentPointcut);
43         this.methodPointcut = methodPointcut;
44         this.interceptor = interceptor;
45     }
46
47     /**
48      * Creates a new <code>InterceptorComponentAspect</code> from a given
49      * interceptor factory.
50      *
51      * @param componentPointcut the components to apply the interceptor to.
52      * @param methodPointcut the methods to intercept.
53      * @param interceptorFactory produces the interceptor advice object.
54      */

55     InterceptorComponentAspect(ComponentPointcut componentPointcut, MethodPointcut methodPointcut,
56                                InterceptorFactory interceptorFactory) {
57         super(componentPointcut);
58         this.methodPointcut = methodPointcut;
59         this.interceptorFactory = interceptorFactory;
60     }
61
62     void doRegisterAspect(Object JavaDoc componentKey, Aspects aspects) {
63         if (interceptor != null) {
64             aspects.interceptor(Pointcuts.ALL_CLASSES, methodPointcut, interceptor);
65         } else {
66             aspects.interceptor(Pointcuts.ALL_CLASSES, methodPointcut, interceptorFactory);
67         }
68     }
69
70 }
Popular Tags