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 org.apache.hivemind.ErrorLog; |
21 |
| import org.apache.hivemind.Location; |
22 |
| import org.apache.hivemind.internal.Module; |
23 |
| import org.apache.hivemind.service.ObjectProvider; |
24 |
| import org.apache.hivemind.util.PropertyUtils; |
25 |
| import org.apache.tapestry.services.Infrastructure; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class InfrastructureObjectProvider implements ObjectProvider |
37 |
| { |
38 |
| private ErrorLog _errorLog; |
39 |
| |
40 |
| private Infrastructure _infrastructure; |
41 |
| |
42 |
| private Map _cache = new HashMap(); |
43 |
| |
44 |
1863
| public synchronized Object provideObject(Module contributingModule, Class propertyType,
|
45 |
| String locator, Location location) |
46 |
| { |
47 |
1863
| Object result = _cache.get(locator);
|
48 |
| |
49 |
1863
| if (result == null)
|
50 |
| { |
51 |
812
| result = readProperty(locator, location);
|
52 |
812
| _cache.put(locator, result);
|
53 |
| } |
54 |
| |
55 |
1863
| return result;
|
56 |
| } |
57 |
| |
58 |
812
| Object readProperty(String locator, Location location)
|
59 |
| { |
60 |
812
| try
|
61 |
| { |
62 |
812
| if (PropertyUtils.isReadable(_infrastructure, locator))
|
63 |
793
| return PropertyUtils.read(_infrastructure, locator);
|
64 |
| |
65 |
19
| return _infrastructure.getProperty(locator);
|
66 |
| } |
67 |
| catch (Throwable ex) |
68 |
| { |
69 |
0
| _errorLog.error(ImplMessages.unableToReadInfrastructureProperty(
|
70 |
| locator, |
71 |
| _infrastructure, |
72 |
| ex), location, ex); |
73 |
| |
74 |
0
| return null;
|
75 |
| } |
76 |
| } |
77 |
| |
78 |
41
| public void setErrorLog(ErrorLog errorLog)
|
79 |
| { |
80 |
41
| _errorLog = errorLog;
|
81 |
| } |
82 |
| |
83 |
42
| public void setInfrastructure(Infrastructure infrastructure)
|
84 |
| { |
85 |
42
| _infrastructure = infrastructure;
|
86 |
| } |
87 |
| |
88 |
| } |