KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > MapStateMap


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: MapStateMap.java,v 1.4 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.data;
21
22 import java.io.*;
23 import java.util.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 /**
28  * The implementation provides a StateMap bridge to a Map
29  * object. By this, we mean that this class allows you to treat an
30  * Map as a StateMap.
31  */

32 public class MapStateMap implements StateMap {
33
34     //private vars
35
protected Map map = null;
36     
37     /**
38      * Public constructor.
39      *
40      * @param imap the underlying servlet map structure
41      */

42     public MapStateMap(Map imap) {
43         map = imap;
44     }
45     
46     /**
47      * set a property in this StateMap
48      *
49      * @param key the key object
50      * @param val the value object
51      */

52     public void putState(Object JavaDoc key, Object JavaDoc val) {
53         map.put(key,val);
54     }
55     
56     /**
57      * get a property in this StateMap
58      *
59      * @param key the key object
60      * @return the value for the given key
61      */

62     public Object JavaDoc getState(Object JavaDoc key) {
63         return map.get(key);
64     }
65     
66     /**
67      * remove a property in this StateMap
68      *
69      * @param key the key object
70      * @return the object which was removed
71      */

72     public Object JavaDoc removeState(Object JavaDoc key) {
73         return map.remove(key);
74     }
75     
76     /**
77      * get a List of the keys for this StateMap (implementation
78      * is an ArrayList)
79      *
80      * @return a List the keys for this StateMap
81      */

82     public List getStateKeys() {
83         return new ArrayList(map.keySet());
84     }
85     
86     /**
87      * get a copy of the underlying Map (in this case, we
88      * map all the attributes of the Map structure
89      * into a Map and return that)
90      *
91      * @return a copy of the underlying state Map
92      */

93     public Map getStateValues() {
94         return map;
95     }
96     
97     //csc_052803_2 - added
98
/**
99      * clear all state information
100      */

101     public void clearState() {
102         map.clear();
103     }
104     
105 }
106
Popular Tags