]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java
@update:81; Ability to copy the content of resources locally, thus enabling launchyin...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / MapExecutionContext.java
index 8c69d7c62c9cf74277105edcd74b67e900b862d4..f38342662852747f4f3aeba405e39bb813907010 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.core.execution;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Stack;
@@ -11,25 +12,27 @@ import org.argeo.slc.SlcException;
 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 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();
+       private final String uuid;
+
+       private final Date creationDate = new Date();
 
-/*     public Map<String, Object> getVariables() {
-               return variables;
-       }*/
-       
-       public void addVariables(Map<? extends String, ? extends Object> variablesToAdd) {
+       public MapExecutionContext() {
+               uuid = UUID.randomUUID().toString();
+               if (log.isDebugEnabled())
+                       log.debug("Execution context #" + uuid + " instantiated.");
+       }
+
+       public void addVariables(
+                       Map<? extends String, ? extends Object> variablesToAdd) {
                variables.putAll(variablesToAdd);
        }
 
@@ -44,7 +47,7 @@ public class MapExecutionContext implements ExecutionContext {
                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));
@@ -63,14 +66,14 @@ public class MapExecutionContext implements ExecutionContext {
                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) {
@@ -108,21 +111,11 @@ public class MapExecutionContext implements ExecutionContext {
 
        }
 
-/*     public Object findOrAddScopedObject(String name, ObjectFactory objectFactory) {
-               Object obj = findScopedObject(name);
-               if (obj == null) {
-                       obj = objectFactory.getObject();
-                       stack.peek().getScopedObjects().put(name, obj);
-               }
-               return obj;
-       }*/
-
-       
        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;
@@ -139,6 +132,10 @@ public class MapExecutionContext implements ExecutionContext {
                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>();