X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Fgenerator%2FRunnableCallFlow.java;fp=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Fgenerator%2FRunnableCallFlow.java;h=bebf6faa0c6cd84a85e419962086f4733e40cfa8;hb=a18184e7d6bb5cc2cd6763439310061c60a00a78;hp=4e58bfc146b0f4576866156d3339c3f262cdcb0a;hpb=de800eefab021b149a8e6dccadbcae9fd40dbc3c;p=gpl%2Fargeo-slc.git
diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/RunnableCallFlow.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/RunnableCallFlow.java
index 4e58bfc14..bebf6faa0 100644
--- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/RunnableCallFlow.java
+++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/RunnableCallFlow.java
@@ -14,114 +14,126 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
- * Execution Flow calling a list of Runnable
(identified by their bean
- * name in the Spring Application Context) after configuring the Execution
- * context and a Map potentially shared by the called Runnable
- *
+ * Execution Flow calling a list of Runnable
(identified by their
+ * bean name in the Spring Application Context) after configuring the Execution
+ * context and a Map potentially shared by the called Runnable
+ *
*/
public class RunnableCallFlow implements ExecutionFlow, ApplicationContextAware {
- private final static Log log = LogFactory.getLog(RunnableCallFlow.class);
-
+ private final static Log log = LogFactory.getLog(RunnableCallFlow.class);
+
/**
- * Key in the execution context for the index of the call (e.g. 0
- * for the first runnable called, ...)
+ * Key in the execution context for the index of the call (e.g. 0 for the
+ * first runnable called, ...)
*/
public final static String VAR_CALL_INDEX = "slcVar.runnableCallFlow.callIndex";
-
+
/**
* Name of the flow. Also bean name
*/
private String name;
-
+
/**
* Path of the flow
*/
private String path;
/**
- * Whether an exception in a Runnable
shall
- * stop the execution of the flow
+ * Whether an exception in a Runnable
shall stop the execution
+ * of the flow
*/
- private Boolean failOnError = true;
-
+ private Boolean failOnError = true;
+
/**
- * List of Runnable
to call, with bean name, execution variables and
- * context values
+ * List of Runnable
to call, with bean name, execution
+ * variables and context values
*/
private List runnableCalls;
-
+
/**
- * Map potentially referenced by called flows. Updated with
- * the context values of a Runnable before calling it.
+ * Map potentially referenced by called flows. Updated with the context
+ * values of a Runnable before calling it.
*/
private Map sharedContextValuesMap;
-
+
/**
- * ExecutionSpec of the flow. Does not contain any
- * attribute.
+ * ExecutionSpec of the flow. Does not contain any attribute.
*/
- private ExecutionSpec executionSpec = new DefaultExecutionSpec();
-
+ private ExecutionSpec executionSpec = new DefaultExecutionSpec();
+
/**
* Reference to the ExecutionContext
*/
- private ExecutionContext executionContext;
-
+ private ExecutionContext executionContext;
+
/**
- * Reference to the Spring ApplicationContext
.
- * Set via setApplicationContext
, the class implementing
+ * Reference to the Spring ApplicationContext
. Set via
+ * setApplicationContext
, the class implementing
* ApplicationContextAware
*/
private ApplicationContext applicationContext;
-
+
/**
- * Runs a Runnable
after configuring the Execution Context
- * and sharedContextValuesMap
- * @param runnable the Runnable
to call
- * @param executionVariables the variables to add to the ExecutionContext
- * @param contextValues the variables to add to sharedContextValuesMap
- * @param callIndex index of the call (0 for the first called Runnable
)
- * set as variable of the ExecutionContext
+ * Runs a Runnable
after configuring the Execution Context and
+ * sharedContextValuesMap
+ *
+ * @param runnable
+ * the Runnable
to call
+ * @param executionVariables
+ * the variables to add to the ExecutionContext
+ * @param contextValues
+ * the variables to add to sharedContextValuesMap
+ * @param callIndex
+ * index of the call (0 for the first called
+ * Runnable
) set as variable of the
+ * ExecutionContext
*/
- private void run(Runnable runnable, Map executionVariables, Map contextValues, int callIndex) {
+ private void run(Runnable runnable, Map executionVariables,
+ Map contextValues, int callIndex) {
// add all variables to the Execution Context
- for(Map.Entry entry : executionVariables.entrySet()) {
+ for (Map.Entry entry : executionVariables.entrySet()) {
executionContext.setVariable(entry.getKey(), entry.getValue());
}
-
+
// add call Index Variable
executionContext.setVariable(VAR_CALL_INDEX, callIndex);
-
+
// clear sharedContextValues and add all values of contextValues
- if(sharedContextValuesMap != null) {
+ if (sharedContextValuesMap != null) {
sharedContextValuesMap.clear();
sharedContextValuesMap.putAll(contextValues);
}
-
+
// then run the runnable
+ doExecuteRunnable(runnable);
+ }
+
+ public void doExecuteRunnable(Runnable runnable) {
runnable.run();
}
-
+
/**
- * Executes the flow.
- * For each RunnableCall
, the corresponding flow
- * is retrieved from the Spring Application Context, the
- * ExecutionContext
and sharedContextValuesMap
- * are configured and the Runnable
is called.
+ * Executes the flow. For each RunnableCall
, the corresponding
+ * flow is retrieved from the Spring Application Context, the
+ * ExecutionContext
and sharedContextValuesMap
are
+ * configured and the Runnable
is called.
*/
public void run() {
if (applicationContext == null) {
throw new SlcException("No ApplicationContext defined");
- }
-
+ }
+
try {
- for(int callIndex = 0; callIndex < runnableCalls.size(); ++callIndex) {
+ for (int callIndex = 0; callIndex < runnableCalls.size(); ++callIndex) {
RunnableCall runnableCall = runnableCalls.get(callIndex);
- Object bean = applicationContext.getBean(runnableCall.getBeanName(), Runnable.class);
- if(log.isDebugEnabled())
- log.debug("Running flow '" + runnableCall.getBeanName() + "'");
- run((Runnable)bean, runnableCall.getExecutionVariables(), runnableCall.getContextValues(), callIndex);
+ Object bean = applicationContext.getBean(runnableCall
+ .getBeanName(), Runnable.class);
+ if (log.isDebugEnabled())
+ log.debug("Running flow '" + runnableCall.getBeanName()
+ + "'");
+ run((Runnable) bean, runnableCall.getExecutionVariables(),
+ runnableCall.getContextValues(), callIndex);
}
} catch (RuntimeException e) {
if (failOnError)
@@ -134,7 +146,7 @@ public class RunnableCallFlow implements ExecutionFlow, ApplicationContextAware
if (log.isTraceEnabled())
e.printStackTrace();
}
- }
+ }
}
public ExecutionSpec getExecutionSpec() {
@@ -157,8 +169,8 @@ public class RunnableCallFlow implements ExecutionFlow, ApplicationContextAware
// The ExecutionSpec having no attribute,
// always return false
return false;
- }
-
+ }
+
public void setName(String name) {
this.name = name;
}