/** @see Execution#setVariable(String, Object) */
public void setVariable(String key, Object value) {
// first search for the most inner variable scope that has a variable for
// the given key
VariableScope variableScope = findVariableScope(key);
// if no variable scope exists for the given variable
if (variableScope==null) {
// then take the most outer scope of the process instance
List<VariableScope> processInstanceVariableScopes = processInstance.getVariableScopes();
if ( (processInstanceVariableScopes!=null)
&& (! processInstanceVariableScopes.isEmpty())
) {
int lastIndex = processInstanceVariableScopes.size()-1;
variableScope = processInstanceVariableScopes.get(lastIndex);
} else { // means the process instance doesn't have a variable scope yet
// create the most outer variable scope
variableScope = processInstance.createVariableScope();
}
}
variableScope.set(key, value);
}