1 package org.apache.turbine.services.pull.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Map;
20 import java.util.HashMap;
21 import java.util.Iterator;
22
23 import org.apache.turbine.services.pull.ApplicationTool;
24
25 /***
26 * Pull tool designed to be used in the session scope for storage of
27 * temporary data. This tool should eliminate the need for the
28 * {@link org.apache.turbine.om.security.User#setTemp} and
29 * {@link org.apache.turbine.om.security.User#getTemp} methods.
30 *
31 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
32 * @version $Id: SessionData.java 264148 2005-08-29 14:21:04Z henning $
33 */
34 public class SessionData implements ApplicationTool
35 {
36 /*** Storage of user defined data */
37 private Map dataStorage;
38
39 /***
40 * Initialize the application tool.
41 *
42 * @param data initialization data
43 */
44 public void init(Object data)
45 {
46 dataStorage = new HashMap();
47 }
48
49 /***
50 * Refresh the application tool.
51 */
52 public void refresh()
53 {
54
55 }
56
57 /***
58 * Gets the data stored under the key. Null will be returned if the
59 * key does not exist or if null was stored under the key.
60 * <p>
61 * To check for a key with a null value use {@link #containsKey}.
62 *
63 * @param key key under which the data is stored.
64 * @return <code>Object</code> stored under the key.
65 */
66 public Object get(String key)
67 {
68 return dataStorage.get(key);
69 }
70
71 /***
72 * Determines is a given key is stored.
73 *
74 * @param key the key to check for
75 * @return true if the key was found
76 */
77 public boolean containsKey(String key)
78 {
79 return dataStorage.containsKey(key);
80 }
81
82 /***
83 * Stores the data. If the key already exists, the value will be
84 * overwritten.
85 *
86 * @param key key under which the data will be stored.
87 * @param value data to store under the key. Null values are allowed.
88 */
89 public void put(String key, Object value)
90 {
91 dataStorage.put(key, value);
92 }
93
94 /***
95 * Clears all data
96 */
97 public void clear()
98 {
99 dataStorage.clear();
100 }
101
102 /***
103 * Gets a iterator for the keys.
104 *
105 * @return <code>Iterator</code> for the keys
106 */
107 public Iterator iterator()
108 {
109 return dataStorage.keySet().iterator();
110 }
111 }