Package io.microsphere.spring.web.util
Enum Class WebScope
- All Implemented Interfaces:
Serializable,Comparable<WebScope>,Constable
The enumeration of scopes for Spring Web
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
RequestAttributes.SCOPE_REQUESTRequestAttributes.SCOPE_SESSION
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAttributes(org.springframework.web.context.request.RequestAttributes requestAttributes) Clear all attributes in the specifiedRequestAttributes.static voidclearAttributes(org.springframework.web.context.request.RequestAttributes requestAttributes, int scope) Clear all attributes in the specifiedRequestAttributesby the scope<T> TgetAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name) Return the request attribute value if present.static <T> TgetAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name, int scope) Get the attribute value by the specified nameString[]getAttributeNames(org.springframework.web.context.request.RequestAttributes requestAttributes) Get all attribute names in the specifiedRequestAttributes.static String[]getAttributeNames(org.springframework.web.context.request.RequestAttributes requestAttributes, int scope) Get all attribute names in the specifiedRequestAttributesby the scope<T> TgetAttributeOrDefault(org.springframework.web.context.request.RequestAttributes requestAttributes, String name, T defaultValue) Return the request attribute value, or a default, fallback value.getAttributes(org.springframework.web.context.request.RequestAttributes requestAttributes) <T> TgetRequiredAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name) Return the request attribute value or if not present raise anIllegalArgumentException.removeAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name) Remove the request attribute by the specified name.static ObjectremoveAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name, int scope) Remove the attribute by the specified namesetAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name, Object value) Set the request attribute value.static ObjectsetAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String name, Object value, int scope) Set the attribute valueintvalue()Get the value of the scopestatic WebScopevalueOf(int scope) Resolve theWebScopeby the specified scope valuestatic WebScopeReturns the enum constant of this class with the specified name.static WebScope[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
REQUEST
Request Scope- See Also:
-
RequestAttributes.SCOPE_REQUEST
-
SESSION
Session Scope- See Also:
-
RequestAttributes.SCOPE_SESSION
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
value
public int value()Get the value of the scope- Returns:
- the value of the scope
-
getAttribute
@Nullable public <T> T getAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name) Return the request attribute value if present.- Type Parameters:
T- the attribute type- Parameters:
requestAttributes-RequestAttributesname- the attribute name- Returns:
- the attribute value
-
setAttribute
public Object setAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name, @Nullable Object value) Set the request attribute value.- Parameters:
requestAttributes-RequestAttributesname- the attribute namevalue- the attribute value- Returns:
- the previous attribute value if the attribute exists, or
null
-
removeAttribute
public Object removeAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name) Remove the request attribute by the specified name.- Parameters:
requestAttributes-RequestAttributesname- the attribute name- Returns:
- the removed attribute value if the attribute exists, or
null
-
getRequiredAttribute
@Nonnull public <T> T getRequiredAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name) Return the request attribute value or if not present raise anIllegalArgumentException.- Type Parameters:
T- the attribute type- Parameters:
requestAttributes-RequestAttributesname- the attribute name- Returns:
- the attribute value
-
getAttributeOrDefault
@Nullable public <T> T getAttributeOrDefault(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name, @Nullable T defaultValue) Return the request attribute value, or a default, fallback value.- Type Parameters:
T- the attribute type- Parameters:
requestAttributes-RequestAttributesname- the attribute namedefaultValue- a default value to return instead- Returns:
- the attribute value
-
getAttributeNames
@Nonnull public String[] getAttributeNames(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes) Get all attribute names in the specifiedRequestAttributes.- Parameters:
requestAttributes-RequestAttributes- Returns:
- an array of attribute names, never
null
-
getAttributes
-
clearAttributes
public void clearAttributes(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes) Clear all attributes in the specifiedRequestAttributes.- Parameters:
requestAttributes-RequestAttributes
-
valueOf
Resolve theWebScopeby the specified scope value- Parameters:
scope- the scope value- Returns:
- the
WebScope - Throws:
IllegalArgumentException- if the scope value is not recognized- See Also:
-
getAttribute
@Nullable public static <T> T getAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name, int scope) throws IllegalArgumentException Get the attribute value by the specified name- Type Parameters:
T- the attribute value type- Parameters:
requestAttributes-RequestAttributessourcename- the attribute namescope- the scope value- Returns:
- the attribute value or
nullif not found - Throws:
IllegalArgumentException- if the scope value is not recognized
-
setAttribute
@Nullable public static Object setAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name, @Nullable Object value, int scope) throws IllegalArgumentException Set the attribute value- Parameters:
requestAttributes-RequestAttributessourcename- the attribute namevalue- the attribute valuescope- the scope value- Returns:
- the previous attribute value if the attribute exists, or
null - Throws:
IllegalArgumentException- if the scope value is not recognized
-
removeAttribute
@Nullable public static Object removeAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String name, int scope) throws IllegalArgumentException Remove the attribute by the specified name- Parameters:
requestAttributes-RequestAttributessourcename- the attribute namescope- the scope value- Returns:
- the removed attribute value if the attribute exists, or
null - Throws:
IllegalArgumentException- if the scope value is not recognized
-
getAttributeNames
public static String[] getAttributeNames(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, int scope) throws IllegalArgumentException Get all attribute names in the specifiedRequestAttributesby the scope- Parameters:
requestAttributes-RequestAttributessourcescope- the scope value- Returns:
- an array of attribute names, never
null - Throws:
IllegalArgumentException- if the scope value is not recognized
-
clearAttributes
public static void clearAttributes(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, int scope) throws IllegalArgumentException Clear all attributes in the specifiedRequestAttributesby the scope- Parameters:
requestAttributes-RequestAttributessourcescope- the scope value- Throws:
IllegalArgumentException- if the scope value is not recognized
-