Package org.pentaho.di.core.variables
Class Variables
- java.lang.Object
-
- org.pentaho.di.core.variables.Variables
-
- All Implemented Interfaces:
VariableSpace
public class Variables extends Object implements VariableSpace
This class is an implementation of VariableSpace- Author:
- Sven Boden
-
-
Constructor Summary
Constructors Constructor Description Variables()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopyVariablesFrom(VariableSpace space)Copy the variables from another space, without initializing with the defaults.StringenvironmentSubstitute(String aString)Substitute the string using the current variable space.String[]environmentSubstitute(String[] string)Replaces environment variables in an array of strings.StringenvironmentSubstitute(String aString, boolean escapeHexDelimiter)Substitute the string using the current variable space.StringfieldSubstitute(String aString, RowMetaInterface rowMeta, Object[] rowData)Substitutes field values inaString.static VariableSpacegetADefaultVariableSpace()Get a default variable space as a placeholder.booleangetBooleanValueOfVariable(String variableName, boolean defaultValue)This method returns a boolean for the new variable check boxes.VariableSpacegetParentVariableSpace()Get the parent of the variable space.StringgetVariable(String variableName)Get the value of a variable.StringgetVariable(String variableName, String defaultValue)Get the value of a variable with a default in case the variable is not found.voidinitializeVariablesFrom(VariableSpace parent)Initialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()).voidinjectVariables(Map<String,String> prop)Inject variables.String[]listVariables()List the variables (not the values) that are currently in the variable space.voidsetParentVariableSpace(VariableSpace parent)Set the parent variable spacevoidsetVariable(String variableName, String variableValue)Sets a variable in the Kettle Variables list.voidshareVariablesWith(VariableSpace space)Share a variable space from another variable space.
-
-
-
Method Detail
-
copyVariablesFrom
public void copyVariablesFrom(VariableSpace space)
Description copied from interface:VariableSpaceCopy the variables from another space, without initializing with the defaults. This does not affect any parent relationship.- Specified by:
copyVariablesFromin interfaceVariableSpace- Parameters:
space- the space to copy the variables from.
-
getParentVariableSpace
public VariableSpace getParentVariableSpace()
Description copied from interface:VariableSpaceGet the parent of the variable space.- Specified by:
getParentVariableSpacein interfaceVariableSpace- Returns:
- the parent.
-
setParentVariableSpace
public void setParentVariableSpace(VariableSpace parent)
Description copied from interface:VariableSpaceSet the parent variable space- Specified by:
setParentVariableSpacein interfaceVariableSpace- Parameters:
parent- The parent variable space to set
-
getVariable
public String getVariable(String variableName, String defaultValue)
Description copied from interface:VariableSpaceGet the value of a variable with a default in case the variable is not found.- Specified by:
getVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variabledefaultValue- The default value in case the variable could not be found- Returns:
- the String value of a variable
-
getVariable
public String getVariable(String variableName)
Description copied from interface:VariableSpaceGet the value of a variable.- Specified by:
getVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variable- Returns:
- the String value of a variable or null in case the variable could not be found.
-
getBooleanValueOfVariable
public boolean getBooleanValueOfVariable(String variableName, boolean defaultValue)
Description copied from interface:VariableSpaceThis method returns a boolean for the new variable check boxes. If the variable name is not set or the variable name is not specified, this method simply returns the default value. If not, it convert the variable value to a boolean. "Y", "YES" and "TRUE" all convert to true. (case insensitive)- Specified by:
getBooleanValueOfVariablein interfaceVariableSpace- Parameters:
variableName- The variable to look up.defaultValue- The default value to return.- Returns:
- See Also:
static method ValueMeta.convertStringToBoolean()
-
initializeVariablesFrom
public void initializeVariablesFrom(VariableSpace parent)
Description copied from interface:VariableSpaceInitialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()). The parent is set as parent variable space.- Specified by:
initializeVariablesFromin interfaceVariableSpace- Parameters:
parent- the parent to start from, or null if root.
-
listVariables
public String[] listVariables()
Description copied from interface:VariableSpaceList the variables (not the values) that are currently in the variable space.- Specified by:
listVariablesin interfaceVariableSpace- Returns:
- Array of String variable names.
-
setVariable
public void setVariable(String variableName, String variableValue)
Description copied from interface:VariableSpaceSets a variable in the Kettle Variables list.- Specified by:
setVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variable to setvariableValue- The value of the variable to set. If the variableValue is null, the variable is cleared from the list.
-
environmentSubstitute
public String environmentSubstitute(String aString)
Description copied from interface:VariableSpaceSubstitute the string using the current variable space.- Specified by:
environmentSubstitutein interfaceVariableSpace- Parameters:
aString- The string to substitute.- Returns:
- The substituted string.
-
environmentSubstitute
public String environmentSubstitute(String aString, boolean escapeHexDelimiter)
Description copied from interface:VariableSpaceSubstitute the string using the current variable space.- Specified by:
environmentSubstitutein interfaceVariableSpace- Parameters:
aString- The string to substitute.escapeHexDelimiter- escapes the hex delimiter substitution- Returns:
- The substituted string.
-
fieldSubstitute
public String fieldSubstitute(String aString, RowMetaInterface rowMeta, Object[] rowData) throws KettleValueException
Substitutes field values inaString. Field values are of the form "?{}". The values are retrieved from the specified row. Please note that the getString() method is used to convert to a String, for all values in the row. - Specified by:
fieldSubstitutein interfaceVariableSpace- Parameters:
aString- the string on which to apply the substitution.rowMeta- The row metadata to use.rowData- The row data to use- Returns:
- the string with the substitution applied.
- Throws:
KettleValueException- In case there is a String conversion error
-
environmentSubstitute
public String[] environmentSubstitute(String[] string)
Description copied from interface:VariableSpaceReplaces environment variables in an array of strings. See also: environmentSubstitute(String string)- Specified by:
environmentSubstitutein interfaceVariableSpace- Parameters:
string- The array of strings that wants its variables to be replaced.- Returns:
- the array with the environment variables replaced.
-
shareVariablesWith
public void shareVariablesWith(VariableSpace space)
Description copied from interface:VariableSpaceShare a variable space from another variable space. This means that the object should take over the space used as argument.- Specified by:
shareVariablesWithin interfaceVariableSpace- Parameters:
space- Variable space to be shared.
-
injectVariables
public void injectVariables(Map<String,String> prop)
Description copied from interface:VariableSpaceInject variables. The behaviour should be that the properties object will be stored and at the time the VariableSpace is initialized (or upon calling this method if the space is already initialized). After injecting the link of the properties object should be removed.- Specified by:
injectVariablesin interfaceVariableSpace- Parameters:
prop- Properties object containing key-value pairs.
-
getADefaultVariableSpace
public static VariableSpace getADefaultVariableSpace()
Get a default variable space as a placeholder. Everytime you will get a new instance.- Returns:
- a default variable space.
-
-