|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ApplicationStateManagerImpl.java | 100% | 87.5% | 85.7% | 88.9% |
|
1 |
// Copyright 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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.PoolManageable;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* This implementation expects to be pooled.
|
|
25 |
*
|
|
26 |
* @author Howard M. Lewis Ship
|
|
27 |
* @since 4.0
|
|
28 |
*/
|
|
29 |
public class ApplicationStateManagerImpl implements ApplicationStateManager, PoolManageable |
|
30 |
{ |
|
31 |
|
|
32 |
/**
|
|
33 |
* Keyed on application static object name, value is the current state object.
|
|
34 |
*/
|
|
35 |
|
|
36 |
private Map _stateObjects = new HashMap(); |
|
37 |
|
|
38 |
private StateObjectManagerRegistry _registry;
|
|
39 |
|
|
40 | 148 |
public void activateService() |
41 |
{ |
|
42 |
} |
|
43 |
|
|
44 | 149 |
public void passivateService() |
45 |
{ |
|
46 | 149 |
_stateObjects.clear(); |
47 |
} |
|
48 |
|
|
49 | 2 |
public boolean exists(String objectName) |
50 |
{ |
|
51 | 2 |
return _stateObjects.containsKey(objectName) || _registry.get(objectName).exists();
|
52 |
} |
|
53 |
|
|
54 | 9 |
public Object get(String objectName)
|
55 |
{ |
|
56 | 9 |
Object result = _stateObjects.get(objectName); |
57 |
|
|
58 | 9 |
if (result == null) |
59 |
{ |
|
60 | 8 |
result = _registry.get(objectName).get(); |
61 |
|
|
62 | 7 |
_stateObjects.put(objectName, result); |
63 |
} |
|
64 |
|
|
65 | 8 |
return result;
|
66 |
} |
|
67 |
|
|
68 | 0 |
public void store(String objectName, Object stateObject) |
69 |
{ |
|
70 | 0 |
_registry.get(objectName).store(stateObject); |
71 |
|
|
72 | 0 |
_stateObjects.put(objectName, stateObject); |
73 |
} |
|
74 |
|
|
75 | 149 |
public void flush() |
76 |
{ |
|
77 | 149 |
Iterator i = _stateObjects.entrySet().iterator(); |
78 | 149 |
while (i.hasNext())
|
79 |
{ |
|
80 | 4 |
Map.Entry e = (Map.Entry) i.next(); |
81 |
|
|
82 | 4 |
String objectName = (String) e.getKey(); |
83 | 4 |
Object stateObject = e.getValue(); |
84 |
|
|
85 |
// Slight bending of law-of-demeter
|
|
86 |
|
|
87 | 4 |
_registry.get(objectName).store(stateObject); |
88 |
} |
|
89 |
} |
|
90 |
|
|
91 | 49 |
public void setRegistry(StateObjectManagerRegistry registry) |
92 |
{ |
|
93 | 49 |
_registry = registry; |
94 |
} |
|
95 |
} |
|