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.ClassAdvisor; 27 import org.jboss.aop.pointcut.ast.ASTCall; 28 import org.jboss.aop.pointcut.ast.ASTConstructor; 29 import org.jboss.aop.pointcut.ast.ASTField; 30 import org.jboss.aop.pointcut.ast.ASTHas; 31 import org.jboss.aop.pointcut.ast.ASTHasField; 32 import org.jboss.aop.pointcut.ast.ASTMethod; 33 import org.jboss.aop.pointcut.ast.ASTStart; 34 import org.jboss.aop.pointcut.ast.ASTWithin; 35 import org.jboss.aop.pointcut.ast.ASTWithincode; 36 import org.jboss.aop.pointcut.ast.Node; 37 38 import java.lang.reflect.AccessibleObject ; 39 import java.lang.reflect.Constructor ; 40 41 47 public class ConstructorCallMatcher extends MatcherHelper 48 { 49 Advisor advisor; 50 AccessibleObject within; 51 Class calledClass; 52 Constructor calledConstructor; 53 54 public ConstructorCallMatcher(Advisor advisor, AccessibleObject within, Class calledClass, Constructor calledCon, ASTStart start) 55 { 56 super(start, advisor.getManager()); 57 this.advisor = advisor; 58 this.within = within; 59 this.calledClass = calledClass; 60 this.calledConstructor = calledCon; 61 } 62 63 public Object visit(ASTCall node, Object data) 64 { 65 try 66 { 67 if (!(node.getBehavior() instanceof ASTConstructor)) return Boolean.FALSE; 68 ASTConstructor astCon = (ASTConstructor) node.getBehavior(); 69 Advisor calledAdvisor = AspectManager.instance().getTempClassAdvisorIfNotExist(calledClass); 70 ConstructorMatcher constructorMatcher = new ConstructorMatcher(calledAdvisor, calledConstructor, null); 71 return constructorMatcher.matches(astCon); 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, 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, 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, calledConstructor)); 113 } 114 115 } 116 | Popular Tags |