1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jetspeed.services.statemanager;
19
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.Vector;
26 import java.util.Set;
27
28 import org.apache.jetspeed.services.statemanager.BaseStateManagerService;
29
30 /***
31 * <p>JetspeedStateManagerService is an implementation of the BaseStateManagerService
32 * which manages the states stored in a local Map (synchronized HashMap).</p>
33 * <p>Note: This implementation of the StateManagerService is independent of all other
34 * services; but it has no automatic way to retire no longer used state. If the
35 * application does not explicitly retire the states created, they will hang around
36 * forever. (see clear() and retireState() of the StateManagerService).</p>
37 * @version $Revision: 1.6 $
38 * @see org.apache.jetspeed.services.statemanager.BaseStateManagerService
39 * @see org.apache.jetspeed.services.statemanager.StateManagerService
40 * @see org.apache.jetspeed.services.statemanager.SessionState
41 * @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
42 */
43 public class JetspeedStateManagerService
44 extends BaseStateManagerService
45 {
46 /*** Store each set of state parameters by state key
47 (each is a HashMap keyed by parameter name) */
48 private Map m_states = null;
49
50 /***
51 * Initialize the states storage.
52 */
53 protected void initStates()
54 {
55
56 m_states = Collections.synchronizedMap(new HashMap());
57
58 }
59
60 /***
61 * Cleanup the states storage.
62 */
63 protected void shutdownStates()
64 {
65 m_states.clear();
66 m_states = null;
67
68 }
69
70 /***
71 * Access the Map which is the set of attributes for a state.
72 * @param key The state key.
73 * @return The Map which is the set of attributes for a state.
74 */
75 protected Map getState( String key )
76 {
77 return (Map) m_states.get(key);
78
79 }
80
81 /***
82 * Add a new state to the states we are managing.
83 * @param key The state key.
84 * @param state The Map which is the set of attributes for the state.
85 */
86 protected void addState( String key, Map state )
87 {
88 m_states.put(key, state);
89
90 }
91
92 /***
93 * Remove a state from the states we are managing.
94 * @param key The state key.
95 */
96 protected void removeState( String key )
97 {
98 m_states.remove(key);
99
100 }
101
102 /***
103 * Access an array of the keys of all states managed, those that start with the parameter.
104 * @param start The starting string used to select the keys.
105 * @return an array of the keys of all states managed.
106 */
107 protected String[] getStateKeys( String start )
108 {
109
110 Vector rv = new Vector();
111
112
113 Set allStateKeys = m_states.keySet();
114 synchronized (m_states)
115 {
116 Iterator i = allStateKeys.iterator();
117 while (i.hasNext())
118 {
119 String key = (String) i.next();
120
121
122 if (key.startsWith(start))
123 {
124 rv.add(key);
125 }
126 }
127 }
128
129 if (rv.size() == 0) return null;
130
131 return (String[]) rv.toArray(new String[rv.size()]);
132
133 }
134
135 }
136
137 /***********************************************************************************
138 *
139 * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedStateManagerService.java,v 1.6 2004/02/23 03:38:28 jford Exp $
140 *
141 **********************************************************************************/
142