Coverage Report - org.apache.myfaces.context.portlet.SessionMap
 
Classes in this File Line Coverage Branch Coverage Complexity
SessionMap
0%
0/23
0%
0/10
0
 
 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 org.apache.myfaces.shared_impl.util.NullEnumeration;
 22  
 import org.apache.myfaces.util.AbstractAttributeMap;
 23  
 
 24  
 import java.util.Enumeration;
 25  
 import java.util.Map;
 26  
 import javax.portlet.PortletRequest;
 27  
 import javax.portlet.PortletSession;
 28  
 
 29  
 /**
 30  
  * Portlet scope PortletSession attibutes as Map.
 31  
  *
 32  
  * @author  Stan Silvert (latest modification by $Author: bommel $)
 33  
  * @version $Revision: 693059 $ $Date: 2008-09-08 06:42:28 -0500 (Mon, 08 Sep 2008) $
 34  
  */
 35  
 public class SessionMap extends AbstractAttributeMap<Object>
 36  
 {
 37  
     private final PortletRequest _portletRequest;
 38  
 
 39  
     SessionMap(PortletRequest portletRequest)
 40  0
     {
 41  0
         _portletRequest = portletRequest;
 42  0
     }
 43  
 
 44  
     @Override
 45  
     protected Object getAttribute(String key)
 46  
     {
 47  0
         PortletSession portletSession = getSession();
 48  0
         return (portletSession == null)
 49  
                ? null : portletSession.getAttribute(key, PortletSession.PORTLET_SCOPE);
 50  
     }
 51  
 
 52  
     @Override
 53  
     protected void setAttribute(String key, Object value)
 54  
     {
 55  0
         _portletRequest.getPortletSession(true).setAttribute(key, value, PortletSession.PORTLET_SCOPE);
 56  0
     }
 57  
 
 58  
     @Override
 59  
     protected void removeAttribute(String key)
 60  
     {
 61  0
         PortletSession portletSession = getSession();
 62  0
         if (portletSession != null)
 63  
         {
 64  0
             portletSession.removeAttribute(key, PortletSession.PORTLET_SCOPE);
 65  
         }
 66  0
     }
 67  
 
 68  
     @Override
 69  
     @SuppressWarnings("unchecked")
 70  
     protected Enumeration<String> getAttributeNames()
 71  
     {
 72  0
         PortletSession portletSession = getSession();
 73  0
         return (portletSession == null)
 74  
                ? NullEnumeration.instance()
 75  
                : portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE);
 76  
     }
 77  
 
 78  
     private PortletSession getSession()
 79  
     {
 80  0
         return _portletRequest.getPortletSession(false);
 81  
     }
 82  
 
 83  
     @Override
 84  
     public void putAll(Map t)
 85  
     {
 86  0
         throw new UnsupportedOperationException();
 87  
     }
 88  
 
 89  
 
 90  
     /**
 91  
      * This will clear the session without invalidation.  If no session has
 92  
      * been created, it will simply return.
 93  
      */
 94  
     @Override
 95  
     public void clear()
 96  
     {
 97  0
         PortletSession session = getSession();
 98  0
         if (session == null) return;
 99  0
         for (Enumeration attributeNames = session.getAttributeNames(PortletSession.PORTLET_SCOPE); 
 100  0
              attributeNames.hasMoreElements(); ) {
 101  0
             String attributeName = (String)attributeNames.nextElement();
 102  0
             session.removeAttribute(attributeName);
 103  0
         }
 104  0
     }
 105  
 }