01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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
38: AbstractGenericPointcutAdvisor implements Serializable {
39:
40: private Pointcut pointcut = Pointcut.TRUE;
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: * Specify the pointcut targeting the advice.
71: * <p>Default is <code>Pointcut.TRUE</code>.
72: * @see #setAdvice
73: */
74: public void setPointcut(Pointcut pointcut) {
75: this .pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
76: }
77:
78: public Pointcut getPointcut() {
79: return this .pointcut;
80: }
81:
82: public String toString() {
83: return getClass().getName() + ": pointcut [" + getPointcut()
84: + "]; advice [" + getAdvice() + "]";
85: }
86:
87: }
|