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
;
19 import java
.util
.List
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.springframework
.beans
.BeansException
;
26 import org
.springframework
.beans
.MutablePropertyValues
;
27 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
28 import org
.springframework
.beans
.factory
.config
.BeanFactoryPostProcessor
;
29 import org
.springframework
.beans
.factory
.config
.ConfigurableListableBeanFactory
;
30 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
31 import org
.springframework
.beans
.factory
.support
.GenericBeanDefinition
;
32 import org
.springframework
.core
.Ordered
;
33 import org
.springframework
.core
.PriorityOrdered
;
35 public abstract class AbstractExecutionFlowGenerator
implements
36 BeanFactoryPostProcessor
, PriorityOrdered
{
37 private final Log log
= LogFactory
.getLog(getClass());
39 protected abstract Map
<String
, BeanDefinition
> createExecutionFlowDefinitions(
40 ConfigurableListableBeanFactory beanFactory
);
42 public void postProcessBeanFactory(
43 ConfigurableListableBeanFactory beanFactory
) throws BeansException
{
44 if (!(beanFactory
instanceof BeanDefinitionRegistry
)) {
45 throw new SlcException("Can only work on "
46 + BeanDefinitionRegistry
.class);
49 Map
<String
, BeanDefinition
> definitions
= createExecutionFlowDefinitions(beanFactory
);
51 for (String beanName
: definitions
.keySet()) {
52 if (log
.isTraceEnabled())
53 log
.debug("Registering execution flow " + beanName
);
54 ((BeanDefinitionRegistry
) beanFactory
).registerBeanDefinition(
55 beanName
, definitions
.get(beanName
));
59 protected GenericBeanDefinition
createDefaultFlowDefinition(
60 List
<Runnable
> executables
) {
61 GenericBeanDefinition bd
= new GenericBeanDefinition();
62 bd
.setBeanClass(DefaultExecutionFlow
.class);
64 MutablePropertyValues mpv
= new MutablePropertyValues();
65 mpv
.addPropertyValue("executables", executables
);
67 bd
.setPropertyValues(mpv
);
71 public int getOrder() {
72 return Ordered
.HIGHEST_PRECEDENCE
;