public class CustomAttribute
extends java.lang.Object
ThreadLocal
, a
class that allows one to associate custom data with a thread.Modifier and Type | Field and Description |
---|---|
static int |
SCOPE_CONFIGURATION
Constant used in the constructor specifying that this attribute is
scoped by the configuration.
|
static int |
SCOPE_ENVIRONMENT
Constant used in the constructor specifying that this attribute is
scoped by the environment.
|
static int |
SCOPE_TEMPLATE
Constant used in the constructor specifying that this attribute is
scoped by the template.
|
Constructor and Description |
---|
CustomAttribute(int scope)
Creates a new custom attribute with the specified scope
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
create()
This method is invoked when
get() is invoked without
set(Object) being invoked before it to define the value in the
current scope. |
java.lang.Object |
get() |
java.lang.Object |
get(Template t) |
void |
set(java.lang.Object value)
Sets the value of the attribute in the context of the current environment.
|
void |
set(java.lang.Object value,
Template t)
Sets the value of a template-scope attribute in the context of the given
template.
|
public static final int SCOPE_ENVIRONMENT
public static final int SCOPE_TEMPLATE
public static final int SCOPE_CONFIGURATION
public CustomAttribute(int scope)
scope
- one of SCOPE_ constants.protected java.lang.Object create()
get()
is invoked without
set(Object)
being invoked before it to define the value in the
current scope. Override it to create the attribute value on-demand.public final java.lang.Object get()
java.lang.IllegalStateException
- if there is no current environment (and
hence also no current template and configuration), therefore the
attribute's current scope object can't be resolved.public final java.lang.Object get(Template t)
java.lang.UnsupportedOperationException
- if this custom attribute is not a
template-scope attributejava.lang.NullPointerException
- if t is nullpublic final void set(java.lang.Object value)
value
- the new value of the attributejava.lang.IllegalStateException
- if there is no current environment (and
hence also no current template and configuration), therefore the
attribute's current scope object can't be resolved.public final void set(java.lang.Object value, Template t)
value
- the new value of the attributet
- the templatejava.lang.UnsupportedOperationException
- if this custom attribute is not a
template-scope attributejava.lang.NullPointerException
- if t is null