]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionSpec.java
6c46248419f0f801540be2c0ce027910713ba62b
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / DefaultExecutionSpec.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.UUID;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.slc.SlcException;
10 import org.argeo.slc.execution.ExecutionFlow;
11 import org.argeo.slc.execution.ExecutionSpec;
12 import org.argeo.slc.execution.ExecutionSpecAttribute;
13 import org.springframework.beans.factory.BeanNameAware;
14
15 public class DefaultExecutionSpec implements ExecutionSpec, BeanNameAware {
16 private final static Log log = LogFactory
17 .getLog(DefaultExecutionSpec.class);
18
19 private final static ThreadLocal<ExecutionFlow> initializingFlow = new ThreadLocal<ExecutionFlow>();
20
21 private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
22
23 private String name = getClass().getName() + "#" + UUID.randomUUID();
24
25 public Map<String, ExecutionSpecAttribute> getAttributes() {
26 return attributes;
27 }
28
29 public void setAttributes(Map<String, ExecutionSpecAttribute> attributes) {
30 this.attributes = attributes;
31 }
32
33 public Object createRef(String name) {
34 ExecutionFlow flow = initializingFlow.get();
35 if (flow == null)
36 throw new SlcException("No flow is currently initializing."
37 + " Declare flow refs as inner beans or prototypes.");
38 /*
39 * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
40 * .get(name); Class<?> targetClass = refSpecAttribute.getTargetClass();
41 * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow,
42 * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory();
43 * proxyFactory.setTargetClass(targetClass);
44 * proxyFactory.setProxyTargetClass(true);
45 * proxyFactory.setTargetSource(targetSource);
46 *
47 * return proxyFactory.getProxy();
48 */
49 return flow.getParameter(name);
50 }
51
52 public void setBeanName(String name) {
53 this.name = name;
54 }
55
56 public String getName() {
57 return name;
58 }
59
60 // FLOWS INITIALIZATION SUPPORT
61
62 public static void flowInitializationStarted(ExecutionFlow flow) {
63 if (log.isTraceEnabled())
64 log.trace("Start initialization of " + flow.hashCode() + " ("
65 + flow + " - " + flow.getClass() + ")");
66 initializingFlow.set(flow);
67 }
68
69 public static void flowInitializationFinished(ExecutionFlow flow) {
70 if (log.isTraceEnabled())
71 log.trace("Finish initialization of " + flow.hashCode() + " ("
72 + flow + " - " + flow.getClass() + ")");
73 ExecutionFlow registeredFlow = initializingFlow.get();
74 if (registeredFlow != null) {
75 if (!flow.getName().equals(registeredFlow.getName()))
76 throw new SlcException("Current flow is " + flow);
77 initializingFlow.set(null);
78 }
79 }
80
81 public static Object getInitializingFlowParameter(String key) {
82 if (initializingFlow.get() == null)
83 throw new SlcException("No initializing flow available.");
84 return initializingFlow.get().getParameter(key);
85 }
86
87 public static Boolean isInFlowInitialization() {
88 return initializingFlow.get() != null;
89 }
90
91 public boolean equals(Object obj) {
92 return ((ExecutionSpec) obj).getName().equals(name);
93 }
94
95 }