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
.generator
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
25 * Composite <code>RunnableFactory</code>, redirecting the Runnable
26 * creation to on of the configured <code>RunnableFactory</code> depending
27 * on an entry of the data of the <code>RunnableDataNode</code>.
29 public class CompositeRunnableFactory
implements RunnableFactory
{
32 * Key used to access factory ID in the data of the <code>RunnableDataNode</code>
34 private String factoryKey
;
37 * Maps a factory ID to an ExecutionFlowFactory
39 private Map
<String
, RunnableFactory
> factories
;
41 public void createAndRegisterRunnable(RunnableDataNode node
,
42 BeanDefinitionRegistry beanDefinitionRegistry
) {
43 findFactory(node
).createAndRegisterRunnable(node
, beanDefinitionRegistry
);
47 * Finds the <code>RunnableFactory</code> to use for a <code>RunnableDataNode</code>
49 * @return the <code>RunnableFactory</code> to use for the <code>RunnableDataNode</code>
51 private RunnableFactory
findFactory(RunnableDataNode node
) {
52 // get the factory ID from the data of the RunnableDescriptor
53 Map
<String
, Object
> data
= node
.getData();
54 if (!data
.containsKey(factoryKey
)) {
55 throw new SlcException("No data value for key '" + factoryKey
+ "'");
57 String factoryId
= data
.get(factoryKey
).toString();
59 // see if we have a factory for the factory ID
60 if ((factories
!= null) && factories
.containsKey(factoryId
)) {
61 return factories
.get(factoryId
);
63 // if not, look for a bean of name equals to the factory ID
65 throw new SlcException("Not implemented");
69 public void setFactoryKey(String factoryKey
) {
70 this.factoryKey
= factoryKey
;
73 public void setFactories(Map
<String
, RunnableFactory
> factories
) {
74 this.factories
= factories
;