The Spring Framework

org.springframework.web.context.request
Class SessionScope

java.lang.Object
  extended by org.springframework.web.context.request.AbstractRequestAttributesScope
      extended by org.springframework.web.context.request.SessionScope
All Implemented Interfaces:
Scope

public class SessionScope
extends AbstractRequestAttributesScope

Session-backed Scope implementation. Relies on a thread-bound RequestAttributes instance, which can be exported through RequestContextListener, RequestContextFilter or DispatcherServlet.

This Scope will also work for Portlet environments, through an alternate RequestAttributes implementation (as exposed out-of-the-box by Spring's DispatcherPortlet).

Since:
2.0
Author:
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
RequestContextHolder.currentRequestAttributes(), RequestAttributes.SCOPE_SESSION, RequestAttributes.SCOPE_GLOBAL_SESSION, RequestContextListener, RequestContextFilter, DispatcherServlet, DispatcherPortlet

Constructor Summary
SessionScope()
          Create a new SessionScope, storing attributes in a locally isolated session.
SessionScope(boolean globalSession)
          Create a new SessionScope, specifying whether to store attributes in the global session, provided that such a distinction is available.
 
Method Summary
 Object get(String name, ObjectFactory objectFactory)
          Return the object with the given name from the underlying scope, creating it if not found in the underlying storage mechanism.
 String getConversationId()
          Return the conversation id for the current underlying scope, if any.
protected  int getScope()
          Template method that determines the actual target scope.
 Object remove(String name)
          Remove the object with the given name from the underlying scope.
 
Methods inherited from class org.springframework.web.context.request.AbstractRequestAttributesScope
registerDestructionCallback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionScope

public SessionScope()
Create a new SessionScope, storing attributes in a locally isolated session.


SessionScope

public SessionScope(boolean globalSession)
Create a new SessionScope, specifying whether to store attributes in the global session, provided that such a distinction is available.

This distinction is important for Portlet environments, where there are two notions of a session: "portlet scope" and "application scope". If this flag is on, objects will be put into the "application scope" session; else they will end up in the "portlet scope" session (the typical default).

In a Servlet environment, this flag is effectively ignored.

See Also:
PortletRequestAttributes, ServletRequestAttributes
Method Detail

getScope

protected int getScope()
Description copied from class: AbstractRequestAttributesScope
Template method that determines the actual target scope.

Specified by:
getScope in class AbstractRequestAttributesScope
Returns:
the target scope, in the form of an appropriate RequestAttributes constant
See Also:
RequestAttributes.SCOPE_REQUEST, RequestAttributes.SCOPE_SESSION, RequestAttributes.SCOPE_GLOBAL_SESSION

getConversationId

public String getConversationId()
Description copied from interface: Scope
Return the conversation id for the current underlying scope, if any.

The exact value of the converation id is totally dependent on the underlying storage mechanism (of course). In the case of session scoped beans a good conversation id probably would be the session id; in the case of a JCache scope a good conversation id probably would be the name of the associated cache.

It is perfectly valid to return null in an implementation of this method if the underlying storage mechanism has no obvious good candidate for a conversation id.

Returns:
the conversation id, or null if there is no conversation id concept for this scope

get

public Object get(String name,
                  ObjectFactory objectFactory)
Description copied from interface: Scope
Return the object with the given name from the underlying scope, creating it if not found in the underlying storage mechanism.

Specified by:
get in interface Scope
Overrides:
get in class AbstractRequestAttributesScope
Parameters:
name - the name of the object to retrieve
objectFactory - the ObjectFactory to use to create the scoped object if it is not present in the underlying storage mechanism
Returns:
the desired object

remove

public Object remove(String name)
Description copied from interface: Scope
Remove the object with the given name from the underlying scope.

Returns 'null' if no object was found; otherwise returns the removed Object.

Specified by:
remove in interface Scope
Overrides:
remove in class AbstractRequestAttributesScope
Parameters:
name - the name of the object to remove
Returns:
the removed object, if any

The Spring Framework

Copyright © 2002-2006 The Spring Framework.