1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.config;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.config.module.RunMode;
20 import org.kuali.rice.core.api.config.property.ConfigContext;
21 import org.kuali.rice.core.api.lifecycle.Lifecycle;
22 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
23 import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
24 import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
25 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
26 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
27 import org.kuali.rice.core.framework.resourceloader.RiceResourceLoaderFactory;
28 import org.kuali.rice.kew.api.KewApiConstants;
29 import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle;
30 import org.kuali.rice.kew.plugin.PluginRegistry;
31 import org.kuali.rice.kew.plugin.PluginRegistryFactory;
32 import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
33 import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol;
34
35 import javax.sql.DataSource;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import java.util.Collections;
40 import java.util.LinkedList;
41 import java.util.List;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class KEWConfigurer extends ModuleConfigurer {
61
62 public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
63
64 private DataSource dataSource;
65
66 public KEWConfigurer() {
67 super(KewApiConstants.Namespaces.MODULE_NAME);
68 setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
69 }
70
71 @Override
72 public List<String> getPrimarySpringFiles() {
73 List<String> springFileLocations = new ArrayList<String>();
74 if (RunMode.REMOTE == getRunMode()) {
75 springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml");
76 } else if (RunMode.EMBEDDED == getRunMode()) {
77 springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml");
78 } else if (RunMode.LOCAL == getRunMode()) {
79 springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml");
80 }
81 return springFileLocations;
82 }
83
84 @Override
85 public List<Lifecycle> loadLifecycles() throws Exception {
86
87 List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
88 if ( !getRunMode().equals( RunMode.REMOTE ) ) {
89 lifecycles.add(createEmbeddedLifeCycle());
90 }
91 return lifecycles;
92 }
93
94
95
96
97
98
99
100 private Lifecycle createEmbeddedLifeCycle() throws Exception {
101 return new EmbeddedLifeCycle();
102 }
103
104 @Override
105 public void addAdditonalToConfig() {
106 configureDataSource();
107 }
108
109 private void configureDataSource() {
110 if (getDataSource() != null) {
111 ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
112 }
113 }
114
115 @Override
116 public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
117
118 PluginRegistry registry = null;
119 String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
120 if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
121 registry = new PluginRegistryFactory().createPluginRegistry();
122 }
123
124 final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>();
125 for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) {
126 CoreResourceLoader coreResourceLoader =
127 new CoreResourceLoader(rl, registry);
128 coreResourceLoader.start();
129
130
131
132
133
134 GlobalResourceLoader.addResourceLoader(coreResourceLoader);
135
136
137 if (registry != null) {
138 registry.start();
139
140
141 }
142 rls.add(coreResourceLoader);
143 }
144
145 return rls;
146 }
147
148 public DataSource getDataSource() {
149 return dataSource;
150 }
151
152 public void setDataSource(DataSource dataSource) {
153 this.dataSource = dataSource;
154 }
155
156 @Override
157 public boolean hasWebInterface() {
158 return true;
159 }
160
161 @Override
162 protected WebModuleConfiguration loadWebModule() {
163 WebModuleConfiguration configuration = super.loadWebModule();
164 configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml"));
165 return configuration;
166 }
167 }