2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.slc
.core
.execution
.generator
;
20 import org
.argeo
.slc
.SlcException
;
21 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
24 * Composite <code>RunnableFactory</code>, redirecting the Runnable
25 * creation to on of the configured <code>RunnableFactory</code> depending
26 * on an entry of the data of the <code>RunnableDataNode</code>.
28 public class CompositeRunnableFactory
implements RunnableFactory
{
31 * Key used to access factory ID in the data of the <code>RunnableDataNode</code>
33 private String factoryKey
;
36 * Maps a factory ID to an ExecutionFlowFactory
38 private Map
<String
, RunnableFactory
> factories
;
40 public void createAndRegisterRunnable(RunnableDataNode node
,
41 BeanDefinitionRegistry beanDefinitionRegistry
) {
42 findFactory(node
).createAndRegisterRunnable(node
, beanDefinitionRegistry
);
46 * Finds the <code>RunnableFactory</code> to use for a <code>RunnableDataNode</code>
48 * @return the <code>RunnableFactory</code> to use for the <code>RunnableDataNode</code>
50 private RunnableFactory
findFactory(RunnableDataNode node
) {
51 // get the factory ID from the data of the RunnableDescriptor
52 Map
<String
, Object
> data
= node
.getData();
53 if (!data
.containsKey(factoryKey
)) {
54 throw new SlcException("No data value for key '" + factoryKey
+ "'");
56 String factoryId
= data
.get(factoryKey
).toString();
58 // see if we have a factory for the factory ID
59 if ((factories
!= null) && factories
.containsKey(factoryId
)) {
60 return factories
.get(factoryId
);
62 // if not, look for a bean of name equals to the factory ID
64 throw new SlcException("Not implemented");
68 public void setFactoryKey(String factoryKey
) {
69 this.factoryKey
= factoryKey
;
72 public void setFactories(Map
<String
, RunnableFactory
> factories
) {
73 this.factories
= factories
;