KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > portlet > SessionMap


1 /*
2  * Copyright 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.myfaces.context.portlet;
17
18 import org.apache.myfaces.util.NullEnumeration;
19
20 import java.util.Enumeration JavaDoc;
21 import javax.portlet.PortletRequest;
22 import javax.portlet.PortletSession;
23 import org.apache.myfaces.context.servlet.AbstractAttributeMap;
24
25 /**
26  * Portlet scope PortletSession attibutes as Map.
27  *
28  * @author Stan Silvert (latest modification by $Author: matzew $)
29  * @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
30  * $Log: SessionMap.java,v $
31  * Revision 1.1 2005/01/26 17:03:09 matzew
32  * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
33  *
34  *
35  */

36 public class SessionMap extends AbstractAttributeMap
37 {
38     private final PortletRequest _portletRequest;
39
40     SessionMap(PortletRequest portletRequest)
41     {
42         _portletRequest = portletRequest;
43     }
44
45     protected Object JavaDoc getAttribute(String JavaDoc key)
46     {
47         PortletSession portletSession = getSession();
48         return (portletSession == null)
49             ? null : portletSession.getAttribute(key.toString(), PortletSession.PORTLET_SCOPE);
50     }
51
52     protected void setAttribute(String JavaDoc key, Object JavaDoc value)
53     {
54         _portletRequest.getPortletSession(true).setAttribute(key, value, PortletSession.PORTLET_SCOPE);
55     }
56
57     protected void removeAttribute(String JavaDoc key)
58     {
59         PortletSession portletSession = getSession();
60         if (portletSession != null)
61         {
62             portletSession.removeAttribute(key, PortletSession.PORTLET_SCOPE);
63         }
64     }
65
66     protected Enumeration getAttributeNames()
67     {
68         PortletSession portletSession = getSession();
69         return (portletSession == null)
70             ? NullEnumeration.instance()
71             : portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE);
72     }
73     
74     private PortletSession getSession()
75     {
76         return _portletRequest.getPortletSession(false);
77     }
78 }
Popular Tags