1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.AspectManager; 26 import org.jboss.aop.pointcut.ast.ASTCall; 27 import org.jboss.aop.pointcut.ast.ASTConstructor; 28 import org.jboss.aop.pointcut.ast.ASTField; 29 import org.jboss.aop.pointcut.ast.ASTHas; 30 import org.jboss.aop.pointcut.ast.ASTHasField; 31 import org.jboss.aop.pointcut.ast.ASTMethod; 32 import org.jboss.aop.pointcut.ast.ASTStart; 33 import org.jboss.aop.pointcut.ast.ASTWithin; 34 import org.jboss.aop.pointcut.ast.ASTWithincode; 35 import org.jboss.aop.pointcut.ast.Node; 36 37 import java.lang.reflect.AccessibleObject ; 38 import java.lang.reflect.Method ; 39 40 46 public class CallMatcher extends MatcherHelper 47 { 48 Advisor advisor; 49 AccessibleObject within; 50 Class calledClass; 51 Method calledMethod; 52 53 public CallMatcher(Advisor advisor, AccessibleObject within, Class calledClass, Method calledMethod, ASTStart start) 54 { 55 super(start, advisor.getManager()); 56 this.advisor = advisor; 57 this.within = within; 58 this.calledClass = calledClass; 59 this.calledMethod = calledMethod; 60 } 61 62 public Object visit(ASTCall node, Object data) 63 { 64 try 65 { 66 if (!(node.getBehavior() instanceof ASTMethod)) return Boolean.FALSE; 67 ASTMethod astMethod = (ASTMethod) node.getBehavior(); 68 Advisor calledAdvisor = AspectManager.instance().getTempClassAdvisorIfNotExist(calledClass); 69 MethodMatcher methodMatcher = new MethodMatcher(calledAdvisor, calledMethod, null); 70 if (!(methodMatcher.matches(astMethod)).booleanValue()) return Boolean.FALSE; 71 return Boolean.TRUE; 72 } 73 catch (Exception e) 74 { 75 throw new RuntimeException (e); } 77 } 78 79 public Object visit(ASTHas node, Object data) 80 { 81 Node n = node.jjtGetChild(0); 82 if (n instanceof ASTMethod) 83 { 84 return new Boolean (Util.has(calledClass, (ASTMethod) n, advisor)); 85 } 86 else 87 { 88 return new Boolean (Util.has(calledClass, (ASTConstructor) n, advisor)); 89 } 90 } 91 92 public Object visit(ASTHasField node, Object data) 93 { 94 ASTField f = (ASTField) node.jjtGetChild(0); 95 return new Boolean (Util.has(calledClass, f, advisor)); 96 } 97 98 public Object visit(ASTWithin node, Object data) 99 { 100 WithinMatcher visitor = new WithinMatcher(advisor, this.within, null); 101 return node.jjtAccept(visitor, null); 102 } 103 104 public Object visit(ASTWithincode node, Object data) 105 { 106 WithinMatcher visitor = new WithinMatcher(advisor, this.within, null); 107 return node.jjtAccept(visitor, null); 108 } 109 110 protected Boolean resolvePointcut(Pointcut p) 111 { 112 return new Boolean (p.matchesCall(advisor, within, calledClass, calledMethod)); 113 } 114 115 } 116 | Popular Tags |