Class 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 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 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 java.lang.Object makeNull​(java.lang.Object aValue)
        Helper method for NULL.
        Parameters:
        aValue -
        Returns:
      • restoreNull

        protected static java.lang.Object restoreNull​(java.lang.Object aValue)
        Helper method for NULL.
        Parameters:
        aValue -
        Returns:
      • get

        public java.lang.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
      • 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 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 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,
                        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 also VariableEntity instances (
        Specified by:
        set in interface VariableManager
        Parameters:
        anEntity - the variable entity
        aValue - the value to set
      • 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 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​(java.lang.String anAction,
                                java.lang.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