View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.context.portlet;
20  
21  import java.util.Enumeration;
22  import java.util.Map;
23  
24  import javax.portlet.PortletRequest;
25  import javax.portlet.PortletSession;
26  
27  import org.apache.myfaces.shared_impl.util.NullEnumeration;
28  import org.apache.myfaces.util.AbstractThreadSafeAttributeMap;
29  
30  /**
31   * Portlet scope PortletSession attibutes as Map.
32   *
33   * @author  Stan Silvert (latest modification by $Author: lu4242 $)
34   * @version $Revision: 1000660 $ $Date: 2010-09-23 18:02:43 -0500 (Thu, 23 Sep 2010) $
35   */
36  public class SessionMap extends AbstractThreadSafeAttributeMap
37  {
38      private final PortletRequest _portletRequest;
39  
40      SessionMap(PortletRequest portletRequest)
41      {
42          _portletRequest = portletRequest;
43      }
44  
45      protected Object getAttribute(String 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 key, Object value)
53      {
54          _portletRequest.getPortletSession(true).setAttribute(key, value, PortletSession.PORTLET_SCOPE);
55      }
56  
57      protected void removeAttribute(String 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  
79      public void putAll(Map t)
80      {
81          throw new UnsupportedOperationException();
82      }
83  
84  
85      public void clear()
86      {
87          throw new UnsupportedOperationException();
88      }
89  }