org.springframework.web.method.annotation
Class SessionAttributesHandler

java.lang.Object
  extended by org.springframework.web.method.annotation.SessionAttributesHandler

public class SessionAttributesHandler
extends java.lang.Object

Manages controller-specific session attributes declared via @SessionAttributes. Actual storage is performed via SessionAttributeStore.

When a controller annotated with @SessionAttributes adds attributes to its model, those attributes are checked against names and types specified via @SessionAttributes. Matching model attributes are saved in the HTTP session and remain there until the controller calls SessionStatus.setComplete().

Since:
3.1
Author:
Rossen Stoyanchev

Field Summary
private  java.util.Set<java.lang.String> attributeNames
           
private  java.util.Set<java.lang.Class<?>> attributeTypes
           
private  java.util.Set<java.lang.String> resolvedAttributeNames
           
private  SessionAttributeStore sessionAttributeStore
           
 
Constructor Summary
SessionAttributesHandler(java.lang.Class<?> handlerType, SessionAttributeStore sessionAttributeStore)
          Creates a new instance for a controller type.
 
Method Summary
 void cleanupAttributes(WebRequest request)
          Cleans "known" attributes from the session - i.e.
 boolean hasSessionAttributes()
          Whether the controller represented by this instance has declared session attribute names or types of interest via SessionAttributes.
 boolean isHandlerSessionAttribute(java.lang.String attributeName, java.lang.Class<?> attributeType)
          Whether the attribute name and/or type match those specified in the controller's @SessionAttributes annotation.
(package private)  java.lang.Object retrieveAttribute(WebRequest request, java.lang.String attributeName)
          A pass-through call to the underlying SessionAttributeStore.
 java.util.Map<java.lang.String,java.lang.Object> retrieveAttributes(WebRequest request)
          Retrieve "known" attributes from the session -- i.e.
 void storeAttributes(WebRequest request, java.util.Map<java.lang.String,?> attributes)
          Stores a subset of the given attributes in the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributeNames

private final java.util.Set<java.lang.String> attributeNames

attributeTypes

private final java.util.Set<java.lang.Class<?>> attributeTypes

resolvedAttributeNames

private final java.util.Set<java.lang.String> resolvedAttributeNames

sessionAttributeStore

private final SessionAttributeStore sessionAttributeStore
Constructor Detail

SessionAttributesHandler

public SessionAttributesHandler(java.lang.Class<?> handlerType,
                                SessionAttributeStore sessionAttributeStore)
Creates a new instance for a controller type. Session attribute names/types are extracted from a type-level @SessionAttributes if found.

Parameters:
handlerType - the controller type
sessionAttributeStore - used for session access
Method Detail

hasSessionAttributes

public boolean hasSessionAttributes()
Whether the controller represented by this instance has declared session attribute names or types of interest via SessionAttributes.


isHandlerSessionAttribute

public boolean isHandlerSessionAttribute(java.lang.String attributeName,
                                         java.lang.Class<?> attributeType)
Whether the attribute name and/or type match those specified in the controller's @SessionAttributes annotation.

Attributes successfully resolved through this method are "remembered" and used in retrieveAttributes(WebRequest) and cleanupAttributes(WebRequest). In other words, retrieval and cleanup only affect attributes previously resolved through here.

Parameters:
attributeName - the attribute name to check; must not be null
attributeType - the type for the attribute; or null

storeAttributes

public void storeAttributes(WebRequest request,
                            java.util.Map<java.lang.String,?> attributes)
Stores a subset of the given attributes in the session. Attributes not declared as session attributes via @SessionAttributes are ignored.

Parameters:
request - the current request
attributes - candidate attributes for session storage

retrieveAttributes

public java.util.Map<java.lang.String,java.lang.Object> retrieveAttributes(WebRequest request)
Retrieve "known" attributes from the session -- i.e. attributes listed in @SessionAttributes and previously stored in the in the model at least once.

Parameters:
request - the current request
Returns:
a map with handler session attributes; possibly empty.

cleanupAttributes

public void cleanupAttributes(WebRequest request)
Cleans "known" attributes from the session - i.e. attributes listed in @SessionAttributes and previously stored in the in the model at least once.

Parameters:
request - the current request

retrieveAttribute

java.lang.Object retrieveAttribute(WebRequest request,
                                   java.lang.String attributeName)
A pass-through call to the underlying SessionAttributeStore.

Parameters:
request - the current request
attributeName - the name of the attribute of interest
Returns:
the attribute value or null