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.ReportStatusEvent; |
24 |
| import org.apache.tapestry.event.ReportStatusListener; |
25 |
| import org.apache.tapestry.event.ResetEventListener; |
26 |
| import org.apache.tapestry.services.ExpressionCache; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class ExpressionCacheImpl implements ExpressionCache, ResetEventListener, |
33 |
| ReportStatusListener |
34 |
| { |
35 |
| private String _serviceId; |
36 |
| |
37 |
| private Map _cache = new HashMap(); |
38 |
| |
39 |
1
| public synchronized void resetEventDidOccur()
|
40 |
| { |
41 |
1
| _cache.clear();
|
42 |
| } |
43 |
| |
44 |
17
| public void reportStatus(ReportStatusEvent event)
|
45 |
| { |
46 |
17
| event.title(_serviceId);
|
47 |
| |
48 |
17
| event.property("cached expression count", _cache.size());
|
49 |
17
| event.collection("cached expressions", _cache.keySet());
|
50 |
| } |
51 |
| |
52 |
1897
| public synchronized Object getCompiledExpression(String expression)
|
53 |
| { |
54 |
1897
| Object result = _cache.get(expression);
|
55 |
| |
56 |
1897
| if (result == null)
|
57 |
| { |
58 |
530
| result = parse(expression);
|
59 |
529
| _cache.put(expression, result);
|
60 |
| } |
61 |
| |
62 |
1896
| return result;
|
63 |
| } |
64 |
| |
65 |
530
| private Object parse(String expression)
|
66 |
| { |
67 |
530
| try
|
68 |
| { |
69 |
530
| return Ognl.parseExpression(expression);
|
70 |
| } |
71 |
| catch (Exception ex) |
72 |
| { |
73 |
1
| throw new ApplicationRuntimeException(ImplMessages.unableToParseExpression(
|
74 |
| expression, |
75 |
| ex), ex); |
76 |
| } |
77 |
| } |
78 |
| |
79 |
38
| public void setServiceId(String serviceId)
|
80 |
| { |
81 |
38
| _serviceId = serviceId;
|
82 |
| } |
83 |
| |
84 |
| } |