1 22 package org.jboss.aop.pointcut; 23 24 import java.io.StringReader ; 25 26 import javassist.CtClass; 27 import javassist.NotFoundException; 28 import javassist.expr.MethodCall; 29 import javassist.expr.NewExpr; 30 31 import org.jboss.aop.Advisor; 32 import org.jboss.aop.pointcut.ast.ASTStart; 33 import org.jboss.aop.pointcut.ast.ParseException; 34 import org.jboss.aop.pointcut.ast.PointcutExpressionParser; 35 import org.jboss.aop.pointcut.ast.TypeExpressionParser; 36 37 42 public class DeclareDef 43 { 44 String name; 45 String expr; 46 boolean warning; 47 String msg; 48 ASTStart ast; 49 boolean pointcut; 50 51 public DeclareDef(String name, String expr, boolean warning, String msg) throws ParseException 52 { 53 this.name = name; 54 this.expr = expr; 55 this.warning = warning; 56 this.msg = msg; 57 58 try 59 { 60 ast = new PointcutExpressionParser(new StringReader (expr)).Start(); 61 pointcut = true; 62 } 63 catch (ParseException pe) 64 { 65 try 66 { 67 ast = new TypeExpressionParser(new StringReader (expr)).Start(); 68 } 69 catch (ParseException te) 70 { 71 StringBuffer sb = new StringBuffer ("The expression '" + 72 expr + "' resolves to neither a pointcut nor a type expression"); 73 sb.append("\n\nPointcut parse error:\n"); 74 sb.append(pe.getMessage()); 75 sb.append("\n\nType expression parse error:\n"); 76 sb.append(te.getMessage()); 77 throw new ParseException(sb.toString()); 78 } 79 } 80 } 81 82 83 public ASTStart getAst() 84 { 85 return ast; 86 } 87 88 public String getExpr() 89 { 90 return expr; 91 } 92 93 public String getName() 94 { 95 return name; 96 } 97 98 public boolean getWarning() 99 { 100 return warning; 101 } 102 103 public String getMsg() 104 { 105 return msg; 106 } 107 108 111 public boolean isPointcut() 112 { 113 return pointcut; 114 } 115 116 public boolean matches(Advisor advisor, CtClass clazz) 117 { 118 if (pointcut)return false; 119 DeclareTypeMatcher matcher = new DeclareTypeMatcher(advisor, clazz); 120 return ((Boolean ) ast.jjtAccept(matcher, null)).booleanValue(); 121 } 122 123 public boolean matches(Advisor advisor, Class clazz) 124 { 125 if (pointcut)return false; 126 DeclareTypeMatcher matcher = new DeclareTypeMatcher(advisor, clazz); 127 return ((Boolean ) ast.jjtAccept(matcher, null)).booleanValue(); 128 } 129 130 public boolean matchesCall(Advisor callingAdvisor, MethodCall methodCall) throws NotFoundException 131 { 132 if (!pointcut)return false; 133 MethodCallMatcher matcher = new MethodCallMatcher(callingAdvisor, methodCall, ast); 134 return matcher.matches(); 135 } 136 137 public boolean matchesCall(Advisor callingAdvisor, NewExpr methodCall) throws NotFoundException 138 { 139 if (!pointcut)return false; 140 NewExprMatcher matcher = new NewExprMatcher(callingAdvisor, methodCall, ast); 141 return matcher.matches(); 142 } 143 144 145 } 146 | Popular Tags |