1 16 17 package org.springframework.aop.support; 18 19 import org.apache.oro.text.regex.MalformedPatternException; 20 import org.apache.oro.text.regex.Pattern; 21 import org.apache.oro.text.regex.PatternMatcher; 22 import org.apache.oro.text.regex.Perl5Compiler; 23 import org.apache.oro.text.regex.Perl5Matcher; 24 25 46 public class Perl5RegexpMethodPointcut extends AbstractRegexpMethodPointcut { 47 48 54 private transient Pattern[] compiledPatterns = new Pattern[0]; 55 56 private transient Pattern[] compiledExclusionPatterns = new Pattern[0]; 57 58 59 private transient PatternMatcher matcher; 60 61 62 65 protected void initPatternRepresentation(String [] patterns) throws IllegalArgumentException { 66 this.compiledPatterns = compilePatterns(patterns); 67 this.matcher = new Perl5Matcher(); 68 } 69 70 74 protected boolean matches(String pattern, int patternIndex) { 75 return this.matcher.matches(pattern, this.compiledPatterns[patternIndex]); 76 } 77 78 81 protected void initExcludedPatternRepresentation(String [] excludedPatterns) throws IllegalArgumentException { 82 this.compiledExclusionPatterns = compilePatterns(excludedPatterns); 83 } 84 85 89 protected boolean matchesExclusion(String pattern, int patternIndex) { 90 return this.matcher.matches(pattern, this.compiledExclusionPatterns[patternIndex]); 91 } 92 93 96 private Pattern[] compilePatterns(String [] source) { 97 Perl5Compiler compiler = new Perl5Compiler(); 98 Pattern[] destination = new Pattern[source.length]; 99 for (int i = 0; i < source.length; i++) { 100 try { 102 destination[i] = compiler.compile(source[i], Perl5Compiler.READ_ONLY_MASK); 103 } 104 catch (MalformedPatternException ex) { 105 throw new IllegalArgumentException (ex.getMessage()); 106 } 107 } 108 return destination; 109 } 110 111 } 112 | Popular Tags |