1
2
3
4 package eu.diversit.jbpm.spring;
5
6 import org.jbpm.api.ExecutionService;
7 import org.jbpm.api.HistoryService;
8 import org.jbpm.api.IdentityService;
9 import org.jbpm.api.ManagementService;
10 import org.jbpm.api.ProcessEngine;
11 import org.jbpm.api.RepositoryService;
12 import org.jbpm.api.TaskService;
13 import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.beans.factory.annotation.Qualifier;
16 import org.springframework.beans.factory.config.BeanDefinition;
17 import org.springframework.context.ApplicationContext;
18 import org.springframework.context.annotation.Bean;
19 import org.springframework.context.annotation.Configuration;
20 import org.springframework.context.annotation.Scope;
21
22 import eu.diversit.jbpm.command.GetEnvironmentObject;
23
24
25
26
27
28
29
30 @Configuration
31 public class JbpmAutoSpringConfiguration {
32
33 protected String jbpmCfg = "jbpm.cfg.xml";
34
35 public void setJbpmCfg(String jbpmCfg) {
36 this.jbpmCfg = jbpmCfg;
37 }
38
39 @Autowired
40 private ApplicationContext applicationContext;
41
42 @Bean(name="jbpmProcessEngine")
43 @Scope(BeanDefinition.SCOPE_SINGLETON)
44 public ProcessEngine processEngine() {
45 return new ConfigurationImpl().springInitiated(applicationContext)
46 .setResource(jbpmCfg).buildProcessEngine();
47 }
48
49
50
51
52
53
54
55 @Bean(name = "jbpmExecutionService")
56 public ExecutionService executionService() {
57 return (ExecutionService) processEngine()
58 .execute(new GetEnvironmentObject(ExecutionService.class));
59 }
60
61
62
63
64
65
66
67 @Bean
68 @Qualifier("jbpmHistoryService")
69 public HistoryService historyService() {
70 return (HistoryService) processEngine().execute(new GetEnvironmentObject(
71 HistoryService.class));
72 }
73
74
75
76
77
78
79
80 @Bean
81 @Qualifier("jbpmIdentityService")
82 public IdentityService identityService() {
83 return (IdentityService) processEngine()
84 .execute(new GetEnvironmentObject(IdentityService.class));
85 }
86
87
88
89
90
91
92
93 @Bean
94 @Qualifier("jbpmManagementService")
95 public ManagementService managementService() {
96 return (ManagementService) processEngine()
97 .execute(new GetEnvironmentObject(ManagementService.class));
98 }
99
100
101
102
103
104
105
106 @Bean
107 @Qualifier("jbpmRepositoryService")
108 public RepositoryService repositoryService() {
109 return (RepositoryService) processEngine()
110 .execute(new GetEnvironmentObject(RepositoryService.class));
111 }
112
113
114
115
116
117
118 @Bean
119 @Qualifier("jbpmTaskService")
120 public TaskService taskService() {
121 return (TaskService) processEngine().execute(new GetEnvironmentObject(
122 TaskService.class));
123 }
124
125 }