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.core.ControlFlow; 26 import org.springframework.core.ControlFlowFactory; 27 import org.springframework.util.Assert; 28 import org.springframework.util.ObjectUtils; 29 30 39 public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable { 40 41 private Class clazz; 42 43 private String methodName; 44 45 private int evaluations; 46 47 48 52 public ControlFlowPointcut(Class clazz) { 53 this(clazz, null); 54 } 55 56 63 public ControlFlowPointcut(Class clazz, String methodName) { 64 Assert.notNull(clazz, "Class must not be null"); 65 this.clazz = clazz; 66 this.methodName = methodName; 67 } 68 69 70 73 public boolean matches(Class clazz) { 74 return true; 75 } 76 77 81 public boolean matches(Method method, Class targetClass) { 82 return true; 83 } 84 85 public boolean isRuntime() { 86 return true; 87 } 88 89 public boolean matches(Method method, Class targetClass, Object [] args) { 90 ++this.evaluations; 91 ControlFlow cflow = ControlFlowFactory.createControlFlow(); 92 return (this.methodName != null) ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz); 93 } 94 95 98 public int getEvaluations() { 99 return evaluations; 100 } 101 102 103 public ClassFilter getClassFilter() { 104 return this; 105 } 106 107 public MethodMatcher getMethodMatcher() { 108 return this; 109 } 110 111 public boolean equals(Object other) { 112 if (this == other) { 113 return true; 114 } 115 if (!(other instanceof ControlFlowPointcut)) { 116 return false; 117 } 118 ControlFlowPointcut that = (ControlFlowPointcut) other; 119 return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(that.methodName, this.methodName); 120 } 121 122 public int hashCode() { 123 int code = 17; 124 code = 37 * code + this.clazz.hashCode(); 125 if (this.methodName != null) { 126 code = 37 * code + this.methodName.hashCode(); 127 } 128 return code; 129 } 130 131 } 132 | Popular Tags |