View Javadoc

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   * Factory bean which create the JBPM Process Engine.
26   * 
27   * @author joostdenboer
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  	 * Provides the {@link ExecutionService}. Qualifier name is
51  	 * 'jbpmExecutionService'.
52  	 * 
53  	 * @return {@link ExecutionService}
54  	 */
55  	@Bean(name = "jbpmExecutionService")
56  	public ExecutionService executionService() {
57  		return (ExecutionService) processEngine()
58  				.execute(new GetEnvironmentObject(ExecutionService.class));
59  	}
60  
61  	/**
62  	 * Provides the {@link HistoryService}. Qualifier name is
63  	 * 'jbpmHistoryService'.
64  	 * 
65  	 * @return {@link HistoryService}
66  	 */
67  	@Bean
68  	@Qualifier("jbpmHistoryService")
69  	public HistoryService historyService() {
70  		return (HistoryService) processEngine().execute(new GetEnvironmentObject(
71  				HistoryService.class));
72  	}
73  
74  	/**
75  	 * Provides the {@link IdentityService}. Qualifier name is
76  	 * 'jbpmIdentityService'.
77  	 * 
78  	 * @return {@link IdentityService}
79  	 */
80  	@Bean
81  	@Qualifier("jbpmIdentityService")
82  	public IdentityService identityService() {
83  		return (IdentityService) processEngine()
84  				.execute(new GetEnvironmentObject(IdentityService.class));
85  	}
86  
87  	/**
88  	 * Provides the {@link ManagementService}. Qualifier name is
89  	 * 'jbpmManagementService'.
90  	 * 
91  	 * @return {@link ManagementService}
92  	 */
93  	@Bean
94  	@Qualifier("jbpmManagementService")
95  	public ManagementService managementService() {
96  		return (ManagementService) processEngine()
97  				.execute(new GetEnvironmentObject(ManagementService.class));
98  	}
99  
100 	/**
101 	 * Provides the {@link RepositoryService}. Qualifier name is
102 	 * 'jbpmRepositoryService'.
103 	 * 
104 	 * @return {@link RepositoryService}
105 	 */
106 	@Bean
107 	@Qualifier("jbpmRepositoryService")
108 	public RepositoryService repositoryService() {
109 		return (RepositoryService) processEngine()
110 				.execute(new GetEnvironmentObject(RepositoryService.class));
111 	}
112 
113 	/**
114 	 * Provides the {@link TaskService}. Qualifier name is 'jbpmTaskService'.
115 	 * 
116 	 * @return {@link TaskService}
117 	 */
118 	@Bean
119 	@Qualifier("jbpmTaskService")
120 	public TaskService taskService() {
121 		return (TaskService) processEngine().execute(new GetEnvironmentObject(
122 				TaskService.class));
123 	}
124 
125 }