Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 93   Methods: 7
NCLOC: 51   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SessionScopeManager.java 100% 100% 100% 100%
coverage
 1   
 // Copyright 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.engine.state;
 16   
 
 17   
 import javax.servlet.http.HttpServletRequest;
 18   
 import javax.servlet.http.HttpSession;
 19   
 
 20   
 /**
 21   
  * Manager for the 'session' scope; state objects are stored as HttpSession attributes. The
 22   
  * HttpSession is created as necessary.
 23   
  * 
 24   
  * @author Howard M. Lewis Ship
 25   
  * @since 3.1
 26   
  */
 27   
 public class SessionScopeManager implements StateObjectPersistenceManager
 28   
 {
 29   
     private HttpServletRequest _request;
 30   
 
 31   
     private String _applicationId;
 32   
 
 33  11
     private String buildKey(String objectName)
 34   
     {
 35  11
         return "state:" + _applicationId + ":" + objectName;
 36   
     }
 37   
 
 38   
     /**
 39   
      * Returns the session for the current request, creating it if necessary.
 40   
      */
 41   
 
 42  9
     private HttpSession getSession()
 43   
     {
 44  9
         return _request.getSession();
 45   
     }
 46   
 
 47  3
     public boolean exists(String objectName)
 48   
     {
 49  3
         HttpSession session = _request.getSession(false);
 50   
 
 51  3
         if (session == null)
 52  1
             return false;
 53   
 
 54  2
         return session.getAttribute(buildKey(objectName)) != null;
 55   
     }
 56   
 
 57  5
     public Object get(String objectName, StateObjectFactory factory)
 58   
     {
 59  5
         String key = buildKey(objectName);
 60  5
         HttpSession session = getSession();
 61   
 
 62  5
         Object result = session.getAttribute(key);
 63  4
         if (result == null)
 64   
         {
 65  3
             result = factory.createStateObject();
 66  3
             session.setAttribute(key, result);
 67   
         }
 68   
 
 69  4
         return result;
 70   
     }
 71   
 
 72  4
     public void store(String objectName, Object stateObject)
 73   
     {
 74  4
         String key = buildKey(objectName);
 75   
 
 76  4
         HttpSession session = getSession();
 77   
 
 78  4
         if (stateObject == null)
 79  1
             session.removeAttribute(key);
 80   
         else
 81  3
             session.setAttribute(key, stateObject);
 82   
     }
 83   
 
 84  9
     public void setApplicationId(String applicationName)
 85   
     {
 86  9
         _applicationId = applicationName;
 87   
     }
 88   
 
 89  10
     public void setRequest(HttpServletRequest request)
 90   
     {
 91  10
         _request = request;
 92   
     }
 93   
 }