1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.ClassAdvisor; 26 import org.jboss.aop.pointcut.ast.ASTAll; 27 import org.jboss.aop.pointcut.ast.ASTAllParameter; 28 import org.jboss.aop.pointcut.ast.ASTAndCFlow; 29 import org.jboss.aop.pointcut.ast.ASTAttribute; 30 import org.jboss.aop.pointcut.ast.ASTCFlow; 31 import org.jboss.aop.pointcut.ast.ASTCFlowBoolean; 32 import org.jboss.aop.pointcut.ast.ASTCFlowExpression; 33 import org.jboss.aop.pointcut.ast.ASTCall; 34 import org.jboss.aop.pointcut.ast.ASTCompositeCFlow; 35 import org.jboss.aop.pointcut.ast.ASTConstruction; 36 import org.jboss.aop.pointcut.ast.ASTConstructor; 37 import org.jboss.aop.pointcut.ast.ASTExecution; 38 import org.jboss.aop.pointcut.ast.ASTField; 39 import org.jboss.aop.pointcut.ast.ASTFieldExecution; 40 import org.jboss.aop.pointcut.ast.ASTGet; 41 import org.jboss.aop.pointcut.ast.ASTHas; 42 import org.jboss.aop.pointcut.ast.ASTHasField; 43 import org.jboss.aop.pointcut.ast.ASTMethod; 44 import org.jboss.aop.pointcut.ast.ASTNotCFlow; 45 import org.jboss.aop.pointcut.ast.ASTOrCFlow; 46 import org.jboss.aop.pointcut.ast.ASTParameter; 47 import org.jboss.aop.pointcut.ast.ASTSet; 48 import org.jboss.aop.pointcut.ast.ASTStart; 49 import org.jboss.aop.pointcut.ast.ASTSubCFlow; 50 import org.jboss.aop.pointcut.ast.ASTWithin; 51 import org.jboss.aop.pointcut.ast.ASTWithincode; 52 import org.jboss.aop.pointcut.ast.ClassExpression; 53 import org.jboss.aop.pointcut.ast.Node; 54 import org.jboss.aop.pointcut.ast.SimpleNode; 55 56 62 public class SoftClassMatcher extends MatcherHelper 63 { 64 protected Advisor advisor; 65 protected String classname; 66 protected boolean match = false; 67 protected Class clazz; 68 69 public SoftClassMatcher(Advisor advisor, String classname, ASTStart start) 70 { 71 super(start, advisor.getManager()); 72 this.advisor = advisor; 73 this.classname = classname; 74 this.start = start; 75 clazz = advisor.getClazz(); 76 } 77 78 protected Boolean resolvePointcut(Pointcut p) 79 { 80 return new Boolean (p.softMatch(advisor)); 81 } 82 83 public Object visit(ASTCall node, Object data) 84 { 85 return node.getBehavior().jjtAccept(this, null); 86 } 87 88 public Object visit(ASTAll node, Object data) 89 { 90 return matches(node.getClazz()); 91 } 92 93 94 public Boolean matches(ClassExpression expr) 95 { 96 if (expr.isAnnotation()) 97 { 98 if (advisor == null) return Boolean.TRUE; 99 if (clazz == null) return Boolean.TRUE; 100 String sub = expr.getOriginal().substring(1); 101 if (!advisor.getClassMetaData().hasTag(sub)) 102 { 103 try 104 { 105 if (clazz == null) return Boolean.TRUE; 106 if (!advisor.hasAnnotation(sub)) return Boolean.FALSE; 107 } 108 catch (Exception e) 109 { 110 throw new RuntimeException (e); } 112 } 113 } 114 else if (expr.isInstanceOf()) 115 { 116 if (clazz == null) return Boolean.TRUE; 117 if (!Util.subtypeOf(clazz, expr, advisor)) return Boolean.FALSE; 118 119 } 120 else if (expr.isTypedef()) 121 { 122 if (clazz == null) return Boolean.TRUE; if (!Util.matchesTypedef(clazz, expr, advisor)) return Boolean.FALSE; 124 } 125 else 126 { 127 if (!expr.matches(classname)) return Boolean.FALSE; 128 } 129 return Boolean.TRUE; 130 } 131 132 public Object visit(ASTWithin node, Object data) 133 { 134 return matches(node.getClazz()); 135 } 136 137 public Object visit(ASTWithincode node, Object data) 138 { 139 return node.jjtGetChild(0).jjtAccept(this, null); 140 } 141 142 public Object visit(ASTExecution node, Object data) 143 { 144 return node.jjtGetChild(0).jjtAccept(this, null); 145 } 146 147 public Object visit(ASTConstruction node, Object data) 148 { 149 return node.jjtGetChild(0).jjtAccept(this, null); 150 } 151 152 public Object visit(ASTGet node, Object data) 153 { 154 return node.jjtGetChild(0).jjtAccept(this, null); 155 } 156 157 public Object visit(ASTSet node, Object data) 158 { 159 return node.jjtGetChild(0).jjtAccept(this, null); 160 } 161 162 public Object visit(ASTFieldExecution node, Object data) 163 { 164 return node.jjtGetChild(0).jjtAccept(this, null); 165 } 166 167 public Object visit(ASTMethod node, Object data) 168 { 169 ClassExpression classExpression = node.getClazz(); 170 return matchClass(classExpression); 171 } 172 173 private Object matchClass(ClassExpression classExpression) 174 { 175 if (classExpression.isAnnotation()) 176 { 177 String sub = classExpression.getOriginal().substring(1); 178 if (advisor.getClassMetaData().hasTag(sub)) return Boolean.TRUE; 179 return new Boolean (advisor.hasAnnotation(clazz, sub)); 180 } 181 else if (classExpression.isInstanceOf()) 182 { 183 if (clazz == null) return Boolean.TRUE; 184 if (Util.subtypeOf(clazz, classExpression, advisor)) return Boolean.TRUE; 185 } 186 else if (classExpression.isTypedef()) 187 { 188 if (Util.matchesTypedef(clazz, classExpression, advisor)) return Boolean.TRUE; 189 } 190 else 191 { 192 return new Boolean (classExpression.matches(this.classname)); 193 } 194 return Boolean.FALSE; 195 } 196 197 public Object visit(ASTConstructor node, Object data) 198 { 199 ClassExpression classExpression = node.getClazz(); 200 return matchClass(classExpression); 201 } 202 203 204 public Object visit(ASTField node, Object data) 205 { 206 ClassExpression classExpression = node.getClazz(); 207 return matchClass(classExpression); 208 } 209 210 public Object visit(ASTHas node, Object data) 211 { 212 if (clazz == null) return Boolean.TRUE; 213 Node n = node.jjtGetChild(0); 214 if (n instanceof ASTMethod) 215 { 216 return new Boolean (Util.has(clazz, (ASTMethod) n, advisor)); 217 } 218 else 219 { 220 return new Boolean (Util.has(clazz, (ASTConstructor) n, advisor)); 221 } 222 } 223 224 public Object visit(ASTHasField node, Object data) 225 { 226 if (clazz == null) return Boolean.TRUE; 227 ASTField f = (ASTField) node.jjtGetChild(0); 228 return new Boolean (Util.has(clazz, f, advisor)); 229 } 230 231 233 public Object visit(ASTAttribute node, Object data) 234 { 235 return data; 236 } 237 238 public Object visit(ASTParameter node, Object data) 239 { 240 return data; 241 } 242 243 public Object visit(ASTAllParameter node, Object data) 244 { 245 return data; 246 } 247 248 public Object visit(ASTCFlowExpression node, Object data) 249 { 250 return data; 251 } 252 253 public Object visit(ASTCFlowBoolean node, Object data) 254 { 255 return data; 256 } 257 258 public Object visit(ASTNotCFlow node, Object data) 259 { 260 return data; 261 } 262 263 public Object visit(ASTCompositeCFlow node, Object data) 264 { 265 return data; 266 } 267 268 public Object visit(ASTSubCFlow node, Object data) 269 { 270 return data; 271 } 272 273 public Object visit(ASTAndCFlow node, Object data) 274 { 275 return data; 276 } 277 278 public Object visit(ASTOrCFlow node, Object data) 279 { 280 return data; 281 } 282 283 public Object visit(ASTCFlow node, Object data) 284 { 285 return data; 286 } 287 288 public Object visit(SimpleNode node, Object data) 289 { 290 return data; 291 } 292 293 } 294 | Popular Tags |