Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.engine.state;
 
Manager for the 'session' scope; state objects are stored as HttpSession attributes. The HttpSession is created as necessary.

Author(s):
Howard M. Lewis Ship
Since:
4.0
 
 {
 
     private WebRequest _request;
 
     private String _applicationId;
 
     private String buildKey(String objectName)
     {
         // For Portlets, the application id is going to be somewhat redundant,
         // since
         // the Portlet API keeps portlets seperate anyway.
 
         return "state:" +  + ":" + objectName;
     }

    
Returns the session for the current request, creating it if necessary.
 
 
     private WebSession getSession()
     {
         return .getSession(true);
     }
 
     public boolean exists(String objectName)
     {
         WebSession session = .getSession(false);
 
         if (session == nullreturn false;
 
         return session.getAttribute(buildKey(objectName)) != null;
     }
 
     public Object get(String objectNameStateObjectFactory factory)
     {
         String key = buildKey(objectName);
         WebSession session = getSession();
 
         Object result = session.getAttribute(key);
         if (result == null)
         {
             result = factory.createStateObject();
             session.setAttribute(keyresult);
         }
 
         return result;
     }
 
     public void store(String objectNameObject stateObject)
     {
         if (stateObject instanceof SessionStoreOptimized)
         {
             SessionStoreOptimized optimized = (SessionStoreOptimizedstateObject;
 
             if (!optimized.isStoreToSessionNeeded())
                 return;
         }
 
         String key = buildKey(objectName);
 
         WebSession session = getSession();
 
         session.setAttribute(keystateObject);
     }
 
     public void setApplicationId(String applicationName)
     {
          = applicationName;
     }
 
     public void setRequest(WebRequest request)
    {
         = request;
    }
New to GrepCode? Check out our FAQ X