1 16 17 package org.springframework.aop.support; 18 19 import java.io.Serializable ; 20 import java.lang.reflect.Method ; 21 22 import org.springframework.aop.ClassFilter; 23 import org.springframework.aop.MethodMatcher; 24 import org.springframework.aop.Pointcut; 25 import org.springframework.util.Assert; 26 27 34 class UnionPointcut implements Pointcut, Serializable { 35 36 private final Pointcut a; 37 38 private final Pointcut b; 39 40 private MethodMatcher methodMatcher; 41 42 43 public UnionPointcut(Pointcut a, Pointcut b) { 44 Assert.notNull(a, "First Pointcut must not be null"); 45 Assert.notNull(b, "Second Pointcut must not be null"); 46 this.a = a; 47 this.b = b; 48 this.methodMatcher = new PointcutUnionMethodMatcher(); 49 } 50 51 public ClassFilter getClassFilter() { 52 return ClassFilters.union(this.a.getClassFilter(), this.b.getClassFilter()); 53 } 54 55 public MethodMatcher getMethodMatcher() { 56 return this.methodMatcher; 58 } 59 60 61 public boolean equals(Object other) { 62 if (this == other) { 63 return true; 64 } 65 if (!(other instanceof UnionPointcut)) { 66 return false; 67 } 68 UnionPointcut that = (UnionPointcut) other; 69 return (this.a.equals(that.a) && this.b.equals(that.b)); 70 } 71 72 public int hashCode() { 73 int code = 17; 74 code = 37 * code + this.a.hashCode(); 75 code = 37 * code + this.b.hashCode(); 76 return code; 77 } 78 79 80 private class PointcutUnionMethodMatcher implements MethodMatcher, Serializable { 81 82 public boolean matches(Method method, Class targetClass) { 83 return (a.getClassFilter().matches(targetClass) && a.getMethodMatcher().matches(method, targetClass)) || 84 (b.getClassFilter().matches(targetClass) && b.getMethodMatcher().matches(method, targetClass)); 85 } 86 87 public boolean isRuntime() { 88 return a.getMethodMatcher().isRuntime() || b.getMethodMatcher().isRuntime(); 89 } 90 91 public boolean matches(Method method, Class targetClass, Object [] args) { 92 return a.getMethodMatcher().matches(method, targetClass, args) || 94 b.getMethodMatcher().matches(method, targetClass, args); 95 } 96 } 97 98 } 99 | Popular Tags |