1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import ognl.Ognl; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.tapestry.event.ResetEventListener; 24 import org.apache.tapestry.services.ExpressionCache; 25 26 30 public class ExpressionCacheImpl implements ExpressionCache, ResetEventListener 31 { 32 public synchronized void resetEventDidOccur() 33 { 34 _cache.clear(); 35 } 36 37 private Map _cache = new HashMap (); 38 39 public synchronized Object getCompiledExpression(String expression) 40 { 41 Object result = _cache.get(expression); 42 43 if (result == null) 44 { 45 result = parse(expression); 46 _cache.put(expression, result); 47 } 48 49 return result; 50 } 51 52 private Object parse(String expression) 53 { 54 try 55 { 56 return Ognl.parseExpression(expression); 57 } 58 catch (Exception ex) 59 { 60 throw new ApplicationRuntimeException(ImplMessages.unableToParseExpression( 61 expression, 62 ex), ex); 63 } 64 } 65 66 } | Popular Tags |