1 4 package com.tc.object.bytecode.aspectwerkz; 5 6 import com.tc.aspectwerkz.expression.ExpressionVisitor; 7 import com.tc.aspectwerkz.expression.ExpressionInfo; 8 import com.tc.aspectwerkz.expression.ExpressionContext; 9 import com.tc.aspectwerkz.expression.PointcutType; 10 import com.tc.aspectwerkz.reflect.MemberInfo; 11 import com.tc.aspectwerkz.reflect.ClassInfo; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 19 public class ExpressionHelper { 20 21 private final Map expressionInfoCache = new HashMap (); 22 23 public ExpressionVisitor[] createExpressionVisitors(String [] expressions) { 24 ExpressionVisitor[] rv = null; 25 if (expressions == null) { 26 rv = new ExpressionVisitor[] {}; 27 } else { 28 rv = new ExpressionVisitor[expressions.length]; 29 for (int i = 0; i < expressions.length; i++) { 30 rv[i] = createExpressionVisitor(expressions[i]); 31 } 32 } 33 return rv; 34 } 35 36 40 public ExpressionVisitor createExpressionVisitor(String expression) { 41 return createExpressionInfo(expression).getExpression(); 42 } 43 44 48 public ExpressionInfo createExpressionInfo(String expression) { 49 return createExpressionInfo(expression, "__tc_default"); 50 } 51 52 56 public ExpressionInfo createExpressionInfo(String expression, String namespace) { 57 ExpressionInfo info; 58 synchronized (expressionInfoCache) { 59 info = (ExpressionInfo) expressionInfoCache.get(expression); 60 if (info == null) { 61 info = new ExpressionInfo(expression, namespace); 62 expressionInfoCache.put(expression, info); 63 } 64 } 65 return info; 66 } 67 68 71 public static String [] expressionPatterns2WithinExpressions(String [] expressions) { 72 String [] rv = null; 73 if (expressions == null) { 74 rv = new String [0]; 75 } else { 76 rv = new String [expressions.length]; 77 for (int i=0; i<expressions.length; i++) { 78 rv[i] = expressionPattern2WithinExpression(expressions[i]); 79 } 80 } 81 return rv; 82 } 83 84 87 public static String expressionPattern2WithinExpression(String expression) { 88 return "within(" + expression + ")"; 89 } 90 91 public static String expressionPattern2ExecutionExpression(String expression) { 92 return "execution(" + expression + ")"; 93 } 94 95 99 public ExpressionContext createWithinExpressionContext(ClassInfo classInfo) { 100 ExpressionContext ctxt = new ExpressionContext(PointcutType.WITHIN, classInfo, classInfo); 102 return ctxt; 103 } 104 105 109 public ExpressionContext createExecutionExpressionContext(MemberInfo methodInfo) { 110 ExpressionContext ctxt = new ExpressionContext(PointcutType.EXECUTION, methodInfo, methodInfo); 112 return ctxt; 113 } 114 } | Popular Tags |