1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.HashMap
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.slc
.SlcException
;
9 import org
.argeo
.slc
.execution
.ExecutionFlow
;
10 import org
.argeo
.slc
.execution
.ExecutionSpec
;
11 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
12 import org
.springframework
.beans
.factory
.BeanNameAware
;
14 public class DefaultExecutionSpec
implements ExecutionSpec
, BeanNameAware
{
15 private final static Log log
= LogFactory
.getLog(DefaultExecutionSpec
.class);
17 private final static ThreadLocal
<ExecutionFlow
> initializingFlow
= new ThreadLocal
<ExecutionFlow
>();
19 private Map
<String
, ExecutionSpecAttribute
> attributes
= new HashMap
<String
, ExecutionSpecAttribute
>();
21 private String name
= null;
23 public Map
<String
, ExecutionSpecAttribute
> getAttributes() {
27 public void setAttributes(Map
<String
, ExecutionSpecAttribute
> attributes
) {
28 this.attributes
= attributes
;
31 public Object
createRef(String name
) {
32 ExecutionFlow flow
= initializingFlow
.get();
34 throw new SlcException("No flow is currently initializing."
35 + " Declare flow refs as inner beans or prototypes.");
37 * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
38 * .get(name); Class<?> targetClass = refSpecAttribute.getTargetClass();
39 * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow,
40 * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory();
41 * proxyFactory.setTargetClass(targetClass);
42 * proxyFactory.setProxyTargetClass(true);
43 * proxyFactory.setTargetSource(targetSource);
45 * return proxyFactory.getProxy();
47 return flow
.getParameter(name
);
50 public void setBeanName(String name
) {
54 public String
getName() {
58 // FLOWS INITIALIZATION SUPPORT
60 public static void flowInitializationStarted(ExecutionFlow flow
) {
61 if (log
.isTraceEnabled())
62 log
.trace("Start initialization of " + flow
.hashCode() + " ("
63 + flow
+ " - " + flow
.getClass() + ")");
64 initializingFlow
.set(flow
);
67 public static void flowInitializationFinished(ExecutionFlow flow
) {
68 if (log
.isTraceEnabled())
69 log
.trace("Finish initialization of " + flow
.hashCode() + " ("
70 + flow
+ " - " + flow
.getClass() + ")");
71 ExecutionFlow registeredFlow
= initializingFlow
.get();
72 if (registeredFlow
!= null) {
73 if (!flow
.getName().equals(registeredFlow
.getName()))
74 throw new SlcException("Current flow is " + flow
);
75 initializingFlow
.set(null);
79 public static Object
getInitializingFlowParameter(String key
) {
80 if (initializingFlow
.get() == null)
81 throw new SlcException("No initializing flow available.");
82 return initializingFlow
.get().getParameter(key
);
85 public static Boolean
isInFlowInitialization() {
86 return initializingFlow
.get() != null;
89 public boolean equals(Object obj
) {
90 return ((ExecutionSpec
) obj
).getName().equals(name
);