1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.AspectManager; 25 import org.jboss.aop.joinpoint.Invocation; 26 import org.jboss.aop.pointcut.ast.ASTAndCFlow; 27 import org.jboss.aop.pointcut.ast.ASTCFlow; 28 import org.jboss.aop.pointcut.ast.ASTCFlowBoolean; 29 import org.jboss.aop.pointcut.ast.ASTCFlowExpression; 30 import org.jboss.aop.pointcut.ast.ASTCompositeCFlow; 31 import org.jboss.aop.pointcut.ast.ASTNotCFlow; 32 import org.jboss.aop.pointcut.ast.ASTOrCFlow; 33 import org.jboss.aop.pointcut.ast.ASTSubCFlow; 34 import org.jboss.aop.pointcut.ast.Node; 35 36 42 public class CFlowMatcher extends MatcherHelper 43 { 44 StackTraceElement [] stack; 45 Invocation invocation; 46 47 public CFlowMatcher() 48 { 49 super(null, null); 50 } 51 52 public boolean matches(ASTCFlowExpression expr, Invocation invocation) 53 { 54 this.invocation = invocation; 55 Boolean rtn = (Boolean ) expr.jjtAccept(this, null); 56 return rtn.booleanValue(); 57 } 58 59 private StackTraceElement [] getStack() 60 { 61 stack = new Throwable ().getStackTrace(); 62 return stack; 63 } 64 65 protected Boolean resolvePointcut(Pointcut p) 66 { 67 throw new RuntimeException ("SHOULD NOT BE REACHABLE"); 68 } 69 70 71 public Object visit(ASTCFlowExpression node, Object data) 72 { 73 return node.jjtGetChild(0).jjtAccept(this, data); 74 } 75 76 public Object visit(ASTCFlowBoolean node, Object data) 77 { 78 return node.jjtGetChild(0).jjtAccept(this, data); 79 } 80 81 public Object visit(ASTNotCFlow node, Object data) 82 { 83 Boolean bool = (Boolean ) node.jjtGetChild(0).jjtAccept(this, data); 84 boolean val = bool.booleanValue(); 85 return val ? Boolean.FALSE : Boolean.TRUE; 86 } 87 88 public Object visit(ASTCompositeCFlow node, Object data) 89 { 90 return node.jjtGetChild(0).jjtAccept(this, data); 91 } 92 93 public Object visit(ASTSubCFlow node, Object data) 94 { 95 for (int i = 0; i < node.jjtGetNumChildren(); i++) 96 { 97 data = node.jjtGetChild(i).jjtAccept(this, data); 98 } 99 return data; 100 } 101 102 public Object visit(ASTAndCFlow node, Object left) 103 { 104 Node andChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 106 return new Boolean (val && ((Boolean ) andChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 107 } 108 109 public Object visit(ASTOrCFlow node, Object left) 110 { 111 Node orChild = node.jjtGetChild(0); boolean val = ((Boolean ) left).booleanValue(); 113 return new Boolean (val || ((Boolean ) orChild.jjtAccept(this, Boolean.FALSE)).booleanValue()); 114 } 115 116 public Object visit(ASTCFlow node, Object data) 117 { 118 AspectManager manager = null; 119 if (invocation.getAdvisor() == null) 120 manager = AspectManager.instance(); 121 else 122 manager = invocation.getAdvisor().getManager(); 123 CFlowStack cflow = manager.getCFlowStack(node.getPointcutName()); 124 if (cflow != null) return new Boolean (cflow.matches(getStack())); 125 126 DynamicCFlow dcflow = manager.getDynamicCFlow(node.getPointcutName()); 127 return new Boolean (dcflow.shouldExecute(invocation)); 128 } 129 } 130 | Popular Tags |