2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.core
.execution
.xml
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.core
.execution
.DefaultExecutionFlow
;
23 import org
.argeo
.slc
.execution
.ExecutionFlow
;
24 import org
.springframework
.beans
.factory
.config
.BeanDefinitionHolder
;
25 import org
.springframework
.beans
.factory
.config
.RuntimeBeanReference
;
26 import org
.springframework
.beans
.factory
.support
.BeanDefinitionBuilder
;
27 import org
.springframework
.beans
.factory
.support
.ManagedList
;
28 import org
.springframework
.beans
.factory
.xml
.BeanDefinitionDecorator
;
29 import org
.springframework
.beans
.factory
.xml
.ParserContext
;
30 import org
.w3c
.dom
.Attr
;
31 import org
.w3c
.dom
.Node
;
33 /** Publishes a {@link Runnable} as an {@link ExecutionFlow} */
34 public class AsFlowDecorator
implements BeanDefinitionDecorator
{
35 private Log log
= LogFactory
.getLog(AsFlowDecorator
.class);
37 @SuppressWarnings("unchecked")
38 public BeanDefinitionHolder
decorate(Node node
, BeanDefinitionHolder bean
,
40 String attrValue
= ((Attr
) node
).getValue();
41 if (attrValue
.charAt(attrValue
.length() - 1) == '/')
42 throw new SlcException(attrValue
+ " cannot end with a path");
43 final String flowBeanName
= attrValue
;
45 if (log
.isTraceEnabled())
46 log
.trace("flowBeanName=" + flowBeanName
);
48 if (ctx
.getRegistry().containsBeanDefinition(flowBeanName
))
49 throw new SlcException("A bean named " + flowBeanName
50 + " is already defined.");
51 BeanDefinitionBuilder flow
= BeanDefinitionBuilder
52 .rootBeanDefinition(DefaultExecutionFlow
.class);
53 ManagedList executables
= new ManagedList(1);
55 String beanName
= bean
.getBeanName();
57 executables
.add(bean
.getBeanDefinition());
59 executables
.add(new RuntimeBeanReference(beanName
));
62 // flow.addPropertyValue("path", path);
63 flow
.addPropertyValue("executables", executables
);
66 ctx
.getRegistry().registerBeanDefinition(flowBeanName
,
67 flow
.getBeanDefinition());