package org.argeo.slc.core.execution;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.argeo.slc.execution.ExecutionContext;
import org.argeo.slc.execution.ExecutionFlow;
import org.argeo.slc.execution.ExecutionSpecAttribute;
-import org.argeo.slc.process.SlcExecution;
-import org.springframework.beans.factory.ObjectFactory;
public class MapExecutionContext implements ExecutionContext {
- private final static Log log = LogFactory.getLog(MapExecutionContext.class);
+ private final static Log log = LogFactory.getLog(MapExecutionContext.class);
private final Stack<ExecutionFlowRuntime> stack = new Stack<ExecutionFlowRuntime>();
// TODO: make it thread safe?
private final Map<String, Object> variables = new HashMap<String, Object>();
- private final String uuid = UUID.randomUUID().toString();
-
- public void addVariables(Map<? extends String, ? extends Object> variablesToAdd) {
+ private final String uuid;
+
+ private final Date creationDate = new Date();
+
+ public MapExecutionContext() {
+ uuid = UUID.randomUUID().toString();
+ variables.put(VAR_EXECUTION_CONTEXT_ID, uuid);
+ }
+
+ public void addVariables(
+ Map<? extends String, ? extends Object> variablesToAdd) {
variables.putAll(variablesToAdd);
}
public void enterFlow(ExecutionFlow executionFlow) {
ExecutionFlowRuntime runtime = new ExecutionFlowRuntime(executionFlow);
stack.push(runtime);
+ variables.put(VAR_FLOW_ID, runtime.getUuid());
+ variables.put(VAR_FLOW_NAME, runtime.getExecutionFlow().getName());
if (log.isDebugEnabled())
log.debug(depthSpaces(stack.size()) + "=> " + executionFlow + " #"
Map<String, ExecutionSpecAttribute> specAttrs = executionFlow
.getExecutionSpec().getAttributes();
for (String key : specAttrs.keySet()) {
- //ExecutionSpecAttribute esa = specAttrs.get(key);
+ // ExecutionSpecAttribute esa = specAttrs.get(key);
if (executionFlow.isSetAsParameter(key)) {
runtime.getLocalVariables().put(key,
executionFlow.getParameter(key));
return obj;
}
- protected Object findVariable(String key) {
+ public Object findVariable(String key) {
Object obj = null;
-
+
// Look if the variable is set in the global execution variables
// (i.e. the variable was overridden)
if (variables.containsKey(key))
- obj = variables.get(key);
-
+ obj = variables.get(key);
+
// if the variable was not found, look in the stack starting at the
// upper flows
if (obj == null) {
leftEf.getLocalVariables().clear();
}
-
+
public void addScopedObject(String name, Object obj) {
- //TODO: check that the object is not set yet ?
+ // TODO: check that the object is not set yet ?
stack.peek().getScopedObjects().put(name, obj);
}
-
+
/** return null if not found */
public Object findScopedObject(String name) {
Object obj = null;
return uuid;
}
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
private static class ExecutionFlowRuntime {
private final ExecutionFlow executionFlow;
private final Map<String, Object> scopedObjects = new HashMap<String, Object>();