1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.AspectManager; 25 import org.jboss.aop.pointcut.ast.ASTAll; 26 import org.jboss.aop.pointcut.ast.ASTAllParameter; 27 import org.jboss.aop.pointcut.ast.ASTAnd; 28 import org.jboss.aop.pointcut.ast.ASTAndCFlow; 29 import org.jboss.aop.pointcut.ast.ASTAttribute; 30 import org.jboss.aop.pointcut.ast.ASTBoolean; 31 import org.jboss.aop.pointcut.ast.ASTCFlow; 32 import org.jboss.aop.pointcut.ast.ASTCFlowBoolean; 33 import org.jboss.aop.pointcut.ast.ASTCFlowExpression; 34 import org.jboss.aop.pointcut.ast.ASTCall; 35 import org.jboss.aop.pointcut.ast.ASTComposite; 36 import org.jboss.aop.pointcut.ast.ASTCompositeCFlow; 37 import org.jboss.aop.pointcut.ast.ASTConstructor; 38 import org.jboss.aop.pointcut.ast.ASTException; 39 import org.jboss.aop.pointcut.ast.ASTExecution; 40 import org.jboss.aop.pointcut.ast.ASTExecutionOnly; 41 import org.jboss.aop.pointcut.ast.ASTField; 42 import org.jboss.aop.pointcut.ast.ASTFieldExecution; 43 import org.jboss.aop.pointcut.ast.ASTGet; 44 import org.jboss.aop.pointcut.ast.ASTHas; 45 import org.jboss.aop.pointcut.ast.ASTHasField; 46 import org.jboss.aop.pointcut.ast.ASTMethod; 47 import org.jboss.aop.pointcut.ast.ASTNot; 48 import org.jboss.aop.pointcut.ast.ASTNotCFlow; 49 import org.jboss.aop.pointcut.ast.ASTOr; 50 import org.jboss.aop.pointcut.ast.ASTOrCFlow; 51 import org.jboss.aop.pointcut.ast.ASTParameter; 52 import org.jboss.aop.pointcut.ast.ASTPointcut; 53 import org.jboss.aop.pointcut.ast.ASTSet; 54 import org.jboss.aop.pointcut.ast.ASTStart; 55 import org.jboss.aop.pointcut.ast.ASTSub; 56 import org.jboss.aop.pointcut.ast.ASTSubCFlow; 57 import org.jboss.aop.pointcut.ast.ASTWithin; 58 import org.jboss.aop.pointcut.ast.ASTWithincode; 59 import org.jboss.aop.pointcut.ast.Node; 60 import org.jboss.aop.pointcut.ast.PointcutExpressionParserVisitor; 61 import org.jboss.aop.pointcut.ast.SimpleNode; 62 import org.jboss.aop.pointcut.ast.ASTConstruction; 63 64 70 public abstract class MatcherHelper implements PointcutExpressionParserVisitor 71 { 72 protected ASTStart start; 73 protected AspectManager manager; 74 75 protected MatcherHelper(ASTStart start, AspectManager manager) 76 { 77 this.start = start; 78 this.manager = manager; 79 } 80 81 public boolean matches() 82 { 83 boolean matches = ((Boolean ) visit(start, null)).booleanValue(); 84 return matches; 85 } 86 87 public Object visit(ASTStart node, Object data) 88 { 89 return node.jjtGetChild(0).jjtAccept(this, data); 90 } 91 92 public Object visit(ASTExecutionOnly node, Object data) 93 { 94 throw new RuntimeException ("SHOULD NEVER BE CALLED!"); 95 } 96 97 public Object visit(ASTBoolean node, Object data) 98 { 99 return node.jjtGetChild(0).jjtAccept(this, data); 100 } 101 102 public Object visit(ASTComposite node, Object data) 103 { 104 return node.jjtGetChild(0).jjtAccept(this, data); 105 } 106 107 public Object visit(ASTNot node, Object data) 108 { 109 110 Boolean bool = (Boolean ) node.jjtGetChild(0).jjtAccept(this, data); 111 boolean val = bool.booleanValue(); 112 return val ? Boolean.FALSE : Boolean.TRUE; 113 } 114 115 public Object visit(ASTSub node, Object data) 116 { 117 for (int i = 0; i < node.jjtGetNumChildren(); i++) 118 { 119 data = node.jjtGetChild(i).jjtAccept(this, data); 120 } 121 return data; 122 } 123 124 public Object visit(ASTAnd node, Object left) 125 { 126 Node andChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 128 return new Boolean (val && ((Boolean ) andChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 129 } 130 131 public Object visit(ASTOr node, Object left) 132 { 133 Node orChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 135 return new Boolean (val || ((Boolean ) orChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 136 } 137 138 protected abstract Boolean resolvePointcut(Pointcut p); 139 140 public Object visit(ASTPointcut node, Object data) 141 { 142 Pointcut p = manager.getPointcut(node.getPointcutName()); 143 if (p == null) throw new RuntimeException ("Unable to resolve pointcut reference: " + node.getPointcutName()); 144 return resolvePointcut(p); 145 } 146 147 public Object visit(SimpleNode node, Object data) 149 { 150 return Boolean.FALSE; 151 } 152 153 public Object visit(ASTAll node, Object data) 154 { 155 return Boolean.FALSE; 156 } 157 158 public Object visit(ASTCFlowExpression node, Object data) 159 { 160 return Boolean.FALSE; 161 } 162 163 public Object visit(ASTCFlowBoolean node, Object data) 164 { 165 return Boolean.FALSE; 166 } 167 168 public Object visit(ASTNotCFlow node, Object data) 169 { 170 return Boolean.FALSE; 171 } 172 173 public Object visit(ASTCompositeCFlow node, Object data) 174 { 175 return Boolean.FALSE; 176 } 177 178 public Object visit(ASTSubCFlow node, Object data) 179 { 180 return Boolean.FALSE; 181 } 182 183 public Object visit(ASTAndCFlow node, Object data) 184 { 185 return Boolean.FALSE; 186 } 187 188 public Object visit(ASTOrCFlow node, Object data) 189 { 190 return Boolean.FALSE; 191 } 192 193 public Object visit(ASTCFlow node, Object data) 194 { 195 return Boolean.FALSE; 196 } 197 198 public Object visit(ASTCall node, Object data) 199 { 200 return Boolean.FALSE; 201 } 202 203 public Object visit(ASTWithin node, Object data) 204 { 205 return Boolean.FALSE; 206 } 207 208 public Object visit(ASTWithincode node, Object data) 209 { 210 return Boolean.FALSE; 211 } 212 213 public Object visit(ASTExecution node, Object data) 214 { 215 return Boolean.FALSE; 216 } 217 218 public Object visit(ASTConstruction node, Object data) 219 { 220 return Boolean.FALSE; 221 } 222 223 public Object visit(ASTGet node, Object data) 224 { 225 return Boolean.FALSE; 226 } 227 228 public Object visit(ASTSet node, Object data) 229 { 230 return Boolean.FALSE; 231 } 232 233 public Object visit(ASTMethod node, Object data) 234 { 235 return Boolean.FALSE; 236 } 237 238 public Object visit(ASTAttribute node, Object data) 239 { 240 return Boolean.FALSE; 241 } 242 243 public Object visit(ASTConstructor node, Object data) 244 { 245 return Boolean.FALSE; 246 } 247 248 public Object visit(ASTParameter node, Object data) 249 { 250 return Boolean.FALSE; 251 } 252 253 public Object visit(ASTAllParameter node, Object data) 254 { 255 return Boolean.FALSE; 256 } 257 258 public Object visit(ASTField node, Object data) 259 { 260 return Boolean.FALSE; 261 } 262 263 public Object visit(ASTException node, Object data) 264 { 265 return Boolean.FALSE; 266 } 267 268 public Object visit(ASTFieldExecution node, Object data) 269 { 270 return Boolean.FALSE; 271 } 272 273 public Object visit(ASTHas node, Object data) 274 { 275 return Boolean.FALSE; 276 } 277 278 public Object visit(ASTHasField node, Object data) 279 { 280 return Boolean.FALSE; 281 } 282 283 284 } 285 | Popular Tags |