Class DefaultVariableManager
- java.lang.Object
-
- de.gebit.integrity.runner.variables.DefaultVariableManager
-
- All Implemented Interfaces:
VariableManager
public class DefaultVariableManager extends java.lang.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 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
).protected static java.lang.String
ENABLE_VARIABLES_STACKTRACE_OUTPUT
System property to enable writing variable access stacktrace output.protected static java.lang.String
ENABLE_VARIABLES_TRACE_OUTPUT
System property to enable writing variable access trace output.protected boolean
isStacktracingEnabled
Whether variable tracing is enabled.protected boolean
isTracingEnabled
Whether variable tracing is enabled.protected TestModel
model
The current test model.protected static java.lang.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).protected ParameterResolver
parameterResolver
The parameter resolver.protected ValueConverter
valueConverter
The value converter.protected java.util.Map<VariableOrConstantEntity,java.lang.Object>
variableMap
The 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 void
clear(boolean aClearConstantsFlag)
Clears all stored variable values.java.util.Map<java.lang.String,java.lang.Object>
dumpVariableState(VariantDefinition aCurrentVariant)
Returns all variable entity entries.java.lang.Object
get(Variable aVariable)
Gets a value for a specific variable.java.lang.Object
get(VariableOrConstantEntity anEntity)
Gets a value for a specific variable.void
importVariableState(java.util.Map<java.lang.String,java.lang.Object> aState)
Reads the state as previously exported via#dumpVariableState()
.boolean
isDefined(Variable aVariable)
Checks whether a specific variable has a defined value.boolean
isDefined(VariableOrConstantEntity anEntity)
Checks whether a specific variable has a defined value.protected static java.lang.Object
makeNull(java.lang.Object aValue)
Helper method forNULL
.protected void
performLazyDefinitionIfNecessary(VariableOrConstantEntity anEntity)
Checks whether a givenVariableOrConstantEntity
is already defined in our map.protected static java.lang.Object
restoreNull(java.lang.Object aValue)
Helper method forNULL
.void
set(VariableOrConstantEntity anEntity, java.lang.Object aValue)
Sets a value for a specific variable.protected void
set(VariableOrConstantEntity anEntity, java.lang.Object aValue, boolean aSuppressTraceLogFlag)
Internal variant ofset(VariableOrConstantEntity, Object)
.void
setInitialValueResolverCallback(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)
Provides theVariableManager
with a resolver callback for initial values of variables and constants.protected void
traceLog(java.lang.String anAction, java.lang.String aLogMessage)
Outputs a trace log.void
unset(VariableOrConstantEntity anEntity)
Unsets the specific variable or constant.
-
-
-
Field Detail
-
ENABLE_VARIABLES_TRACE_OUTPUT
protected static final java.lang.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 java.lang.String ENABLE_VARIABLES_STACKTRACE_OUTPUT
System property to enable writing variable access stacktrace output. If this is set,ENABLE_VARIABLES_TRACE_OUTPUT
is 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 java.util.Map<VariableOrConstantEntity,java.lang.Object> variableMap
The map used to store variables.
-
NULL
protected static final java.lang.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 java.lang.Object makeNull(java.lang.Object aValue)
Helper method forNULL
.- Parameters:
aValue
-- Returns:
-
restoreNull
protected static java.lang.Object restoreNull(java.lang.Object aValue)
Helper method forNULL
.- Parameters:
aValue
-- Returns:
-
setInitialValueResolverCallback
public void setInitialValueResolverCallback(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)
Description copied from interface:VariableManager
Provides theVariableManager
with 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:
setInitialValueResolverCallback
in interfaceVariableManager
- Parameters:
aConstantResolver
- the callback to use
-
get
public java.lang.Object get(VariableOrConstantEntity anEntity)
Description copied from interface:VariableManager
Gets a value for a specific variable.- Specified by:
get
in interfaceVariableManager
- Parameters:
anEntity
- the variable entity- Returns:
- the value or null if none was defined
-
performLazyDefinitionIfNecessary
protected void performLazyDefinitionIfNecessary(VariableOrConstantEntity anEntity)
Checks whether a givenVariableOrConstantEntity
is already defined in our map. If it isn't and we had aVariableOrConstantEntityInitialValueDefinitionCallback
provided to us, a lazy initial value definition is triggered through this callback.
-
isDefined
public boolean isDefined(VariableOrConstantEntity anEntity)
Description copied from interface:VariableManager
Checks 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:
isDefined
in interfaceVariableManager
- Parameters:
anEntity
- the variable entity- Returns:
- true if the variable is defined, false if not
-
get
public java.lang.Object get(Variable aVariable)
Description copied from interface:VariableManager
Gets a value for a specific variable. This is able to retrieve attribute values out of bean variable values, if necessary.- Specified by:
get
in 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:VariableManager
Checks 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:
isDefined
in interfaceVariableManager
- Parameters:
aVariable
- the variable entity- Returns:
- true if the variable is defined, false if not
-
set
public void set(VariableOrConstantEntity anEntity, java.lang.Object aValue)
Description copied from interface:VariableManager
Sets a value for a specific variable. This is also used to define constants, as constants are technically alsoVariableEntity
instances (- Specified by:
set
in interfaceVariableManager
- Parameters:
anEntity
- the variable entityaValue
- the value to set
-
set
protected void set(VariableOrConstantEntity anEntity, java.lang.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:VariableManager
Unsets the specific variable or constant.- Specified by:
unset
in interfaceVariableManager
- Parameters:
anEntity
- the variable entity
-
dumpVariableState
public java.util.Map<java.lang.String,java.lang.Object> dumpVariableState(VariantDefinition aCurrentVariant)
Description copied from interface:VariableManager
Returns all variable entity entries.- Specified by:
dumpVariableState
in interfaceVariableManager
- Returns:
-
importVariableState
public void importVariableState(java.util.Map<java.lang.String,java.lang.Object> aState)
Description copied from interface:VariableManager
Reads the state as previously exported via#dumpVariableState()
. This is additive, meaning it does not remove non-mentioned variables.- Specified by:
importVariableState
in interfaceVariableManager
-
clear
public void clear(boolean aClearConstantsFlag)
Description copied from interface:VariableManager
Clears all stored variable values.- Specified by:
clear
in interfaceVariableManager
- Parameters:
aClearConstantsFlag
- Whether to clear constants as well. If false, only actual variables are cleared.
-
traceLog
protected void traceLog(java.lang.String anAction, java.lang.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
-
-