KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > pull > util > SessionData


1 package org.apache.turbine.services.pull.util;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Map JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
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,v 1.1.2.2 2004/05/20 03:06:47 seade Exp $
33  */

34 public class SessionData implements ApplicationTool
35 {
36     /** Storage of user defined data */
37     private Map JavaDoc dataStorage;
38
39     /**
40      * Initialize the application tool.
41      *
42      * @param data initialization data
43      */

44     public void init(Object JavaDoc data)
45     {
46         dataStorage = new HashMap JavaDoc();
47     }
48
49     /**
50      * Refresh the application tool.
51      */

52     public void refresh()
53     {
54         // do nothing
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 JavaDoc get(String JavaDoc 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 JavaDoc 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 JavaDoc key, Object JavaDoc 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 JavaDoc iterator()
108     {
109         return dataStorage.keySet().iterator();
110     }
111 }
112
Popular Tags