Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 93   Methods: 7
NCLOC: 48   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 org.apache.tapestry.web.WebRequest;
 18   
 import org.apache.tapestry.web.WebSession;
 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 4.0
 26   
  */
 27   
 public class SessionScopeManager implements StateObjectPersistenceManager
 28   
 {
 29   
     private WebRequest _request;
 30   
 
 31   
     private String _applicationId;
 32   
 
 33  10
     private String buildKey(String objectName)
 34   
     {
 35   
         // For Portlets, the application id is going to be somewhat redundant, since
 36   
         // the Portlet API keeps portlets seperate anyway.
 37   
 
 38  10
         return "state:" + _applicationId + ":" + objectName;
 39   
     }
 40   
 
 41   
     /**
 42   
      * Returns the session for the current request, creating it if necessary.
 43   
      */
 44   
 
 45  8
     private WebSession getSession()
 46   
     {
 47  8
         return _request.getSession(true);
 48   
     }
 49   
 
 50  3
     public boolean exists(String objectName)
 51   
     {
 52  3
         WebSession session = _request.getSession(false);
 53   
 
 54  3
         if (session == null)
 55  1
             return false;
 56   
 
 57  2
         return session.getAttribute(buildKey(objectName)) != null;
 58   
     }
 59   
 
 60  5
     public Object get(String objectName, StateObjectFactory factory)
 61   
     {
 62  5
         String key = buildKey(objectName);
 63  5
         WebSession session = getSession();
 64   
 
 65  5
         Object result = session.getAttribute(key);
 66  5
         if (result == null)
 67   
         {
 68  4
             result = factory.createStateObject();
 69  3
             session.setAttribute(key, result);
 70   
         }
 71   
 
 72  4
         return result;
 73   
     }
 74   
 
 75  3
     public void store(String objectName, Object stateObject)
 76   
     {
 77  3
         String key = buildKey(objectName);
 78   
 
 79  3
         WebSession session = getSession();
 80   
 
 81  3
         session.setAttribute(key, stateObject);
 82   
     }
 83   
 
 84  8
     public void setApplicationId(String applicationName)
 85   
     {
 86  8
         _applicationId = applicationName;
 87   
     }
 88   
 
 89  9
     public void setRequest(WebRequest request)
 90   
     {
 91  9
         _request = request;
 92   
     }
 93   
 }