1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.engine.state; |
16 | |
|
17 | |
import java.util.HashMap; |
18 | |
import java.util.Iterator; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.apache.hivemind.ApplicationRuntimeException; |
22 | |
import org.apache.hivemind.ErrorLog; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class SOMRegistryImpl implements StateObjectManagerRegistry |
29 | |
{ |
30 | |
|
31 | |
private ErrorLog _errorLog; |
32 | |
|
33 | |
private Map _factoryContributions; |
34 | |
|
35 | |
private Map _applicationContributions; |
36 | |
|
37 | |
private Map _persistenceManagers; |
38 | |
|
39 | 0 | private Map _objectManagers = new HashMap(); |
40 | |
|
41 | |
public void initializeService() |
42 | |
{ |
43 | 0 | Map contributions = new HashMap(); |
44 | 0 | contributions.putAll(_factoryContributions); |
45 | |
|
46 | 0 | contributions.putAll(_applicationContributions); |
47 | |
|
48 | 0 | Iterator i = contributions.values().iterator(); |
49 | 0 | while(i.hasNext()) |
50 | |
{ |
51 | 0 | StateObjectContribution c = (StateObjectContribution) i.next(); |
52 | |
|
53 | 0 | String objectName = c.getName(); |
54 | 0 | String scope = c.getScope(); |
55 | |
|
56 | 0 | StateObjectPersistenceManager pm = (StateObjectPersistenceManager) _persistenceManagers |
57 | |
.get(scope); |
58 | |
|
59 | 0 | if (pm == null) |
60 | |
{ |
61 | 0 | _errorLog.error(StateMessages.unknownScope(objectName, scope), |
62 | |
c.getLocation(), null); |
63 | 0 | continue; |
64 | |
} |
65 | |
|
66 | 0 | StateObjectManager manager = new StateObjectManagerImpl(objectName, |
67 | |
c.getFactory(), pm); |
68 | |
|
69 | 0 | _objectManagers.put(objectName, manager); |
70 | |
|
71 | 0 | } |
72 | 0 | } |
73 | |
|
74 | |
public StateObjectManager get(String objectName) |
75 | |
{ |
76 | 0 | StateObjectManager manager = (StateObjectManager) _objectManagers |
77 | |
.get(objectName); |
78 | |
|
79 | 0 | if (manager == null) |
80 | 0 | throw new ApplicationRuntimeException(StateMessages |
81 | |
.unknownStateObjectName(objectName)); |
82 | |
|
83 | 0 | return manager; |
84 | |
} |
85 | |
|
86 | |
public void setApplicationContributions(Map applicationContributions) |
87 | |
{ |
88 | 0 | _applicationContributions = applicationContributions; |
89 | 0 | } |
90 | |
|
91 | |
public void setErrorLog(ErrorLog errorLog) |
92 | |
{ |
93 | 0 | _errorLog = errorLog; |
94 | 0 | } |
95 | |
|
96 | |
public void setFactoryContributions(Map factoryContributions) |
97 | |
{ |
98 | 0 | _factoryContributions = factoryContributions; |
99 | 0 | } |
100 | |
|
101 | |
public void setPersistenceManagers(Map persistenceManagers) |
102 | |
{ |
103 | 0 | _persistenceManagers = persistenceManagers; |
104 | 0 | } |
105 | |
} |