001: package org.apache.turbine.services.pull.util;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.Map;
023: import java.util.HashMap;
024: import java.util.Iterator;
025:
026: import org.apache.turbine.services.pull.ApplicationTool;
027:
028: /**
029: * Pull tool designed to be used in the session scope for storage of
030: * temporary data. This tool should eliminate the need for the
031: * {@link org.apache.turbine.om.security.User#setTemp} and
032: * {@link org.apache.turbine.om.security.User#getTemp} methods.
033: *
034: * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
035: * @version $Id: SessionData.java 534527 2007-05-02 16:10:59Z tv $
036: */
037: public class SessionData implements ApplicationTool {
038: /** Storage of user defined data */
039: private Map dataStorage;
040:
041: /**
042: * Initialize the application tool.
043: *
044: * @param data initialization data
045: */
046: public void init(Object data) {
047: dataStorage = new HashMap();
048: }
049:
050: /**
051: * Refresh the application tool.
052: */
053: public void refresh() {
054: // do nothing
055: }
056:
057: /**
058: * Gets the data stored under the key. Null will be returned if the
059: * key does not exist or if null was stored under the key.
060: * <p>
061: * To check for a key with a null value use {@link #containsKey}.
062: *
063: * @param key key under which the data is stored.
064: * @return <code>Object</code> stored under the key.
065: */
066: public Object get(String key) {
067: return dataStorage.get(key);
068: }
069:
070: /**
071: * Determines is a given key is stored.
072: *
073: * @param key the key to check for
074: * @return true if the key was found
075: */
076: public boolean containsKey(String key) {
077: return dataStorage.containsKey(key);
078: }
079:
080: /**
081: * Stores the data. If the key already exists, the value will be
082: * overwritten.
083: *
084: * @param key key under which the data will be stored.
085: * @param value data to store under the key. Null values are allowed.
086: */
087: public void put(String key, Object value) {
088: dataStorage.put(key, value);
089: }
090:
091: /**
092: * Clears all data
093: */
094: public void clear() {
095: dataStorage.clear();
096: }
097:
098: /**
099: * Gets a iterator for the keys.
100: *
101: * @return <code>Iterator</code> for the keys
102: */
103: public Iterator iterator() {
104: return dataStorage.keySet().iterator();
105: }
106: }
|