1 4 package com.tc.aspectwerkz.expression; 5 6 import com.tc.aspectwerkz.exception.DefinitionException; 7 8 import java.util.HashMap ; 9 import java.util.Map ; 10 import java.util.WeakHashMap ; 11 12 18 public final class ExpressionNamespace { 19 22 private static final Map s_namespaces = new WeakHashMap (); 23 24 27 private final Map m_expressions = new HashMap (); 28 29 32 private final String m_namespace; 33 34 39 private ExpressionNamespace(final String namespace) { 40 m_namespace = namespace; 41 } 42 43 49 public static synchronized ExpressionNamespace getNamespace(final String namespace) { 50 if (!s_namespaces.containsKey(namespace)) { 51 s_namespaces.put(namespace, new ExpressionNamespace(namespace)); 52 } 53 return (ExpressionNamespace) s_namespaces.get(namespace); 54 } 55 56 62 public void addExpressionInfo(final String name, final ExpressionInfo expressionInfo) { 63 m_expressions.put(name, expressionInfo); 64 } 65 66 72 public ExpressionInfo getExpressionInfoOrNull(final String name) { 73 int index = name.lastIndexOf('.'); 74 if (index != -1) { 75 return getNamespace(name.substring(0, index)).getExpressionInfoOrNull( 78 name.substring(index + 1, name.length()) 79 ); 80 } else { 81 final ExpressionInfo expressionInfo = ((ExpressionInfo) m_expressions.get(name)); 82 return expressionInfo; 93 } 94 } 95 96 102 public ExpressionInfo getExpressionInfo(final String name) { 103 int index = name.lastIndexOf('.'); 104 if (index != -1) { 105 return getNamespace(name.substring(0, index)).getExpressionInfo(name.substring(index + 1, name.length())); 108 } else { 109 final ExpressionInfo expressionInfo = ((ExpressionInfo) m_expressions.get(name)); 110 if (expressionInfo == null) { 111 throw new DefinitionException( 112 new StringBuffer (). 113 append("could not resolve reference to pointcut ["). 114 append(name). 115 append("] in namespace ["). 116 append(m_namespace). 117 append("]").toString() 118 ); 119 } 120 return expressionInfo; 121 } 122 } 123 124 130 public ExpressionVisitor getExpression(final String name) { 131 return getExpressionInfo(name).getExpression(); 132 } 133 134 140 public AdvisedClassFilterExpressionVisitor getAdvisedClassExpression(final String name) { 141 return getExpressionInfo(name).getAdvisedClassFilterExpression(); 142 } 143 144 149 public String getName() { 150 return m_namespace; 151 } 152 } | Popular Tags |