1
|
package eu.dnetlib.msro.workflows.sarasvati.loader;
|
2
|
|
3
|
import org.springframework.beans.factory.annotation.Required;
|
4
|
import org.springframework.context.ApplicationContext;
|
5
|
import org.springframework.context.ApplicationContextAware;
|
6
|
|
7
|
import com.googlecode.sarasvati.Node;
|
8
|
import com.googlecode.sarasvati.load.DefaultNodeFactory;
|
9
|
import com.googlecode.sarasvati.load.SarasvatiLoadException;
|
10
|
import com.googlecode.sarasvati.mem.MemNode;
|
11
|
|
12
|
public class InjectableNodeFactory extends DefaultNodeFactory implements ApplicationContextAware {
|
13
|
|
14
|
private String beanNamePrefix = "wfNode";
|
15
|
|
16
|
private static final String DEFAULT_NODE_TYPE = "node";
|
17
|
|
18
|
private transient ApplicationContext applicationContext;
|
19
|
|
20
|
public InjectableNodeFactory() {
|
21
|
super(MemNode.class);
|
22
|
}
|
23
|
|
24
|
public InjectableNodeFactory(final Class<? extends Node> defaultClass) {
|
25
|
super(defaultClass);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public Node newNode(final String type) throws SarasvatiLoadException {
|
30
|
|
31
|
if (!DEFAULT_NODE_TYPE.equals(type)) {
|
32
|
final Node prototypeNode = (Node) applicationContext.getBean(beanNamePrefix + type, Node.class);
|
33
|
|
34
|
if (prototypeNode != null) {
|
35
|
return prototypeNode;
|
36
|
} else {
|
37
|
throw new SarasvatiLoadException("cannot find bean " + beanNamePrefix + type);
|
38
|
}
|
39
|
}
|
40
|
return super.newNode(type);
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public void setApplicationContext(final ApplicationContext context) {
|
45
|
this.applicationContext = context;
|
46
|
}
|
47
|
|
48
|
public String getBeanNamePrefix() {
|
49
|
return beanNamePrefix;
|
50
|
}
|
51
|
|
52
|
@Required
|
53
|
public void setBeanNamePrefix(final String beanNamePrefix) {
|
54
|
this.beanNamePrefix = beanNamePrefix;
|
55
|
}
|
56
|
|
57
|
}
|