KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > context > SessionMap


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

16 package org.apache.cocoon.faces.context;
17
18 import org.apache.cocoon.environment.Session;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Set JavaDoc;
23
24 /**
25  * Session attributes map
26  *
27  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
28  * @version CVS $Id: SessionMap.java 46253 2004-09-17 14:36:29Z vgritsenko $
29  */

30 class SessionMap extends BaseMap {
31
32     private Session session;
33
34
35     SessionMap(Session session) {
36         this.session = session;
37     }
38
39     public Object JavaDoc get(Object JavaDoc key) {
40         return session.getAttribute(key.toString());
41     }
42
43     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
44         String JavaDoc sKey = key.toString();
45         Object JavaDoc old = session.getAttribute(sKey);
46         session.setAttribute(sKey, value);
47         return old;
48     }
49
50     public Object JavaDoc remove(Object JavaDoc key) {
51         String JavaDoc sKey = key.toString();
52         Object JavaDoc old = session.getAttribute(sKey);
53         session.removeAttribute(sKey);
54         return old;
55     }
56
57     public Set JavaDoc entrySet() {
58         Set JavaDoc entries = new HashSet JavaDoc();
59         for (Enumeration JavaDoc e = session.getAttributeNames(); e.hasMoreElements();) {
60             String JavaDoc name = (String JavaDoc) e.nextElement();
61             entries.add(new BaseMap.Entry(name, session.getAttribute(name)));
62         }
63
64         return entries;
65     }
66
67     public boolean equals(Object JavaDoc obj) {
68         if (obj == null || !(obj instanceof SessionMap)) {
69             return false;
70         }
71
72         return super.equals(obj);
73     }
74 }
75
Popular Tags