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.persistence.jpa.OrmUtils; |
24 | |
import org.kuali.rice.core.impl.config.module.ModuleConfigurer; |
25 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
26 | |
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
27 | |
import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory; |
28 | |
import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory; |
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.Collection; |
38 | |
import java.util.Collections; |
39 | |
import java.util.LinkedList; |
40 | |
import java.util.List; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | public class KEWConfigurer extends ModuleConfigurer { |
60 | |
|
61 | |
public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource"; |
62 | |
|
63 | |
private DataSource dataSource; |
64 | |
|
65 | |
@Override |
66 | |
public List<String> getPrimarySpringFiles() { |
67 | |
final List<String> springFileLocations; |
68 | 0 | if (RunMode.REMOTE.equals(getRunMode()) || RunMode.THIN.equals(getRunMode()) || |
69 | |
ClientProtocol.WEBSERVICE.equals(getClientProtocol())) { |
70 | 0 | springFileLocations = Collections.emptyList(); |
71 | |
} else { |
72 | 0 | springFileLocations = getEmbeddedSpringFileLocation(); |
73 | |
} |
74 | |
|
75 | 0 | return springFileLocations; |
76 | |
} |
77 | |
|
78 | |
private List<String> getEmbeddedSpringFileLocation(){ |
79 | 0 | final List<String> springFileLocations = new ArrayList<String>(); |
80 | 0 | springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWSpringBeans.xml"); |
81 | |
|
82 | 0 | if ( isExposeServicesOnBus() ) { |
83 | 0 | springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml"); |
84 | |
} |
85 | |
|
86 | 0 | if (OrmUtils.isJpaEnabled("rice.kew")) { |
87 | 0 | springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml"); |
88 | |
} |
89 | |
else { |
90 | 0 | springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWOJBSpringBeans.xml"); |
91 | |
} |
92 | |
|
93 | 0 | return springFileLocations; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
public List<Lifecycle> loadLifecycles() throws Exception { |
98 | |
|
99 | 0 | List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); |
100 | 0 | if ( getRunMode().equals( RunMode.THIN ) ) { |
101 | 0 | lifecycles.add(createThinClientLifecycle()); |
102 | 0 | } else if ( !getRunMode().equals( RunMode.REMOTE ) ) { |
103 | 0 | lifecycles.add(createEmbeddedLifeCycle()); |
104 | |
} |
105 | 0 | return lifecycles; |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
private Lifecycle createEmbeddedLifeCycle() throws Exception { |
115 | 0 | return new EmbeddedLifeCycle(); |
116 | |
} |
117 | |
|
118 | |
private Lifecycle createThinClientLifecycle() throws Exception { |
119 | 0 | return new ThinClientLifecycle(); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public void addAdditonalToConfig() { |
124 | 0 | configureDataSource(); |
125 | 0 | } |
126 | |
|
127 | |
private void configureDataSource() { |
128 | 0 | if (getDataSource() != null) { |
129 | 0 | ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource()); |
130 | |
} |
131 | 0 | } |
132 | |
|
133 | |
@Override |
134 | |
public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception { |
135 | |
|
136 | 0 | PluginRegistry registry = null; |
137 | 0 | String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled"); |
138 | 0 | if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) { |
139 | 0 | registry = new PluginRegistryFactory().createPluginRegistry(); |
140 | |
} |
141 | |
|
142 | 0 | final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>(); |
143 | 0 | for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) { |
144 | 0 | CoreResourceLoader coreResourceLoader = |
145 | |
new CoreResourceLoader(rl, registry); |
146 | 0 | coreResourceLoader.start(); |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | 0 | GlobalResourceLoader.addResourceLoader(coreResourceLoader); |
153 | |
|
154 | |
|
155 | 0 | if (registry != null) { |
156 | 0 | registry.start(); |
157 | |
|
158 | |
|
159 | |
} |
160 | 0 | rls.add(coreResourceLoader); |
161 | 0 | } |
162 | |
|
163 | 0 | return rls; |
164 | |
} |
165 | |
|
166 | |
private ClientProtocol getClientProtocol() { |
167 | 0 | return ClientProtocol.valueOf(ConfigContext.getCurrentContextConfig().getProperty("client.protocol")); |
168 | |
} |
169 | |
|
170 | |
public DataSource getDataSource() { |
171 | 0 | return dataSource; |
172 | |
} |
173 | |
|
174 | |
public void setDataSource(DataSource dataSource) { |
175 | 0 | this.dataSource = dataSource; |
176 | 0 | } |
177 | |
} |