Package org.kohsuke.stapler
Class AttributeKey<T>
- java.lang.Object
-
- org.kohsuke.stapler.AttributeKey<T>
-
public abstract class AttributeKey<T> extends Object
Type-safe attribute accessor.Servlet API has a bag of stuff in several scopes (such as request, session, ...) but the API is not type-safe. This object provides a convenient type-safe access to to such bags, as well as providing uniform API regardless of the actual scope.
Each instance of
AttributeKey
gets an unique attribute name, which means in the most typical case, these instances should be used as a singleton.- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description AttributeKey()
AttributeKey(String name)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> AttributeKey<T>
appScoped()
Creates a newServletContext
-scopedAttributeKey
.T
get()
abstract T
get(javax.servlet.http.HttpServletRequest req)
void
remove()
abstract void
remove(javax.servlet.http.HttpServletRequest req)
static <T> AttributeKey<T>
requestScoped()
Creates a new request-scopedAttributeKey
.static <T> AttributeKey<T>
sessionScoped()
Creates a new session-scopedAttributeKey
.abstract void
set(javax.servlet.http.HttpServletRequest req, T value)
void
set(T value)
-
-
-
Field Detail
-
name
protected final String name
-
-
Constructor Detail
-
AttributeKey
public AttributeKey()
-
AttributeKey
public AttributeKey(String name)
-
-
Method Detail
-
get
public abstract T get(javax.servlet.http.HttpServletRequest req)
-
set
public abstract void set(javax.servlet.http.HttpServletRequest req, T value)
-
remove
public abstract void remove(javax.servlet.http.HttpServletRequest req)
-
get
public final T get()
-
set
public final void set(T value)
-
remove
public final void remove()
-
requestScoped
public static <T> AttributeKey<T> requestScoped()
Creates a new request-scopedAttributeKey
.
-
sessionScoped
public static <T> AttributeKey<T> sessionScoped()
Creates a new session-scopedAttributeKey
.
-
appScoped
public static <T> AttributeKey<T> appScoped()
Creates a newServletContext
-scopedAttributeKey
.
-
-