1 16 17 package org.springframework.aop.support; 18 19 import java.io.Serializable ; 20 21 import org.aopalliance.aop.Advice; 22 23 import org.springframework.aop.Pointcut; 24 import org.springframework.core.JdkVersion; 25 import org.springframework.util.ObjectUtils; 26 27 54 public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor { 55 56 private String [] patterns; 57 58 private boolean perl5 = false; 59 60 private AbstractRegexpMethodPointcut pointcut; 61 62 private final Object pointcutMonitor = new SerializableMonitor(); 63 64 65 72 public RegexpMethodPointcutAdvisor() { 73 } 74 75 83 public RegexpMethodPointcutAdvisor(Advice advice) { 84 setAdvice(advice); 85 } 86 87 93 public RegexpMethodPointcutAdvisor(String pattern, Advice advice) { 94 setPattern(pattern); 95 setAdvice(advice); 96 } 97 98 104 public RegexpMethodPointcutAdvisor(String [] patterns, Advice advice) { 105 setPatterns(patterns); 106 setAdvice(advice); 107 } 108 109 110 115 public void setPattern(String pattern) { 116 setPatterns(new String [] {pattern}); 117 } 118 119 126 public void setPatterns(String [] patterns) { 127 this.patterns = patterns; 128 } 129 130 140 public void setPerl5(boolean perl5) { 141 this.perl5 = perl5; 142 } 143 144 145 148 public Pointcut getPointcut() { 149 synchronized (this.pointcutMonitor) { 150 if (this.pointcut == null) { 151 this.pointcut = createPointcut(); 152 this.pointcut.setPatterns(this.patterns); 153 } 154 return pointcut; 155 } 156 } 157 158 167 protected AbstractRegexpMethodPointcut createPointcut() { 168 if (this.perl5 || JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_14) { 169 return Perl5RegexpPointcutFactory.createPerl5RegexpPointcut(); 171 } 172 else { 173 return new JdkRegexpMethodPointcut(); 175 } 176 } 177 178 public String toString() { 179 return getClass().getName() + ": advice [" + getAdvice() + 180 "], pointcut patterns " + ObjectUtils.nullSafeToString(this.patterns); 181 } 182 183 184 188 private static class Perl5RegexpPointcutFactory { 189 190 public static AbstractRegexpMethodPointcut createPerl5RegexpPointcut() { 191 return new Perl5RegexpMethodPointcut(); 192 } 193 } 194 195 196 199 private static class SerializableMonitor implements Serializable { 200 } 201 202 } 203 | Popular Tags |