1 8 package org.codehaus.aspectwerkz.expression; 9 10 import org.codehaus.aspectwerkz.exception.DefinitionException; 11 12 import java.util.HashMap ; 13 import java.util.Map ; 14 import java.util.WeakHashMap ; 15 16 22 public final class ExpressionNamespace { 23 26 private static final Map s_namespaces = new WeakHashMap (); 27 28 31 private final Map m_expressions = new HashMap (); 32 33 36 private final String m_namespace; 37 38 43 private ExpressionNamespace(final String namespace) { 44 m_namespace = namespace; 45 } 46 47 53 public static synchronized ExpressionNamespace getNamespace(final String namespace) { 54 if (!s_namespaces.containsKey(namespace)) { 55 s_namespaces.put(namespace, new ExpressionNamespace(namespace)); 56 } 57 return (ExpressionNamespace) s_namespaces.get(namespace); 58 } 59 60 66 public void addExpressionInfo(final String name, final ExpressionInfo expressionInfo) { 67 m_expressions.put(name, expressionInfo); 68 } 69 70 76 public ExpressionInfo getExpressionInfoOrNull(final String name) { 77 int index = name.lastIndexOf('.'); 78 if (index != -1) { 79 return getNamespace(name.substring(0, index)).getExpressionInfoOrNull( 82 name.substring(index + 1, name.length()) 83 ); 84 } else { 85 final ExpressionInfo expressionInfo = ((ExpressionInfo) m_expressions.get(name)); 86 return expressionInfo; 97 } 98 } 99 100 106 public ExpressionInfo getExpressionInfo(final String name) { 107 int index = name.lastIndexOf('.'); 108 if (index != -1) { 109 return getNamespace(name.substring(0, index)).getExpressionInfo(name.substring(index + 1, name.length())); 112 } else { 113 final ExpressionInfo expressionInfo = ((ExpressionInfo) m_expressions.get(name)); 114 if (expressionInfo == null) { 115 throw new DefinitionException( 116 new StringBuffer (). 117 append("could not resolve reference to pointcut ["). 118 append(name). 119 append("] in namespace ["). 120 append(m_namespace). 121 append("]").toString() 122 ); 123 } 124 return expressionInfo; 125 } 126 } 127 128 134 public ExpressionVisitor getExpression(final String name) { 135 return getExpressionInfo(name).getExpression(); 136 } 137 138 144 public AdvisedClassFilterExpressionVisitor getAdvisedClassExpression(final String name) { 145 return getExpressionInfo(name).getAdvisedClassFilterExpression(); 146 } 147 148 153 public String getName() { 154 return m_namespace; 155 } 156 } | Popular Tags |