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 |
3 |
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 |
3 |
private Map _objectManagers = new HashMap(); |
40 |
|
|
41 |
|
public void initializeService() |
42 |
|
{ |
43 |
2 |
Map contributions = new HashMap(); |
44 |
2 |
contributions.putAll(_factoryContributions); |
45 |
|
|
46 |
2 |
contributions.putAll(_applicationContributions); |
47 |
|
|
48 |
2 |
Iterator i = contributions.values().iterator(); |
49 |
4 |
while(i.hasNext()) |
50 |
|
{ |
51 |
2 |
StateObjectContribution c = (StateObjectContribution) i.next(); |
52 |
|
|
53 |
2 |
String objectName = c.getName(); |
54 |
2 |
String scope = c.getScope(); |
55 |
|
|
56 |
2 |
StateObjectPersistenceManager pm = (StateObjectPersistenceManager) _persistenceManagers |
57 |
|
.get(scope); |
58 |
|
|
59 |
2 |
if (pm == null) |
60 |
|
{ |
61 |
1 |
_errorLog.error(StateMessages.unknownScope(objectName, scope), |
62 |
|
c.getLocation(), null); |
63 |
1 |
continue; |
64 |
|
} |
65 |
|
|
66 |
1 |
StateObjectManager manager = new StateObjectManagerImpl(objectName, |
67 |
|
c.getFactory(), pm); |
68 |
|
|
69 |
1 |
_objectManagers.put(objectName, manager); |
70 |
|
|
71 |
1 |
} |
72 |
2 |
} |
73 |
|
|
74 |
|
public StateObjectManager get(String objectName) |
75 |
|
{ |
76 |
2 |
StateObjectManager manager = (StateObjectManager) _objectManagers |
77 |
|
.get(objectName); |
78 |
|
|
79 |
2 |
if (manager == null) |
80 |
1 |
throw new ApplicationRuntimeException(StateMessages |
81 |
|
.unknownStateObjectName(objectName)); |
82 |
|
|
83 |
1 |
return manager; |
84 |
|
} |
85 |
|
|
86 |
|
public void setApplicationContributions(Map applicationContributions) |
87 |
|
{ |
88 |
2 |
_applicationContributions = applicationContributions; |
89 |
2 |
} |
90 |
|
|
91 |
|
public void setErrorLog(ErrorLog errorLog) |
92 |
|
{ |
93 |
1 |
_errorLog = errorLog; |
94 |
1 |
} |
95 |
|
|
96 |
|
public void setFactoryContributions(Map factoryContributions) |
97 |
|
{ |
98 |
2 |
_factoryContributions = factoryContributions; |
99 |
2 |
} |
100 |
|
|
101 |
|
public void setPersistenceManagers(Map persistenceManagers) |
102 |
|
{ |
103 |
2 |
_persistenceManagers = persistenceManagers; |
104 |
2 |
} |
105 |
|
} |