]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/AsFlowDecorator.java
Remove unnecessary check causing failures
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / xml / AsFlowDecorator.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.core.execution.xml;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.argeo.slc.SlcException;
21 import org.argeo.slc.core.execution.DefaultExecutionFlow;
22 import org.argeo.slc.execution.ExecutionFlow;
23 import org.springframework.beans.factory.config.BeanDefinitionHolder;
24 import org.springframework.beans.factory.config.RuntimeBeanReference;
25 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
26 import org.springframework.beans.factory.support.ManagedList;
27 import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
28 import org.springframework.beans.factory.xml.ParserContext;
29 import org.w3c.dom.Attr;
30 import org.w3c.dom.Node;
31
32 /** Publishes a {@link Runnable} as an {@link ExecutionFlow} */
33 public class AsFlowDecorator implements BeanDefinitionDecorator {
34 private Log log = LogFactory.getLog(AsFlowDecorator.class);
35
36 @SuppressWarnings("unchecked")
37 public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder bean,
38 ParserContext ctx) {
39 String attrValue = ((Attr) node).getValue();
40 if (attrValue.charAt(attrValue.length() - 1) == '/')
41 throw new SlcException(attrValue + " cannot end with a path");
42 final String flowBeanName = attrValue;
43
44 if (log.isTraceEnabled())
45 log.trace("flowBeanName=" + flowBeanName);
46
47 if (ctx.getRegistry().containsBeanDefinition(flowBeanName))
48 throw new SlcException("A bean named " + flowBeanName
49 + " is already defined.");
50 BeanDefinitionBuilder flow = BeanDefinitionBuilder
51 .rootBeanDefinition(DefaultExecutionFlow.class);
52 ManagedList executables = new ManagedList(1);
53
54 String beanName = bean.getBeanName();
55 if (beanName == null)
56 executables.add(bean.getBeanDefinition());
57 else
58 executables.add(new RuntimeBeanReference(beanName));
59
60 // if (path != null)
61 // flow.addPropertyValue("path", path);
62 flow.addPropertyValue("executables", executables);
63
64 if (beanName != null)
65 ctx.getRegistry().registerBeanDefinition(flowBeanName,
66 flow.getBeanDefinition());
67 return bean;
68 }
69
70 }