1 package org
.argeo
.slc
.core
.execution
.xml
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.slc
.SlcException
;
6 import org
.argeo
.slc
.core
.execution
.DefaultExecutionFlow
;
7 import org
.argeo
.slc
.execution
.ExecutionFlow
;
8 import org
.springframework
.beans
.BeanMetadataElement
;
9 import org
.springframework
.beans
.factory
.config
.BeanDefinitionHolder
;
10 import org
.springframework
.beans
.factory
.config
.RuntimeBeanReference
;
11 import org
.springframework
.beans
.factory
.support
.BeanDefinitionBuilder
;
12 import org
.springframework
.beans
.factory
.support
.ManagedList
;
13 import org
.springframework
.beans
.factory
.xml
.BeanDefinitionDecorator
;
14 import org
.springframework
.beans
.factory
.xml
.ParserContext
;
15 import org
.w3c
.dom
.Attr
;
16 import org
.w3c
.dom
.Node
;
18 /** Publishes a {@link Runnable} as an {@link ExecutionFlow} */
19 public class AsFlowDecorator
implements BeanDefinitionDecorator
{
20 private Log log
= LogFactory
.getLog(AsFlowDecorator
.class);
22 public BeanDefinitionHolder
decorate(Node node
, BeanDefinitionHolder bean
,
24 String attrValue
= ((Attr
) node
).getValue();
25 if (attrValue
.charAt(attrValue
.length() - 1) == '/')
26 throw new SlcException(attrValue
+ " cannot end with a path");
27 final String flowBeanName
= attrValue
;
29 if (log
.isTraceEnabled())
30 log
.trace("flowBeanName=" + flowBeanName
);
32 if (ctx
.getRegistry().containsBeanDefinition(flowBeanName
))
33 throw new SlcException("A bean named " + flowBeanName
34 + " is already defined.");
35 BeanDefinitionBuilder flow
= BeanDefinitionBuilder
36 .rootBeanDefinition(DefaultExecutionFlow
.class);
37 ManagedList
<BeanMetadataElement
> executables
= new ManagedList
<BeanMetadataElement
>(
40 String beanName
= bean
.getBeanName();
42 executables
.add(bean
.getBeanDefinition());
44 executables
.add(new RuntimeBeanReference(beanName
));
47 // flow.addPropertyValue("path", path);
48 flow
.addPropertyValue("executables", executables
);
51 ctx
.getRegistry().registerBeanDefinition(flowBeanName
,
52 flow
.getBeanDefinition());