1 10 package org.nanocontainer.aop.defaults; 11 12 import org.apache.oro.text.regex.MalformedPatternException; 13 import org.apache.oro.text.regex.Pattern; 14 import org.apache.oro.text.regex.Perl5Compiler; 15 import org.apache.oro.text.regex.Perl5Matcher; 16 import org.nanocontainer.aop.ComponentPointcut; 17 import org.nanocontainer.aop.MalformedRegularExpressionException; 18 19 26 public class NameMatchesComponentPointcut implements ComponentPointcut { 27 28 private final Pattern pattern; 29 private final Perl5Matcher matcher = new Perl5Matcher(); 30 31 43 public NameMatchesComponentPointcut(String regex) throws MalformedRegularExpressionException { 44 Perl5Compiler compiler = new Perl5Compiler(); 45 try { 46 pattern = compiler.compile(regex); 47 } catch (MalformedPatternException e) { 48 throw new MalformedRegularExpressionException("malformed component name regular expression", e); 49 } 50 } 51 52 60 public boolean picks(Object componentKey) { 61 String componentName = (String ) componentKey.toString(); 62 return matcher.contains(componentName, pattern); 63 } 64 65 } | Popular Tags |