1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.aop.support;
18
19 import java.io.Serializable;
20
21 import org.springframework.aop.ClassFilter;
22 import org.springframework.aop.MethodMatcher;
23 import org.springframework.aop.Pointcut;
24 import org.springframework.util.Assert;
25 import org.springframework.util.ObjectUtils;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class ComposablePointcut implements Pointcut, Serializable {
42
43
44 private static final long serialVersionUID = -2743223737633663832L;
45
46 private ClassFilter classFilter;
47
48 private MethodMatcher methodMatcher;
49
50
51
52
53
54
55 public ComposablePointcut() {
56 this.classFilter = ClassFilter.TRUE;
57 this.methodMatcher = MethodMatcher.TRUE;
58 }
59
60
61
62
63
64 public ComposablePointcut(Pointcut pointcut) {
65 Assert.notNull(pointcut, "Pointcut must not be null");
66 this.classFilter = pointcut.getClassFilter();
67 this.methodMatcher = pointcut.getMethodMatcher();
68 }
69
70
71
72
73
74
75 public ComposablePointcut(ClassFilter classFilter) {
76 Assert.notNull(classFilter, "ClassFilter must not be null");
77 this.classFilter = classFilter;
78 this.methodMatcher = MethodMatcher.TRUE;
79 }
80
81
82
83
84
85
86 public ComposablePointcut(MethodMatcher methodMatcher) {
87 Assert.notNull(methodMatcher, "MethodMatcher must not be null");
88 this.classFilter = ClassFilter.TRUE;
89 this.methodMatcher = methodMatcher;
90 }
91
92
93
94
95
96
97 public ComposablePointcut(ClassFilter classFilter, MethodMatcher methodMatcher) {
98 Assert.notNull(classFilter, "ClassFilter must not be null");
99 Assert.notNull(methodMatcher, "MethodMatcher must not be null");
100 this.classFilter = classFilter;
101 this.methodMatcher = methodMatcher;
102 }
103
104
105
106
107
108
109
110 public ComposablePointcut union(ClassFilter other) {
111 this.classFilter = ClassFilters.union(this.classFilter, other);
112 return this;
113 }
114
115
116
117
118
119
120 public ComposablePointcut intersection(ClassFilter other) {
121 this.classFilter = ClassFilters.intersection(this.classFilter, other);
122 return this;
123 }
124
125
126
127
128
129
130 public ComposablePointcut union(MethodMatcher other) {
131 this.methodMatcher = MethodMatchers.union(this.methodMatcher, other);
132 return this;
133 }
134
135
136
137
138
139
140 public ComposablePointcut intersection(MethodMatcher other) {
141 this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other);
142 return this;
143 }
144
145
146
147
148
149
150
151
152
153
154 public ComposablePointcut union(Pointcut other) {
155 this.methodMatcher = MethodMatchers.union(
156 this.methodMatcher, this.classFilter, other.getMethodMatcher(), other.getClassFilter());
157 this.classFilter = ClassFilters.union(this.classFilter, other.getClassFilter());
158 return this;
159 }
160
161
162
163
164
165
166 public ComposablePointcut intersection(Pointcut other) {
167 this.classFilter = ClassFilters.intersection(this.classFilter, other.getClassFilter());
168 this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other.getMethodMatcher());
169 return this;
170 }
171
172
173 @Override
174 public ClassFilter getClassFilter() {
175 return this.classFilter;
176 }
177
178 @Override
179 public MethodMatcher getMethodMatcher() {
180 return this.methodMatcher;
181 }
182
183 @Override
184 public boolean equals(Object other) {
185 if (this == other) {
186 return true;
187 }
188 if (!(other instanceof ComposablePointcut)) {
189 return false;
190 }
191 ComposablePointcut that = (ComposablePointcut) other;
192 return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
193 ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
194 }
195
196 @Override
197 public int hashCode() {
198 int code = 17;
199 if (this.classFilter != null) {
200 code = 37 * code + this.classFilter.hashCode();
201 }
202 if (this.methodMatcher != null) {
203 code = 37 * code + this.methodMatcher.hashCode();
204 }
205 return code;
206 }
207
208 @Override
209 public String toString() {
210 return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher;
211 }
212
213 }