1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
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 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| public class ExpressionCacheImpl implements ExpressionCache, ResetEventListener |
31 |
| { |
32 |
1
| public synchronized void resetEventDidOccur()
|
33 |
| { |
34 |
1
| _cache.clear();
|
35 |
| } |
36 |
| |
37 |
| private Map _cache = new HashMap(); |
38 |
| |
39 |
1838
| public synchronized Object getCompiledExpression(String expression)
|
40 |
| { |
41 |
1838
| Object result = _cache.get(expression);
|
42 |
| |
43 |
1838
| if (result == null)
|
44 |
| { |
45 |
547
| result = parse(expression);
|
46 |
546
| _cache.put(expression, result);
|
47 |
| } |
48 |
| |
49 |
1837
| return result;
|
50 |
| } |
51 |
| |
52 |
547
| private Object parse(String expression)
|
53 |
| { |
54 |
547
| try
|
55 |
| { |
56 |
547
| return Ognl.parseExpression(expression);
|
57 |
| } |
58 |
| catch (Exception ex) |
59 |
| { |
60 |
1
| throw new ApplicationRuntimeException(ImplMessages.unableToParseExpression(
|
61 |
| expression, |
62 |
| ex), ex); |
63 |
| } |
64 |
| } |
65 |
| |
66 |
| } |