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