1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation; 25 import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation; 26 import org.jboss.aop.joinpoint.ConstructorInvocation; 27 import org.jboss.aop.joinpoint.FieldReadInvocation; 28 import org.jboss.aop.joinpoint.FieldWriteInvocation; 29 import org.jboss.aop.joinpoint.Invocation; 30 import org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation; 31 import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation; 32 import org.jboss.aop.joinpoint.MethodInvocation; 33 import org.jboss.aop.pointcut.ast.ParseException; 34 35 41 public class JoinPointMatcher 42 { 43 Pointcut p; 44 45 49 public JoinPointMatcher(String expr) throws ParseException 50 { 51 p = new PointcutExpression("test", expr); 52 } 53 54 public boolean matches(Invocation invocation) 55 { 56 if (invocation instanceof MethodInvocation) 57 { 58 MethodInvocation mi = (MethodInvocation) invocation; 59 PointcutMethodMatch pmatch = p.matchesExecution(mi.getAdvisor(), mi.getMethod()); 60 if (pmatch == null) 61 { 62 return false; 63 } 64 return pmatch.isMatch(); 65 } 66 else if (invocation instanceof ConstructorInvocation) 67 { 68 ConstructorInvocation mi = (ConstructorInvocation) invocation; 69 return p.matchesExecution(mi.getAdvisor(), mi.getConstructor()); 70 } 71 else if (invocation instanceof FieldReadInvocation) 72 { 73 FieldReadInvocation mi = (FieldReadInvocation) invocation; 74 return p.matchesGet(mi.getAdvisor(), mi.getField()); 75 } 76 else if (invocation instanceof FieldWriteInvocation) 77 { 78 FieldWriteInvocation mi = (FieldWriteInvocation) invocation; 79 return p.matchesSet(mi.getAdvisor(), mi.getField()); 80 } 81 else if (invocation instanceof MethodCalledByMethodInvocation) 82 { 83 MethodCalledByMethodInvocation mi = (MethodCalledByMethodInvocation) invocation; 84 return p.matchesCall(mi.getAdvisor(), mi.getCallingMethod(), mi.getCalledMethod().getDeclaringClass(), mi.getCalledMethod()); 85 } 86 else if (invocation instanceof MethodCalledByConstructorInvocation) 87 { 88 MethodCalledByConstructorInvocation mi = (MethodCalledByConstructorInvocation) invocation; 89 return p.matchesCall(mi.getAdvisor(), mi.getCalling(), mi.getCalledMethod().getDeclaringClass(), mi.getCalledMethod()); 90 } 91 else if (invocation instanceof ConstructorCalledByConstructorInvocation) 92 { 93 ConstructorCalledByConstructorInvocation mi = (ConstructorCalledByConstructorInvocation) invocation; 94 return p.matchesCall(mi.getAdvisor(), mi.getCallingConstructor(), mi.getCalledConstructor().getDeclaringClass(), mi.getCalledConstructor()); 95 } 96 else if (invocation instanceof ConstructorCalledByMethodInvocation) 97 { 98 ConstructorCalledByMethodInvocation mi = (ConstructorCalledByMethodInvocation) invocation; 99 return p.matchesCall(mi.getAdvisor(), mi.getCallingMethod(), mi.getCalledConstructor().getDeclaringClass(), mi.getCalledConstructor()); 100 } 101 throw new RuntimeException ("UNKNOWN JOINPOINT TYPE: " + invocation.getClass().getName()); 102 } 103 } 104 | Popular Tags |