1 22 package org.jboss.aop.expressions; 23 24 import javassist.CtConstructor; 25 import javassist.NotFoundException; 26 27 import java.lang.reflect.Constructor ; 28 import java.util.regex.Matcher ; 29 import java.util.regex.Pattern ; 30 31 38 public class ConstructorExpression 39 { 40 protected static final Pattern PATTERN = Pattern.compile("(.*)\\((.*)\\)"); 41 public String originalExpression; 42 public ParameterExpression params; 43 public Pattern classExpr; 44 public String className; 45 46 public ConstructorExpression(String ex) 47 { 48 Matcher m = PATTERN.matcher(ex); 49 if (!m.matches()) throw new IllegalStateException ("ConstructorExpression is invalid: " + ex); 50 className = m.group(1); 51 params = new ParameterExpression(m.group(2)); 52 className = className.replaceAll("\\.", "\\\\."); 53 className = className.replaceAll("\\*", ".*"); 54 classExpr = Pattern.compile(className); 55 } 56 57 58 public boolean matches(Constructor con) 59 { 60 Matcher cm = classExpr.matcher(con.getDeclaringClass().getName()); 61 if (cm.matches() == false) return false; 62 63 return params.matches(con.getParameterTypes()); 64 } 65 66 public boolean matchParamsOnly(Constructor con) 67 { 68 return params.matches(con.getParameterTypes()); 69 } 70 71 public boolean matchParamsOnly(CtConstructor con) throws NotFoundException 72 { 73 return params.matches(con.getParameterTypes()); 74 } 75 76 public boolean matches(CtConstructor con) throws NotFoundException 77 { 78 Matcher cm = classExpr.matcher(con.getDeclaringClass().getName()); 79 if (cm.matches() == false) return false; 80 81 return params.matches(con.getParameterTypes()); 82 } 83 } 84 | Popular Tags |