1 22 package org.jboss.aop.pointcut; 23 24 import javassist.CtBehavior; 25 import javassist.CtConstructor; 26 import javassist.CtMethod; 27 import javassist.NotFoundException; 28 import org.jboss.aop.Advisor; 29 import org.jboss.aop.pointcut.ast.ASTConstructor; 30 import org.jboss.aop.pointcut.ast.ASTMethod; 31 import org.jboss.aop.pointcut.ast.ASTStart; 32 import org.jboss.aop.pointcut.ast.ASTWithin; 33 import org.jboss.aop.pointcut.ast.ASTWithincode; 34 35 import java.lang.reflect.AccessibleObject ; 36 import java.lang.reflect.Constructor ; 37 import java.lang.reflect.Method ; 38 39 45 public class WithinMatcher extends MatcherHelper 46 { 47 CtBehavior behavior; 48 Advisor advisor; 49 AccessibleObject accessible; 50 51 public WithinMatcher(Advisor advisor, CtBehavior behavior, ASTStart start) throws NotFoundException 52 { 53 super(start, advisor.getManager()); 54 this.advisor = advisor; 55 this.behavior = behavior; 56 } 57 58 public WithinMatcher(Advisor advisor, AccessibleObject behavior, ASTStart start) 59 { 60 super(start, advisor.getManager()); 61 this.advisor = advisor; 62 this.accessible = behavior; 63 } 64 65 protected Boolean resolvePointcut(Pointcut p) 66 { 67 throw new RuntimeException ("NOT REACHABLE"); 68 } 69 70 public Class getDeclaringClass() 71 { 72 if (accessible instanceof Constructor) 73 return ((Constructor) accessible).getDeclaringClass(); 74 else if (accessible instanceof Method) return ((Method) accessible).getDeclaringClass(); 75 return null; 76 } 77 78 public Object visit(ASTWithin node, Object data) 79 { 80 if (behavior != null) 81 { 82 if (!Util.matchesClassExpr(node.getClazz(), behavior.getDeclaringClass(), advisor)) return Boolean.FALSE; 83 } 84 else 85 { 86 if (!Util.matchesClassExpr(node.getClazz(), getDeclaringClass(), advisor)) return Boolean.FALSE; 87 } 88 return Boolean.TRUE; 89 } 90 91 public Object visit(ASTWithincode node, Object data) 92 { 93 return node.jjtGetChild(0).jjtAccept(this, null); 94 } 95 96 public Object visit(ASTMethod node, Object data) 97 { 98 if (behavior != null) 99 { 100 if (behavior instanceof CtConstructor) return Boolean.FALSE; 101 MethodMatcher matcher = new MethodMatcher(advisor, (CtMethod) behavior, null); 102 return matcher.matches(node); 103 } 104 if (accessible instanceof Constructor) return Boolean.FALSE; 105 MethodMatcher matcher = new MethodMatcher(advisor, (Method) accessible, null); 106 return matcher.matches(node); 107 108 } 109 110 public Object visit(ASTConstructor node, Object data) 111 { 112 if (behavior != null) 113 { 114 try 115 { 116 if (behavior instanceof CtMethod) return Boolean.FALSE; 117 ConstructorMatcher matcher = new ConstructorMatcher(advisor, (CtConstructor) behavior, null); 118 return matcher.matches(node); 119 } 120 catch (NotFoundException e) 121 { 122 throw new RuntimeException (e); } 124 } 125 if (accessible instanceof Method) return Boolean.FALSE; 126 ConstructorMatcher matcher = new ConstructorMatcher(advisor, (Constructor) accessible, null); 127 return matcher.matches(node); 128 129 } 130 131 } 132 | Popular Tags |