Top Description Fields Constructors Methods
org.springframework.web.reactive.result.method.annotation

pack-priv Class SessionAttributesHandler

extends Object
Class Inheritance
Imports
java.util.Collections, .HashMap, .HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, org.springframework.core.annotation.AnnotatedElementUtils, org.springframework.util.Assert, org.springframework.web.bind.annotation.SessionAttributes, org.springframework.web.server.WebSession

Package-private class to assist ModelInitializer with managing model attributes in the WebSession based on model attribute names and types declared va @SessionAttributes.
Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private final Set<String>
private final Set<Class<?>>
private final Set<String>

Constructor Summary

AccessConstructor and Description
public
SessionAttributesHandler(Class<?>
the controller type
handlerType
)

Create a new session attributes handler.

Method Summary

Modifier and TypeMethod and Description
public void
cleanupAttributes(WebSession
the current session
session
)

Remove "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

public boolean
hasSessionAttributes()

Whether the controller represented by this instance has declared any session attributes through an SessionAttributes annotation.

public boolean
isHandlerSessionAttribute(String
the attribute name to check
attributeName
,
Class<?>
the type for the attribute
attributeType
)

Whether the attribute name or type match the names and types specified via @SessionAttributes on the underlying controller.

public Map<String, Object>

Returns:

a map with handler session attributes, possibly empty
retrieveAttributes
(WebSession
the current session
session
)

Retrieve "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

public void
storeAttributes(WebSession
the current session
session
,
Map<String, ?>
candidate attributes for session storage
attributes
)

Store a subset of the given attributes in the session.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeNamesback to summary
private final Set<String> attributeNames
attributeTypesback to summary
private final Set<Class<?>> attributeTypes
knownAttributeNamesback to summary
private final Set<String> knownAttributeNames

Constructor Detail

SessionAttributesHandlerback to summary
public SessionAttributesHandler(Class<?> handlerType)

Create a new session attributes handler. Session attribute names and types are extracted from the @SessionAttributes annotation, if present, on the given type.

Parameters
handlerType:Class<?>

the controller type

Method Detail

cleanupAttributesback to summary
public void cleanupAttributes(WebSession session)

Remove "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

Parameters
session:WebSession

the current session

hasSessionAttributesback to summary
public boolean hasSessionAttributes()

Whether the controller represented by this instance has declared any session attributes through an SessionAttributes annotation.

isHandlerSessionAttributeback to summary
public boolean isHandlerSessionAttribute(String attributeName, Class<?> attributeType)

Whether the attribute name or type match the names and types specified via @SessionAttributes on the underlying controller.

Attributes successfully resolved through this method are "remembered" and subsequently used in retrieveAttributes(WebSession) and also cleanupAttributes(WebSession).

Parameters
attributeName:String

the attribute name to check

attributeType:Class<?>

the type for the attribute

retrieveAttributesback to summary
public Map<String, Object> retrieveAttributes(WebSession session)

Retrieve "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

Parameters
session:WebSession

the current session

Returns:Map<String, Object>

a map with handler session attributes, possibly empty

storeAttributesback to summary
public void storeAttributes(WebSession session, Map<String, ?> attributes)

Store a subset of the given attributes in the session. Attributes not declared as session attributes via @SessionAttributes are ignored.

Parameters
session:WebSession

the current session

attributes:Map<String, ?>

candidate attributes for session storage