Class MapDelegateVariableContainer

java.lang.Object
org.flowable.common.engine.impl.variable.MapDelegateVariableContainer
All Implemented Interfaces:
VariableContainer

public class MapDelegateVariableContainer extends Object implements VariableContainer
A simple VariableContainer implementation with the ability to add transient variables in addition to a VariableContainer.

The getVariable(String) method first looks if there is a local transient variable and returns it, if not, the delegate method is called. In case there is also a variable with the same key here as well as in the delegate, the delegate is ignored, effectively shadowing the variable of the delegate.

Author:
Arthur Hupka-Merle
  • Field Details

  • Constructor Details

    • MapDelegateVariableContainer

      public MapDelegateVariableContainer(Map<String,Object> transientVariables, VariableContainer delegate)
    • MapDelegateVariableContainer

      public MapDelegateVariableContainer(VariableContainer delegate)
    • MapDelegateVariableContainer

      public MapDelegateVariableContainer()
  • Method Details

    • hasVariable

      public boolean hasVariable(String key)
      Checks whether the given key can be resolved by this variable container.
      Specified by:
      hasVariable in interface VariableContainer
      Parameters:
      key - the name of the variable
      Returns:
      true in case this variable container defines a variable with the given key.
      See Also:
    • getVariable

      public Object getVariable(String key)
      The method first looks if there is a local transient variable and returns it. If not, the delegate method is called. In case there is also a variable with the same key here as well as in the delegate, the delegate is ignored, effectively shadowing the variable of the delegate.
      Specified by:
      getVariable in interface VariableContainer
      Returns:
      the variable of this variable container, the delegate container if not defined here or null when not found in either.
    • setVariable

      public void setVariable(String key, Object value)
      Sets the variable to the delegate.

      NOTE: this does not add the variable to this variable container, but to the delegate. Only in case delegate is VariableContainer.empty() it is set as transient variable for this container to ensure consistent behavior, when using this variable container without a delegate. Use addTransientVariable(String, Object) to add variables local to this variable container only.

      Specified by:
      setVariable in interface VariableContainer
      Parameters:
      key - the variable name
      value - the variable value to set to the delegate
    • setTransientVariable

      public void setTransientVariable(String key, Object value)
      Sets a transient variable, which is local to this variable container. Transient variables take precedence over variables for the delegate VariableContainer. Therefore, transient variables do shadow potentially available variables with the same name in the delegate.
      Specified by:
      setTransientVariable in interface VariableContainer
      Parameters:
      key - the variable name
      value - the variable value
      See Also:
    • addTransientVariable

      public MapDelegateVariableContainer addTransientVariable(String key, Object variable)
      Convenience method which returns this for method concatenation. Same as setTransientVariable(String, Object)
    • clearTransientVariables

      public void clearTransientVariables()
      Clears all transient variables of this variable container (not touching the delegate).
    • getTransientVariables

      public Map<String,Object> getTransientVariables()
      Returns:
      all available transient variables
    • removeTransientVariable

      public MapDelegateVariableContainer removeTransientVariable(String key)
    • getTenantId

      public String getTenantId()
      Specified by:
      getTenantId in interface VariableContainer
    • toString

      public String toString()
      Overrides:
      toString in class Object