View Javadoc

1   package org.apache.turbine.services.pull.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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          // do nothing
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 }