1 22 package org.jboss.aop.pointcut; 23 24 import java.lang.reflect.Constructor ; 25 import java.util.ArrayList ; 26 import org.jboss.aop.Advisor; 27 import org.jboss.aop.pointcut.ast.ASTAll; 28 import org.jboss.aop.pointcut.ast.ASTAttribute; 29 import org.jboss.aop.pointcut.ast.ASTConstructor; 30 import org.jboss.aop.pointcut.ast.ASTStart; 31 32 import javassist.CtConstructor; 33 import javassist.NotFoundException; 34 35 41 public class ConstructorMatcher extends MatcherHelper 42 { 43 protected Advisor advisor; 44 protected CtConstructor ctCon; 45 protected Constructor refCon; 46 protected int conModifiers; 47 protected String classname; 48 49 public ConstructorMatcher(Advisor advisor, CtConstructor con, ASTStart start) throws NotFoundException 50 { 51 super(start, advisor.getManager()); 52 this.advisor = advisor; 53 this.start = start; 54 this.conModifiers = con.getModifiers(); 55 this.classname = con.getDeclaringClass().getName(); 56 this.ctCon = con; 57 } 58 59 public ConstructorMatcher(Advisor advisor, Constructor con, ASTStart start) 60 { 61 super(start, advisor.getManager()); 62 this.advisor = advisor; 63 this.start = start; 64 this.conModifiers = con.getModifiers(); 65 this.classname = con.getDeclaringClass().getName(); 66 this.refCon = con; 67 } 68 69 protected Boolean resolvePointcut(Pointcut p) 70 { 71 throw new RuntimeException ("SHOULD NOT BE CALLED"); 72 } 73 74 public Object visit(ASTConstructor node, Object data) 75 { 76 return matches(node); 77 } 78 79 public Boolean matches(ASTConstructor node) 80 { 81 if (node.getAttributes().size() > 0) 82 { 83 for (int i = 0; i < node.getAttributes().size(); i++) 84 { 85 ASTAttribute attr = (ASTAttribute) node.getAttributes().get(i); 86 if (!Util.matchModifiers(attr, conModifiers)) return Boolean.FALSE; 87 } 88 } 89 90 if (ctCon != null) 91 { 92 if (!Util.matchesClassExpr(node.getClazz(), ctCon.getDeclaringClass(), advisor)) return Boolean.FALSE; 93 } 94 else 95 { 96 if (!Util.matchesClassExpr(node.getClazz(), refCon.getDeclaringClass(), advisor)) return Boolean.FALSE; 97 } 98 99 100 if (node.getConstructorAnnotation() != null) 101 { 102 String sub = node.getConstructorAnnotation().getOriginal().substring(1); 103 if (ctCon != null) 104 { 105 if (!advisor.getConstructorMetaData().hasGroup(ctCon, sub)) 106 { 107 if (!advisor.getDefaultMetaData().hasTag(sub)) 108 { 109 if (!advisor.hasAnnotation(ctCon, sub)) return Boolean.FALSE; 110 } 111 } 112 } 113 else 114 { 115 if (!advisor.getConstructorMetaData().hasTag(refCon, sub)) 116 { 117 if (!advisor.getDefaultMetaData().hasTag(sub)) 118 { 119 try 120 { 121 if (!advisor.hasAnnotation(refCon, sub)) return Boolean.FALSE; 122 } 123 catch (Exception e) 124 { 125 throw new RuntimeException (e); } 127 } 128 } 129 } 130 } 131 132 ArrayList nodeExceptions = node.getExceptions(); 134 if (nodeExceptions.size() > 0) 135 { 136 if (ctCon != null) 137 { 138 try 139 { 140 if (!Util.matchExceptions(nodeExceptions, ctCon.getExceptionTypes())) 141 { 142 return Boolean.FALSE; 143 } 144 } 145 catch (NotFoundException e) 146 { 147 throw new RuntimeException (e); 148 } 149 } 150 else 151 { 152 if (!Util.matchExceptions(nodeExceptions, refCon.getExceptionTypes())) 153 { 154 return Boolean.FALSE; 155 } 156 } 157 } 158 159 if (ctCon != null) 160 { 161 if (!Util.matchesParameters(advisor, node, ctCon)) return Boolean.FALSE; 162 } 163 else 164 { 165 if (!Util.matchesParameters(advisor, node, refCon)) return Boolean.FALSE; 166 } 167 return Boolean.TRUE; 168 } 169 170 public Object visit(ASTAll node, Object data) 171 { 172 if (node.getClazz().isAnnotation()) 173 { 174 String sub = node.getClazz().getOriginal().substring(1); 175 if (ctCon != null) 176 { 177 if (!advisor.getConstructorMetaData().hasGroup(ctCon, sub)) 178 { 179 if (!advisor.getDefaultMetaData().hasTag(sub)) 180 { 181 if (!advisor.hasAnnotation(ctCon, sub)) 182 { 183 return Boolean.FALSE; 184 } 185 } 186 } 187 } 188 else 189 { 190 if (!advisor.getConstructorMetaData().hasTag(refCon, sub)) 191 { 192 if (!advisor.getDefaultMetaData().hasTag(sub)) 193 { 194 try 195 { 196 if (!advisor.hasAnnotation(refCon, sub)) return Boolean.FALSE; 197 } 198 catch (Exception e) 199 { 200 throw new RuntimeException (e); } 202 } 203 } 204 } 205 } 206 else if (node.getClazz().isInstanceOf()) 207 { 208 if (ctCon != null) 209 { 210 if (!Util.subtypeOf(ctCon.getDeclaringClass(), node.getClazz(), advisor)) return Boolean.FALSE; 211 } 212 else if (!Util.subtypeOf(refCon.getDeclaringClass(), node.getClazz(), advisor)) return Boolean.FALSE; 213 214 } 215 else if (node.getClazz().isTypedef()) 216 { 217 if (ctCon != null) 218 { 219 try 220 { 221 if (!Util.matchesTypedef(ctCon.getDeclaringClass(), node.getClazz(), advisor)) return Boolean.FALSE; 222 } 223 catch (Exception e) 224 { 225 throw new RuntimeException (e); 226 } 227 } 228 else if (!Util.matchesTypedef(refCon.getDeclaringClass(), node.getClazz(), advisor)) return Boolean.FALSE; 229 } 230 else if (!node.getClazz().matches(classname)) 231 { 232 return Boolean.FALSE; 233 } 234 235 return Boolean.TRUE; 236 } 237 } 238 | Popular Tags |