public abstract class AbstractMutableGenericContext extends Object implements MutableGenericContext
GenericContext
interface.Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
AbstractMutableGenericContext(MapFactory<? extends Map> mapFactory,
GenericContext parentContext)
The constructor for a
sub-context . |
Modifier and Type | Method and Description |
---|---|
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 . |
<T> T |
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 . |
<T> T |
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 . |
<T> T |
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createChildContext, getVariable
private final GenericContext parent
private final GenericContext immutableContext
private final MapFactory<? extends Map> mapFactory
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.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)
GenericContext
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)
GenericContext
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
GenericContext
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
GenericContext
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
GenericContext
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)
GenericContext
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
GenericContext.hasVariable(String)
where possible.getVariableNames
in interface GenericContext
public Object setVariable(String variableName, Object value)
MutableGenericContext
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)
MutableGenericContext
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)
MutableGenericContext
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()
GenericContext
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
MutableGenericContext
.getImmutableContext
in interface MutableGenericContext
protected MapFactory<? extends Map> getMapFactory()
MapFactory
.MapFactory
to use.Copyright © 2001–2016 mmm-Team. All rights reserved.