1/*2 * Copyright 2000-2002,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617// package18packageorg.apache.jetspeed.services.statemanager;
1920// imports21import java.util.HashMap;
22import java.util.Map;
23import java.util.Collections;
24import java.util.Iterator;
25import java.util.Vector;
26import java.util.Set;
2728import org.apache.jetspeed.services.statemanager.BaseStateManagerService;
2930/***31* <p>JetspeedStateManagerService is an implementation of the BaseStateManagerService32* which manages the states stored in a local Map (synchronized HashMap).</p>33* <p>Note: This implementation of the StateManagerService is independent of all other34* services; but it has no automatic way to retire no longer used state. If the35* application does not explicitly retire the states created, they will hang around36* forever. (see clear() and retireState() of the StateManagerService).</p>37* @version $Revision: 1.6 $38* @see org.apache.jetspeed.services.statemanager.BaseStateManagerService39* @see org.apache.jetspeed.services.statemanager.StateManagerService40* @see org.apache.jetspeed.services.statemanager.SessionState41* @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>42*/43publicclassJetspeedStateManagerService44extendsBaseStateManagerService45 {
46/*** Store each set of state parameters by state key47 (each is a HashMap keyed by parameter name) */48private Map m_states = null;
4950/***51 * Initialize the states storage.52 */53protectedvoid initStates()
54 {
55// create our states map synchronized56 m_states = Collections.synchronizedMap(new HashMap());
5758 } // initStates5960/***61 * Cleanup the states storage.62 */63protectedvoid shutdownStates()
64 {
65 m_states.clear();
66 m_states = null;
6768 } // shutdownStates6970/***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 */75protected Map getState( String key )
76 {
77return (Map) m_states.get(key);
7879 } // getState8081/***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 */86protectedvoid addState( String key, Map state )
87 {
88 m_states.put(key, state);
8990 } // addState9192/***93 * Remove a state from the states we are managing.94 * @param key The state key.95 */96protectedvoid removeState( String key )
97 {
98 m_states.remove(key);
99100 } // removeState101102/***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 */107protected String[] getStateKeys( String start )
108 {
109// collect for return110 Vector rv = new Vector();
111112// get the entire set of keys to iterate over113 Set allStateKeys = m_states.keySet();
114synchronized (m_states)
115 {
116 Iterator i = allStateKeys.iterator();
117while (i.hasNext())
118 {
119 String key = (String) i.next();
120121// if this matches our pattern122if (key.startsWith(start))
123 {
124 rv.add(key);
125 }
126 }
127 }
128129if (rv.size() == 0) returnnull;
130131return (String[]) rv.toArray(new String[rv.size()]);
132133 } // getStateKeys134135 } // JetspeedStateManagerService136137/***********************************************************************************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