Class DefaultVariableManager
- java.lang.Object
-
- de.gebit.integrity.runner.variables.DefaultVariableManager
-
- All Implemented Interfaces:
VariableManager
public class DefaultVariableManager extends Object implements VariableManager
The simple, default variable manager which keeps variables in a map.- Author:
- Rene Schneider - initial API and implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected VariableOrConstantEntityInitialValueDefinitionCallbackconstantResolverA callback that can be used to trigger a lazy definition of the initial value of a constant or variable, if such a definition has not already been found to be done (= there is a value present in thevariableMap).protected static StringENABLE_VARIABLES_STACKTRACE_OUTPUTSystem property to enable writing variable access stacktrace output.protected static StringENABLE_VARIABLES_TRACE_OUTPUTSystem property to enable writing variable access trace output.protected booleanisStacktracingEnabledWhether variable tracing is enabled.protected booleanisTracingEnabledWhether variable tracing is enabled.protected TestModelmodelThe current test model.protected static ObjectNULLThis is a special null-representing object to be used to insert a logical "null" value intovariableMap(ConcurrentHashMap is important for performance purposes during concurrent variable/constant init, but does not support null values, which we unfortunately need).protected ParameterResolverparameterResolverThe parameter resolver.protected ValueConvertervalueConverterThe value converter.protected Map<VariableOrConstantEntity,Object>variableMapThe map used to store variables.
-
Constructor Summary
Constructors Constructor Description DefaultVariableManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(boolean aClearConstantsFlag)Clears all stored variable values.Map<String,Object>dumpVariableState(VariantDefinition aCurrentVariant)Returns all variable entity entries.Objectget(Variable aVariable)Gets a value for a specific variable.Objectget(VariableOrConstantEntity anEntity)Gets a value for a specific variable.voidimportVariableState(Map<String,Object> aState)Reads the state as previously exported via#dumpVariableState().booleanisDefined(Variable aVariable)Checks whether a specific variable has a defined value.booleanisDefined(VariableOrConstantEntity anEntity)Checks whether a specific variable has a defined value.protected static ObjectmakeNull(Object aValue)Helper method forNULL.protected voidperformLazyDefinitionIfNecessary(VariableOrConstantEntity anEntity)Checks whether a givenVariableOrConstantEntityis already defined in our map.protected static ObjectrestoreNull(Object aValue)Helper method forNULL.voidset(VariableOrConstantEntity anEntity, Object aValue)Sets a value for a specific variable.protected voidset(VariableOrConstantEntity anEntity, Object aValue, boolean aSuppressTraceLogFlag)Internal variant ofset(VariableOrConstantEntity, Object).voidsetInitialValueResolverCallback(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)Provides theVariableManagerwith a resolver callback for initial values of variables and constants.protected voidtraceLog(String anAction, String aLogMessage)Outputs a trace log.voidunset(VariableOrConstantEntity anEntity)Unsets the specific variable or constant.
-
-
-
Field Detail
-
ENABLE_VARIABLES_TRACE_OUTPUT
protected static final String ENABLE_VARIABLES_TRACE_OUTPUT
System property to enable writing variable access trace output.- See Also:
- Constant Field Values
-
ENABLE_VARIABLES_STACKTRACE_OUTPUT
protected static final String ENABLE_VARIABLES_STACKTRACE_OUTPUT
System property to enable writing variable access stacktrace output. If this is set,ENABLE_VARIABLES_TRACE_OUTPUTis automatically true as well.- See Also:
- Constant Field Values
-
isStacktracingEnabled
protected boolean isStacktracingEnabled
Whether variable tracing is enabled.
-
isTracingEnabled
protected boolean isTracingEnabled
Whether variable tracing is enabled.
-
variableMap
protected Map<VariableOrConstantEntity,Object> variableMap
The map used to store variables.
-
NULL
protected static final Object NULL
This is a special null-representing object to be used to insert a logical "null" value intovariableMap(ConcurrentHashMap is important for performance purposes during concurrent variable/constant init, but does not support null values, which we unfortunately need).
-
model
@Inject protected TestModel model
The current test model.
-
parameterResolver
@Inject protected ParameterResolver parameterResolver
The parameter resolver.
-
valueConverter
@Inject protected ValueConverter valueConverter
The value converter.
-
constantResolver
protected VariableOrConstantEntityInitialValueDefinitionCallback constantResolver
A callback that can be used to trigger a lazy definition of the initial value of a constant or variable, if such a definition has not already been found to be done (= there is a value present in thevariableMap). This callback must be injected from the outside, as the variable manager is not able to actually perform a variable/constant resolving by itself, but relies on someone else (usually theTestRunner) to perform any variable value setting.
-
-
Method Detail
-
makeNull
protected static Object makeNull(Object aValue)
Helper method forNULL.- Parameters:
aValue-- Returns:
-
restoreNull
protected static Object restoreNull(Object aValue)
Helper method forNULL.- Parameters:
aValue-- Returns:
-
setInitialValueResolverCallback
public void setInitialValueResolverCallback(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)
Description copied from interface:VariableManagerProvides theVariableManagerwith a resolver callback for initial values of variables and constants. If the manager is asked for the value of a not-yet-knownVariableOrConstantEntity, it may use this callback (if one is present) to trigger a definition of the value in question. It should however never rely on anything to be defined in this case. Execution of callback invocations can be expected to be synchronous.- Specified by:
setInitialValueResolverCallbackin interfaceVariableManager- Parameters:
aConstantResolver- the callback to use
-
get
public Object get(VariableOrConstantEntity anEntity)
Description copied from interface:VariableManagerGets a value for a specific variable.- Specified by:
getin interfaceVariableManager- Parameters:
anEntity- the variable entity- Returns:
- the value or null if none was defined
-
performLazyDefinitionIfNecessary
protected void performLazyDefinitionIfNecessary(VariableOrConstantEntity anEntity)
Checks whether a givenVariableOrConstantEntityis already defined in our map. If it isn't and we had aVariableOrConstantEntityInitialValueDefinitionCallbackprovided to us, a lazy initial value definition is triggered through this callback.
-
isDefined
public boolean isDefined(VariableOrConstantEntity anEntity)
Description copied from interface:VariableManagerChecks whether a specific variable has a defined value. Variables with 'null' as their defined value will return true here, even though calling get() on them will yield the same result as if they were not defined.- Specified by:
isDefinedin interfaceVariableManager- Parameters:
anEntity- the variable entity- Returns:
- true if the variable is defined, false if not
-
get
public Object get(Variable aVariable)
Description copied from interface:VariableManagerGets a value for a specific variable. This is able to retrieve attribute values out of bean variable values, if necessary.- Specified by:
getin interfaceVariableManager- Parameters:
aVariable- the variable entity- Returns:
- the value or null if none was defined
-
isDefined
public boolean isDefined(Variable aVariable)
Description copied from interface:VariableManagerChecks whether a specific variable has a defined value. Variables with 'null' as their defined value will return true here, even though calling get() on them will yield the same result as if they were not defined.- Specified by:
isDefinedin interfaceVariableManager- Parameters:
aVariable- the variable entity- Returns:
- true if the variable is defined, false if not
-
set
public void set(VariableOrConstantEntity anEntity, Object aValue)
Description copied from interface:VariableManagerSets a value for a specific variable. This is also used to define constants, as constants are technically alsoVariableEntityinstances (- Specified by:
setin interfaceVariableManager- Parameters:
anEntity- the variable entityaValue- the value to set
-
set
protected void set(VariableOrConstantEntity anEntity, Object aValue, boolean aSuppressTraceLogFlag)
Internal variant ofset(VariableOrConstantEntity, Object). Exists to add the suppression of trace output.- Parameters:
anEntity-aValue-aSuppressTraceLogFlag-
-
unset
public void unset(VariableOrConstantEntity anEntity)
Description copied from interface:VariableManagerUnsets the specific variable or constant.- Specified by:
unsetin interfaceVariableManager- Parameters:
anEntity- the variable entity
-
dumpVariableState
public Map<String,Object> dumpVariableState(VariantDefinition aCurrentVariant)
Description copied from interface:VariableManagerReturns all variable entity entries.- Specified by:
dumpVariableStatein interfaceVariableManager- Returns:
-
importVariableState
public void importVariableState(Map<String,Object> aState)
Description copied from interface:VariableManagerReads the state as previously exported via#dumpVariableState(). This is additive, meaning it does not remove non-mentioned variables.- Specified by:
importVariableStatein interfaceVariableManager
-
clear
public void clear(boolean aClearConstantsFlag)
Description copied from interface:VariableManagerClears all stored variable values.- Specified by:
clearin interfaceVariableManager- Parameters:
aClearConstantsFlag- Whether to clear constants as well. If false, only actual variables are cleared.
-
traceLog
protected void traceLog(String anAction, String aLogMessage)
Outputs a trace log. Although this checks forisTracingEnabled, the caller may also check to save some cycles when generating expensive parameters.- Parameters:
anAction- the actionaLogMessage- the message to log
-
-