1 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 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 55 public ComposablePointcut() { 56 this.classFilter = ClassFilter.TRUE; 57 this.methodMatcher = MethodMatcher.TRUE; 58 } 59 60 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 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 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 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 110 public ComposablePointcut union(ClassFilter other) { 111 this.classFilter = ClassFilters.union(this.classFilter, other); 112 return this; 113 } 114 115 120 public ComposablePointcut intersection(ClassFilter other) { 121 this.classFilter = ClassFilters.intersection(this.classFilter, other); 122 return this; 123 } 124 125 130 public ComposablePointcut union(MethodMatcher other) { 131 this.methodMatcher = MethodMatchers.union(this.methodMatcher, other); 132 return this; 133 } 134 135 140 public ComposablePointcut intersection(MethodMatcher other) { 141 this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other); 142 return this; 143 } 144 145 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 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 public ClassFilter getClassFilter() { 174 return this.classFilter; 175 } 176 177 public MethodMatcher getMethodMatcher() { 178 return this.methodMatcher; 179 } 180 181 182 public boolean equals(Object other) { 183 if (this == other) { 184 return true; 185 } 186 if (!(other instanceof ComposablePointcut)) { 187 return false; 188 } 189 190 ComposablePointcut that = (ComposablePointcut) other; 191 return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) && 192 ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher); 193 } 194 195 public int hashCode() { 196 int code = 17; 197 if (this.classFilter != null) { 198 code = 37 * code + this.classFilter.hashCode(); 199 } 200 if (this.methodMatcher != null) { 201 code = 37 * code + this.methodMatcher.hashCode(); 202 } 203 return code; 204 } 205 206 public String toString() { 207 return "ComposablePointcut: ClassFilter [" + this.classFilter + 208 "], MethodMatcher [" + this.methodMatcher + "]"; 209 } 210 211 } 212 | Popular Tags |