1 22 package org.jboss.aop.pointcut; 23 24 import java.lang.reflect.Method ; 25 26 import org.jboss.aop.Advisor; 27 import org.jboss.aop.AspectManager; 28 import org.jboss.aop.annotation.AnnotationElement; 29 import org.jboss.aop.pointcut.ast.ClassExpression; 30 import org.jboss.aop.proxy.container.ClassProxyContainer; 31 32 38 public abstract class MatcherStrategy 39 { 40 private final static MatcherStrategy ADVISOR_MATCHER_STRATEGY = new AdvisorMatcherStrategy(); 41 private final static MatcherStrategy PROXY_MATCHER_STRATEGY = new ProxyMatcherStrategy(); 42 43 public static MatcherStrategy getMatcher(Advisor advisor) 44 { 45 if (advisor instanceof ClassProxyContainer) 46 { 47 return PROXY_MATCHER_STRATEGY; 48 } 49 50 return ADVISOR_MATCHER_STRATEGY; 51 } 52 53 public boolean subtypeOf(Class clazz, ClassExpression instanceOf, Advisor advisor) 54 { 55 56 if (clazz == null) return false; 57 if (instanceOf.isInstanceOfAnnotated()) 58 { 59 String sub = instanceOf.getInstanceOfAnnotation().substring(1); 60 try 61 { 62 Class annotation = Thread.currentThread().getContextClassLoader().loadClass(sub); 63 if (AnnotationElement.getAnyAnnotation(clazz, annotation) != null) 64 { 65 return true; 66 } 67 } 68 catch (ClassNotFoundException e) 69 { 70 if (AspectManager.verbose) 71 { 72 System.out.println("[warn] The annotation @" + sub + " referenced in one of your pointcut expressions can not be found"); 73 } 74 return false; 75 } 76 } 77 else if (instanceOf.matches(clazz.getName())) 78 { 79 return true; 80 } 81 82 Class [] interfaces = clazz.getInterfaces(); 83 for (int i = 0; i < interfaces.length; i++) 84 { 85 if (subtypeOf(interfaces[i], instanceOf, advisor)) return true; 86 } 87 if (clazz.isInterface()) return false; 89 if (checkIntroductions(clazz, instanceOf, advisor)) 90 { 91 return true; 92 } 93 94 return subtypeOf(clazz.getSuperclass(), instanceOf, advisor); 95 } 96 97 protected abstract boolean checkIntroductions(Class clazz, ClassExpression instanceOf, Advisor advisor); 98 99 public abstract Class getDeclaringClass(Advisor advisor, Method m); 100 } 101 | Popular Tags |