Package de.gebit.integrity.runner.variables

## 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 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 the `variableMap`).
    `protected static String` | `ENABLE_VARIABLES_STACKTRACE_OUTPUT` | System property to enable writing variable access stacktrace output.
    `protected static 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 Object` | `NULL` | This is a special null-representing object to be used to insert a logical "null" value into `variableMap` (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 Map<VariableOrConstantEntity,​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.
    `Map<String,​Object>` | `dumpVariableState​(VariantDefinition aCurrentVariant)` | Returns all variable entity entries.
    `Object` | `get​(Variable aVariable)` | Gets a value for a specific variable.
    `Object` | `get​(VariableOrConstantEntity anEntity)` | Gets a value for a specific variable.
    `void` | `importVariableState​(Map<String,​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 Object` | `makeNull​(Object aValue)` | Helper method for `NULL`.
    `protected void` | `performLazyDefinitionIfNecessary​(VariableOrConstantEntity anEntity)` | Checks whether a given `VariableOrConstantEntity` is already defined in our map.
    `protected static Object` | `restoreNull​(Object aValue)` | Helper method for `NULL`.
    `void` | `set​(VariableOrConstantEntity anEntity, Object aValue)` | Sets a value for a specific variable.
    `protected void` | `set​(VariableOrConstantEntity anEntity, Object aValue, boolean aSuppressTraceLogFlag)` | Internal variant of `set(VariableOrConstantEntity, Object)`.
    `void` | `setInitialValueResolverCallback​(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)` | Provides the `VariableManager` with a resolver callback for initial values of variables and constants.
    `protected void` | `traceLog​(String anAction, String aLogMessage)` | Outputs a trace log.
    `void` | `unset​(VariableOrConstantEntity anEntity)` | Unsets the specific variable or constant.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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_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 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 into `variableMap` (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 the `variableMap`). 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 the `TestRunner`) to perform any variable value setting.

  - ### Constructor Detail

    - #### DefaultVariableManager

          public DefaultVariableManager()

  - ### Method Detail

    - #### makeNull

          protected static Object makeNull​(Object aValue)

      Helper method for `NULL`.
      Parameters:
        `aValue` -
      Returns:

    - #### restoreNull

          protected static Object restoreNull​(Object aValue)

      Helper method for `NULL`.
      Parameters:
        `aValue` -
      Returns:

    - #### setInitialValueResolverCallback

          public void setInitialValueResolverCallback​(VariableOrConstantEntityInitialValueDefinitionCallback aConstantResolver)

      Description copied from interface: `VariableManager`
      Provides the `VariableManager` with a resolver callback for initial values of variables and constants. If the manager is asked for the value of a not-yet-known `VariableOrConstantEntity`, 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 interface `VariableManager`
      Parameters:
        `aConstantResolver` - the callback to use

    - #### get

          public Object get​(VariableOrConstantEntity anEntity)

      Description copied from interface: `VariableManager`
      Gets a value for a specific variable.
      Specified by:
        `get` in interface `VariableManager`
      Parameters:
        `anEntity` - the variable entity
      Returns:
        the value or null if none was defined

    - #### performLazyDefinitionIfNecessary

          protected void performLazyDefinitionIfNecessary​(VariableOrConstantEntity anEntity)

      Checks whether a given `VariableOrConstantEntity` is already defined in our map. If it isn't and we had a `VariableOrConstantEntityInitialValueDefinitionCallback` 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 interface `VariableManager`
      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: `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 interface `VariableManager`
      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 interface `VariableManager`
      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: `VariableManager`
      Sets a value for a specific variable. This is also used to define constants, as constants are technically also `VariableEntity` instances (
      Specified by:
        `set` in interface `VariableManager`
      Parameters:
        `anEntity` - the variable entity
        `aValue` - the value to set

    - #### set

          protected void set​(VariableOrConstantEntity anEntity,
                             Object aValue,
                             boolean aSuppressTraceLogFlag)

      Internal variant of `set(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 interface `VariableManager`
      Parameters:
        `anEntity` - the variable entity

    - #### dumpVariableState

          public Map<String,​Object> dumpVariableState​(VariantDefinition aCurrentVariant)

      Description copied from interface: `VariableManager`
      Returns all variable entity entries.
      Specified by:
        `dumpVariableState` in interface `VariableManager`
      Returns:

    - #### importVariableState

          public void importVariableState​(Map<String,​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 interface `VariableManager`

    - #### clear

          public void clear​(boolean aClearConstantsFlag)

      Description copied from interface: `VariableManager`
      Clears all stored variable values.
      Specified by:
        `clear` in interface `VariableManager`
      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 for `isTracingEnabled`, the caller may also check to save some cycles when generating expensive parameters.
      Parameters:
        `anAction` - the action
        `aLogMessage` - the message to log