1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.HashMap
;
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
;
15 public class DefaultExecutionSpec
implements ExecutionSpec
, BeanNameAware
{
16 private final static Log log
= LogFactory
17 .getLog(DefaultExecutionSpec
.class);
19 private final static ThreadLocal
<ExecutionFlow
> initializingFlow
= new ThreadLocal
<ExecutionFlow
>();
21 private Map
<String
, ExecutionSpecAttribute
> attributes
= new HashMap
<String
, ExecutionSpecAttribute
>();
23 private String name
= getClass().getName() + "#" + UUID
.randomUUID();
25 public Map
<String
, ExecutionSpecAttribute
> getAttributes() {
29 public void setAttributes(Map
<String
, ExecutionSpecAttribute
> attributes
) {
30 this.attributes
= attributes
;
33 public Object
createRef(String name
) {
34 ExecutionFlow flow
= initializingFlow
.get();
36 throw new SlcException("No flow is currently initializing."
37 + " Declare flow refs as inner beans or prototypes.");
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);
47 * return proxyFactory.getProxy();
49 return flow
.getParameter(name
);
52 public void setBeanName(String name
) {
56 public String
getName() {
60 // FLOWS INITIALIZATION SUPPORT
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
);
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);
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
);
87 public static Boolean
isInFlowInitialization() {
88 return initializingFlow
.get() != null;
91 public boolean equals(Object obj
) {
92 return ((ExecutionSpec
) obj
).getName().equals(name
);