|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.context.base.AbstractMutableGenericContext
public abstract class AbstractMutableGenericContext
This class is the basic implementation of the GenericContext
interface.
Field Summary | |
---|---|
private GenericContext |
immutableContext
the parent context |
private MapFactory<? extends Map> |
mapFactory
|
private GenericContext |
parent
the parent context |
private Map<String,Object> |
variableMap
maps variable names to values |
Constructor Summary | |
---|---|
AbstractMutableGenericContext(MapFactory<? extends Map> mapFactory,
GenericContext parentContext)
The constructor for a sub-context . |
Method Summary | ||
---|---|---|
GenericContext |
getImmutableContext()
This method gets an immutable proxy of this context that can NOT be casted to MutableGenericContext . |
|
protected MapFactory<? extends Map> |
getMapFactory()
This method gets the MapFactory . |
|
|
getVariable(Class<T> type)
This method gets the variable associated with the given type . |
|
Object |
getVariable(String variableName)
This method gets the variable associated with the given variableName . |
|
protected String |
getVariableName(Class<?> type)
This method gets the variable-name (key) for the given type . |
|
Set<String> |
getVariableNames()
This method returns the names of all defined variables. |
|
boolean |
hasVariable(String variableName)
This method determines if the variable for the
given variableName exists. |
|
Object |
removeVariable(String variableName)
This method removes (unsets) the variable specified by variableName . |
|
|
requireVariable(Class<T> type)
This method gets the variable associated with the given type . |
|
Object |
requireVariable(String variableName)
This method gets the variable associated with the given variableName . |
|
|
requireVariable(String variableName,
Class<T> type)
This method gets the variable associated with the given variableName . |
|
Object |
setVariable(Object value)
This method sets the variable given by value . |
|
Object |
setVariable(String variableName,
Object value)
This method sets the variable specified by variableName to the
given value . |
|
Map<String,Object> |
toMap()
This method allows to create a Map representing the variables of
this context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.mmm.util.context.api.GenericContext |
---|
createChildContext, getVariable |
Field Detail |
---|
private final Map<String,Object> variableMap
values
private final GenericContext parent
private final GenericContext immutableContext
private final MapFactory<? extends Map> mapFactory
getMapFactory()
Constructor Detail |
---|
public AbstractMutableGenericContext(MapFactory<? extends Map> mapFactory, GenericContext parentContext)
sub-context
.
mapFactory
- is used to create the map for storing variables.parentContext
- is the context the created one will derive from.Method Detail |
---|
protected String getVariableName(Class<?> type)
type
.
type
- is the Class
reflecting the type of some variable.
type
.setVariable(Object)
,
getVariable(Class)
,
requireVariable(Class)
public Object getVariable(String variableName)
variableName
.
getVariable
in interface GenericContext
variableName
- is the name of the requested variable.
null
if the variable is
NOT set.public <T> T getVariable(Class<T> type)
type
.
It will use the classname
as
variable-name
.String
or Integer
are bad candidates while
MySpecificSingletonComponentInterface
might be a good option.
getVariable
in interface GenericContext
T
- the generic type of the variable.type
- is the class reflecting the type of the variable.
null
if the variable is
NOT set.MutableGenericContext.setVariable(String, Object)
public Object requireVariable(String variableName) throws ValueNotSetException
variableName
.
requireVariable
in interface GenericContext
variableName
- is the name of the requested variable.
ValueNotSetException
- if the requested variable is NOT set.public <T> T requireVariable(String variableName, Class<T> type) throws ValueNotSetException
variableName
.
requireVariable
in interface GenericContext
T
- the generic type of the variable.variableName
- is the name of the requested variable.type
- is the class reflecting the type of the variable.
ValueNotSetException
- if the requested variable is NOT set.public <T> T requireVariable(Class<T> type) throws ValueNotSetException
type
.
It will use the classname
as
variable-name
.String
or Integer
are bad candidates while
MySpecificSingletonComponentInterface
might be a good option.
requireVariable
in interface GenericContext
T
- the generic type of the variable.type
- is the class reflecting the type of the variable.
ValueNotSetException
- if the requested variable is NOT set.MutableGenericContext.setVariable(String, Object)
public boolean hasVariable(String variableName)
variable
for the
given variableName
exists.
hasVariable
in interface GenericContext
variableName
- is the name of the requested variable.
true
if a value exists for the given
variableName
, false
otherwise.public Set<String> getVariableNames()
GenericContext.hasVariable(String)
where possible.
getVariableNames
in interface GenericContext
public Object setVariable(String variableName, Object value)
variableName
to the
given value
. If the variable is already set, it will be
overridden.
setVariable
in interface MutableGenericContext
variableName
- is the name of the variable to set.value
- is the value to assign to the variable.
null
if the variable was undefined or
NOT overridden in this context.GenericContext.getVariable(String)
public Object setVariable(Object value)
value
. If the variable
is already set, it will be overridden. This method will use the
classname
as variable-name
.String
or Integer
are bad candidates while
MySpecificSingletonComponentInterface
might be a good option.
setVariable
in interface MutableGenericContext
value
- is the value to assign to the variable.
null
if the variable was undefined or
NOT overridden in this context.GenericContext.getVariable(String)
,
GenericContext.getVariable(Class)
public Object removeVariable(String variableName)
variableName
. This will only remove a variable defined in this
context. A variable inherited from a
parent context
can not be
removed here. set
a variable to null
instead.
removeVariable
in interface MutableGenericContext
variableName
- is the name of the variable to unset.
null
if the variable
is NOT defined (in this context).public Map<String,Object> toMap()
Map
representing the variables of
this context. This can be useful to pass this context to an external
component (e.g. a template-engine) that typically accepts a Map
.Map
will NOT reflect
changes of this context and vice versa.
toMap
in interface GenericContext
public GenericContext getImmutableContext()
MutableGenericContext
.
getImmutableContext
in interface MutableGenericContext
protected MapFactory<? extends Map> getMapFactory()
MapFactory
.
MapFactory
to use.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |