net.sf.mmm.util.context.impl
Class MutableGenericContextImpl

java.lang.Object
  extended by net.sf.mmm.util.context.base.AbstractMutableGenericContext
      extended by net.sf.mmm.util.context.impl.MutableGenericContextImpl
All Implemented Interfaces:
GenericContext, MutableGenericContext

public class MutableGenericContextImpl
extends AbstractMutableGenericContext

This is the implementation of the MutableGenericContext interface.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  GenericValueConverter<Object> valueConverter
           
 
Constructor Summary
MutableGenericContextImpl(MapFactory<? extends Map> mapFactory)
          The constructor for a root-context.
MutableGenericContextImpl(MapFactory<? extends Map> mapFactory, GenericContext parentContext)
          The constructor for a sub-context.
MutableGenericContextImpl(MapFactory<? extends Map> mapFactory, GenericContext parentContext, GenericValueConverter<Object> valueConverter)
          The constructor for a sub-context.
MutableGenericContextImpl(MapFactory<? extends Map> mapFactory, GenericValueConverter<Object> valueConverter)
          The constructor for a sub-context.
 
Method Summary
 MutableGenericContext createChildContext()
          This method creates a new context that inherits all variables from this context (and its parent contexts).
<T> T
getVariable(String variableName, Class<T> type)
          This method gets the variable associated with the given variableName as the given type.
 
Methods inherited from class net.sf.mmm.util.context.base.AbstractMutableGenericContext
getImmutableContext, getMapFactory, getVariable, getVariable, getVariableName, getVariableNames, hasVariable, removeVariable, requireVariable, requireVariable, requireVariable, setVariable, setVariable, toMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueConverter

private final GenericValueConverter<Object> valueConverter
See Also:
getVariable(String, Class)
Constructor Detail

MutableGenericContextImpl

public MutableGenericContextImpl(MapFactory<? extends Map> mapFactory)
The constructor for a root-context.

Parameters:
mapFactory - is used to create the map for storing variables.

MutableGenericContextImpl

public MutableGenericContextImpl(MapFactory<? extends Map> mapFactory,
                                 GenericValueConverter<Object> valueConverter)
The constructor for a sub-context.

Parameters:
mapFactory - is used to create the map for storing variables.
valueConverter - is the GenericValueConverter used to convert variables that are requested as a different type.

MutableGenericContextImpl

public MutableGenericContextImpl(MapFactory<? extends Map> mapFactory,
                                 GenericContext parentContext)
The constructor for a sub-context.

Parameters:
mapFactory - is used to create the map for storing variables.
parentContext - is the context the created one will derive from.

MutableGenericContextImpl

public MutableGenericContextImpl(MapFactory<? extends Map> mapFactory,
                                 GenericContext parentContext,
                                 GenericValueConverter<Object> valueConverter)
The constructor for a sub-context.

Parameters:
mapFactory - is used to create the map for storing variables.
parentContext - is the context the created one will derive from.
valueConverter - is the GenericValueConverter used to convert variables that are requested as a different type.
Method Detail

getVariable

public <T> T getVariable(String variableName,
                         Class<T> type)
This method gets the variable associated with the given variableName as the given type. If the type does NOT match the actual type of the variable it may automatically be converted as possible.

Type Parameters:
T - the generic type of the variable.
Parameters:
variableName - is the name of the requested variable.
type - is the class reflecting the type of the variable.
Returns:
the value of the variable or null if the variable is NOT set.

createChildContext

public MutableGenericContext createChildContext()
This method creates a new context that inherits all variables from this context (and its parent contexts). Variables that are set in the child-context override inherited variables. However changes to the child-context do NOT modify this context.
ATTENTION:
Typically the child-context will be a cheap-copy connected to this context. So you should be aware of this when creating many child-contexts recursively as their parent-contexts can NOT be collected by the garbage-collector.

Returns:
the new created sub-context.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.