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.MethodMatcher; 23 import org.springframework.aop.Pointcut; 24 import org.springframework.util.Assert; 25 26 35 public abstract class Pointcuts { 36 37 38 public static final Pointcut SETTERS = SetterPointcut.INSTANCE; 39 40 41 public static final Pointcut GETTERS = GetterPointcut.INSTANCE; 42 43 44 51 public static Pointcut union(Pointcut pc1, Pointcut pc2) { 52 return new ComposablePointcut(pc1).union(pc2); 53 } 54 55 62 public static Pointcut intersection(Pointcut pc1, Pointcut pc2) { 63 return new ComposablePointcut(pc1).intersection(pc2); 64 } 65 66 74 public static boolean matches(Pointcut pointcut, Method method, Class targetClass, Object [] args) { 75 Assert.notNull(pointcut, "Pointcut must not be null"); 76 if (pointcut == Pointcut.TRUE) { 77 return true; 78 } 79 if (pointcut.getClassFilter().matches(targetClass)) { 80 MethodMatcher mm = pointcut.getMethodMatcher(); 82 if (mm.matches(method, targetClass)) { 83 return (!mm.isRuntime() || mm.matches(method, targetClass, args)); 85 } 86 } 87 return false; 88 } 89 90 91 94 private static class SetterPointcut extends StaticMethodMatcherPointcut implements Serializable { 95 96 public static SetterPointcut INSTANCE = new SetterPointcut(); 97 98 public boolean matches(Method method, Class targetClass) { 99 return method.getName().startsWith("set") && 100 method.getParameterTypes().length == 1 && 101 method.getReturnType() == Void.TYPE; 102 } 103 104 private Object readResolve() { 105 return INSTANCE; 106 } 107 } 108 109 110 113 private static class GetterPointcut extends StaticMethodMatcherPointcut implements Serializable { 114 115 public static GetterPointcut INSTANCE = new GetterPointcut(); 116 117 public boolean matches(Method method, Class targetClass) { 118 return method.getName().startsWith("get") && 119 method.getParameterTypes().length == 0; 120 } 121 122 private Object readResolve() { 123 return INSTANCE; 124 } 125 } 126 127 } 128 | Popular Tags |