1 22 package org.jboss.aop.pointcut; 23 24 import javassist.CtClass; 25 import org.jboss.aop.Advisor; 26 import org.jboss.aop.pointcut.ast.ASTAllParameter; 27 import org.jboss.aop.pointcut.ast.ASTAnd; 28 import org.jboss.aop.pointcut.ast.ASTAttribute; 29 import org.jboss.aop.pointcut.ast.ASTBoolean; 30 import org.jboss.aop.pointcut.ast.ASTClass; 31 import org.jboss.aop.pointcut.ast.ASTComposite; 32 import org.jboss.aop.pointcut.ast.ASTConstructor; 33 import org.jboss.aop.pointcut.ast.ASTException; 34 import org.jboss.aop.pointcut.ast.ASTField; 35 import org.jboss.aop.pointcut.ast.ASTHas; 36 import org.jboss.aop.pointcut.ast.ASTHasField; 37 import org.jboss.aop.pointcut.ast.ASTMethod; 38 import org.jboss.aop.pointcut.ast.ASTNot; 39 import org.jboss.aop.pointcut.ast.ASTOr; 40 import org.jboss.aop.pointcut.ast.ASTParameter; 41 import org.jboss.aop.pointcut.ast.ASTStart; 42 import org.jboss.aop.pointcut.ast.ASTSub; 43 import org.jboss.aop.pointcut.ast.Node; 44 import org.jboss.aop.pointcut.ast.SimpleNode; 45 import org.jboss.aop.pointcut.ast.TypeExpressionParserVisitor; 46 47 53 public class TypeMatcher implements TypeExpressionParserVisitor 54 { 55 protected Advisor advisor; 56 protected CtClass ctClass; 57 protected Class clazz; 58 59 public TypeMatcher(Advisor advisor, Class clazz) 60 { 61 this.advisor = advisor; 62 this.clazz = clazz; 63 } 64 65 public TypeMatcher(Advisor advisor, CtClass ctClass) 66 { 67 this.advisor = advisor; 68 this.ctClass = ctClass; 69 } 70 71 public Object visit(ASTStart node, Object data) 72 { 73 return node.jjtGetChild(0).jjtAccept(this, data); 74 } 75 76 public Object visit(ASTBoolean node, Object data) 77 { 78 return node.jjtGetChild(0).jjtAccept(this, data); 79 } 80 81 public Object visit(ASTComposite node, Object data) 82 { 83 return node.jjtGetChild(0).jjtAccept(this, data); 84 } 85 86 public Object visit(ASTNot node, Object data) 87 { 88 89 Boolean bool = (Boolean ) node.jjtGetChild(0).jjtAccept(this, data); 90 boolean val = bool.booleanValue(); 91 return val ? Boolean.FALSE : Boolean.TRUE; 92 } 93 94 public Object visit(ASTSub node, Object data) 95 { 96 for (int i = 0; i < node.jjtGetNumChildren(); i++) 97 { 98 data = node.jjtGetChild(i).jjtAccept(this, data); 99 } 100 return data; 101 } 102 103 public Object visit(ASTAnd node, Object left) 104 { 105 Node andChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 107 return new Boolean (val && ((Boolean ) andChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 108 } 109 110 public Object visit(ASTOr node, Object left) 111 { 112 Node orChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 114 return new Boolean (val || ((Boolean ) orChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 115 } 116 117 118 public Object visit(SimpleNode node, Object data) 119 { 120 return null; 121 } 122 123 124 public Object visit(ASTHas node, Object data) 125 { 126 Node n = node.jjtGetChild(0); 127 if (n instanceof ASTMethod) 128 { 129 if (clazz != null) return new Boolean (Util.has(clazz, (ASTMethod) n, advisor)); 130 if (ctClass != null) return new Boolean (Util.has(ctClass, (ASTMethod) n, advisor)); 131 } 132 else 133 { 134 if (clazz != null) return new Boolean (Util.has(clazz, (ASTConstructor) n, advisor)); 135 if (ctClass != null) return new Boolean (Util.has(ctClass, (ASTConstructor) n, advisor)); 136 } 137 return Boolean.FALSE; 138 } 139 140 public Object visit(ASTHasField node, Object data) 141 { 142 ASTField f = (ASTField) node.jjtGetChild(0); 143 if (clazz != null) 144 return new Boolean (Util.has(clazz, f, advisor)); 145 else 146 return new Boolean (Util.has(ctClass, f, advisor)); 147 } 148 149 public Object visit(ASTClass node, Object data) 150 { 151 if (clazz != null) 152 { 153 return new Boolean (Util.matchesClassExpr(node.getClazz(), clazz, advisor)); 154 } 155 else 156 { 157 return new Boolean (Util.matchesClassExpr(node.getClazz(), ctClass, advisor)); 158 } 159 } 160 161 public Object visit(ASTMethod node, Object data) 162 { 163 return Boolean.FALSE; 164 } 165 166 public Object visit(ASTAttribute node, Object data) 167 { 168 return Boolean.FALSE; 169 } 170 171 public Object visit(ASTConstructor node, Object data) 172 { 173 return Boolean.FALSE; 174 } 175 176 public Object visit(ASTParameter node, Object data) 177 { 178 return Boolean.FALSE; 179 } 180 181 public Object visit(ASTAllParameter node, Object data) 182 { 183 return Boolean.FALSE; 184 } 185 186 public Object visit(ASTField node, Object data) 187 { 188 return Boolean.FALSE; 189 } 190 191 public Object visit(ASTException node, Object data) 192 { 193 return Boolean.FALSE; 194 } 195 196 197 } 198 | Popular Tags |