KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > support > DefaultPointcutAdvisor


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.support;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.aopalliance.aop.Advice;
22
23 import org.springframework.aop.Pointcut;
24
25 /**
26  * Convenient Pointcut-driven Advisor implementation.
27  *
28  * <p>This is the most commonly used Advisor implementation. It can be used
29  * with any pointcut and advice type, except for introductions. There is
30  * normally no need to subclass this class, or to implement custom Advisors.
31  *
32  * @author Rod Johnson
33  * @author Juergen Hoeller
34  * @see #setPointcut
35  * @see #setAdvice
36  */

37 public class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor implements Serializable JavaDoc {
38
39     private Pointcut pointcut = Pointcut.TRUE;
40
41
42     /**
43      * Create an empty DefaultPointcutAdvisor.
44      * <p>Advice must be set before use using setter methods.
45      * Pointcut will normally be set also, but defaults to <code>Pointcut.TRUE</code>.
46      */

47     public DefaultPointcutAdvisor() {
48     }
49     
50     /**
51      * Create a DefaultPointcutAdvisor that matches all methods.
52      * <p><code>Pointcut.TRUE</code> will be used as Pointcut.
53      * @param advice the Advice to use
54      */

55     public DefaultPointcutAdvisor(Advice advice) {
56         this(Pointcut.TRUE, advice);
57     }
58     
59     /**
60      * Create a DefaultPointcutAdvisor, specifying Pointcut and Advice.
61      * @param pointcut the Pointcut targeting the Advice
62      * @param advice the Advice to run when Pointcut matches
63      */

64     public DefaultPointcutAdvisor(Pointcut pointcut, Advice advice) {
65         this.pointcut = pointcut;
66         setAdvice(advice);
67     }
68
69
70     /**
71      * Specify the pointcut targeting the advice.
72      * <p>Default is <code>Pointcut.TRUE</code>.
73      * @see #setAdvice
74      */

75     public void setPointcut(Pointcut pointcut) {
76         this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
77     }
78
79     public Pointcut getPointcut() {
80         return this.pointcut;
81     }
82
83
84     public String JavaDoc toString() {
85         return getClass().getName() + ": pointcut [" + getPointcut() + "]; advice [" + getAdvice() + "]";
86     }
87
88 }
89
Popular Tags