]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.spring/src/org/argeo/slc/core/execution/xml/AsFlowDecorator.java
b68d9c77dfda7136ad91507b17fccd75c83ebf1c
[gpl/argeo-slc.git] / cms / org.argeo.slc.spring / src / org / argeo / slc / core / execution / xml / AsFlowDecorator.java
1 package org.argeo.slc.core.execution.xml;
2
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;
17
18 /** Publishes a {@link Runnable} as an {@link ExecutionFlow} */
19 public class AsFlowDecorator implements BeanDefinitionDecorator {
20 private Log log = LogFactory.getLog(AsFlowDecorator.class);
21
22 public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder bean,
23 ParserContext ctx) {
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;
28
29 if (log.isTraceEnabled())
30 log.trace("flowBeanName=" + flowBeanName);
31
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>(
38 1);
39
40 String beanName = bean.getBeanName();
41 if (beanName == null)
42 executables.add(bean.getBeanDefinition());
43 else
44 executables.add(new RuntimeBeanReference(beanName));
45
46 // if (path != null)
47 // flow.addPropertyValue("path", path);
48 flow.addPropertyValue("executables", executables);
49
50 if (beanName != null)
51 ctx.getRegistry().registerBeanDefinition(flowBeanName,
52 flow.getBeanDefinition());
53 return bean;
54 }
55
56 }