| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.config; |
| 18 | |
|
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.config.*; |
| 21 | |
import org.kuali.rice.core.lifecycle.Lifecycle; |
| 22 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
| 23 | |
import org.kuali.rice.core.resourceloader.ResourceLoader; |
| 24 | |
import org.kuali.rice.core.resourceloader.RiceResourceLoaderFactory; |
| 25 | |
import org.kuali.rice.core.resourceloader.SpringLoader; |
| 26 | |
import org.kuali.rice.core.util.OrmUtils; |
| 27 | |
import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle; |
| 28 | |
import org.kuali.rice.kew.plugin.PluginRegistry; |
| 29 | |
import org.kuali.rice.kew.plugin.PluginRegistryFactory; |
| 30 | |
import org.kuali.rice.kew.resourceloader.CoreResourceLoader; |
| 31 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 32 | |
|
| 33 | |
import javax.sql.DataSource; |
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.LinkedList; |
| 36 | |
import java.util.List; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public class KEWConfigurer extends ModuleConfigurer { |
| 56 | |
|
| 57 | |
public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource"; |
| 58 | |
public static final String KEW_DATASOURCE_JNDI = "org.kuali.workflow.datasource.jndi.location"; |
| 59 | |
private static final String ADDITIONAL_SPRING_FILES_PARAM = "kew.additionalSpringFiles"; |
| 60 | |
|
| 61 | |
private String clientProtocol; |
| 62 | |
|
| 63 | |
private DataSource dataSource; |
| 64 | |
private String dataSourceJndiName; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public KEWConfigurer() { |
| 69 | 0 | super(); |
| 70 | 0 | setModuleName( "KEW" ); |
| 71 | 0 | setHasWebInterface( true ); |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public String getSpringFileLocations(){ |
| 76 | |
String springFileLocations; |
| 77 | 0 | if (KEWConfigurer.REMOTE_RUN_MODE.equals(getRunMode()) || KEWConfigurer.THIN_RUN_MODE.equals(getRunMode()) || |
| 78 | |
KEWConstants.WEBSERVICE_CLIENT_PROTOCOL.equals(ConfigContext.getCurrentContextConfig().getClientProtocol())) { |
| 79 | 0 | springFileLocations = ""; |
| 80 | |
} else { |
| 81 | 0 | springFileLocations = getEmbeddedSpringFileLocation(); |
| 82 | |
} |
| 83 | |
|
| 84 | 0 | return springFileLocations; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public String getEmbeddedSpringFileLocation(){ |
| 88 | 0 | String springLocation = ConfigContext.getCurrentContextConfig().getAlternateSpringFile(); |
| 89 | 0 | if (springLocation == null) { |
| 90 | 0 | springLocation = "classpath:org/kuali/rice/kew/config/KEWSpringBeans.xml"; |
| 91 | |
} |
| 92 | |
|
| 93 | 0 | if ( exposeServicesOnBus ) { |
| 94 | 0 | if (setSOAPServicesAsDefault) { |
| 95 | 0 | springLocation += "," + "classpath:org/kuali/rice/kew/config/KEWServiceBusSOAPDefaultSpringBeans.xml"; |
| 96 | |
} else { |
| 97 | 0 | springLocation += "," + "classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml"; |
| 98 | |
} |
| 99 | |
} |
| 100 | |
|
| 101 | 0 | springLocation += SpringLoader.SPRING_SEPARATOR_CHARACTER; |
| 102 | |
|
| 103 | 0 | if (OrmUtils.isJpaEnabled("rice.kew")) { |
| 104 | 0 | springLocation += "classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml"; |
| 105 | |
} |
| 106 | |
else { |
| 107 | 0 | springLocation += "classpath:org/kuali/rice/kew/config/KEWOJBSpringBeans.xml"; |
| 108 | |
} |
| 109 | |
|
| 110 | 0 | String additionalSpringFiles = ConfigContext.getCurrentContextConfig().getProperty(ADDITIONAL_SPRING_FILES_PARAM); |
| 111 | 0 | if(StringUtils.isNotEmpty(additionalSpringFiles) && additionalSpringFiles.contains(",")) |
| 112 | 0 | StringUtils.split(additionalSpringFiles, ","); |
| 113 | |
String[] springLocations; |
| 114 | 0 | if (!StringUtils.isEmpty(additionalSpringFiles)) { |
| 115 | 0 | springLocations = new String[2]; |
| 116 | 0 | springLocations[0] = "," + additionalSpringFiles; |
| 117 | |
} |
| 118 | 0 | return springLocation; |
| 119 | |
} |
| 120 | |
|
| 121 | |
@Override |
| 122 | |
protected List<Lifecycle> loadLifecycles() throws Exception { |
| 123 | 0 | List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); |
| 124 | 0 | if ( getRunMode().equals( THIN_RUN_MODE ) ) { |
| 125 | 0 | lifecycles.add(createThinClientLifecycle()); |
| 126 | 0 | } else if ( !getRunMode().equals( REMOTE_RUN_MODE ) ) { |
| 127 | 0 | lifecycles.add(createEmbeddedLifeCycle()); |
| 128 | |
} |
| 129 | 0 | return lifecycles; |
| 130 | |
} |
| 131 | |
|
| 132 | |
protected boolean isStandaloneServer() { |
| 133 | 0 | return getRunMode().equals( LOCAL_RUN_MODE ); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
protected Lifecycle createEmbeddedLifeCycle() throws Exception { |
| 143 | 0 | return new EmbeddedLifeCycle(); |
| 144 | |
} |
| 145 | |
|
| 146 | |
protected Lifecycle createThinClientLifecycle() throws Exception { |
| 147 | 0 | return new ThinClientLifecycle(); |
| 148 | |
} |
| 149 | |
|
| 150 | |
@Override |
| 151 | |
public Config loadConfig(Config parentConfig) throws Exception { |
| 152 | 0 | parentConfig = super.loadConfig(parentConfig); |
| 153 | 0 | Config currentConfig = parseConfig(parentConfig); |
| 154 | 0 | configureClientProtocol(currentConfig); |
| 155 | 0 | configureDataSource(currentConfig); |
| 156 | 0 | return currentConfig; |
| 157 | |
} |
| 158 | |
|
| 159 | |
protected Config parseConfig(Config parentConfig) throws Exception { |
| 160 | 0 | List<String> defaultConfigLocations = new ArrayList<String>(); |
| 161 | 0 | defaultConfigLocations.add(KEWConstants.DEFAULT_GLOBAL_CONFIG_LOCATION); |
| 162 | 0 | defaultConfigLocations.add(KEWConstants.DEFAULT_APPLICATION_CONFIG_LOCATION); |
| 163 | |
|
| 164 | 0 | Config kewConfig = new JAXBConfigImpl(defaultConfigLocations, parentConfig.getProperties()); |
| 165 | |
|
| 166 | 0 | kewConfig.parseConfig(); |
| 167 | 0 | mergeDefaultsIntoParentConfig(parentConfig, kewConfig); |
| 168 | 0 | return parentConfig; |
| 169 | |
} |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
protected void mergeDefaultsIntoParentConfig(Config parentConfig, Config defaultConfig) { |
| 180 | 0 | for (Object keyObj : defaultConfig.getProperties().keySet()) { |
| 181 | 0 | String key = (String)keyObj; |
| 182 | 0 | if (!parentConfig.getProperties().containsKey(key)) { |
| 183 | 0 | parentConfig.putProperty(key, defaultConfig.getProperty(key)); |
| 184 | |
} |
| 185 | 0 | } |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
protected String getServiceNamespace(Config config) { |
| 189 | 0 | if (StringUtils.isBlank(config.getServiceNamespace())) { |
| 190 | 0 | throw new ConfigurationException("The 'service.namespace' property was not properly configured."); |
| 191 | |
} |
| 192 | 0 | return config.getServiceNamespace(); |
| 193 | |
} |
| 194 | |
|
| 195 | |
protected void configureClientProtocol(Config config) { |
| 196 | 0 | if (StringUtils.isBlank(clientProtocol)) { |
| 197 | 0 | clientProtocol = config.getClientProtocol(); |
| 198 | 0 | if (StringUtils.isBlank(clientProtocol)) { |
| 199 | |
|
| 200 | 0 | if ( getRunMode().equals( REMOTE_RUN_MODE ) || getRunMode().equals( THIN_RUN_MODE ) ) { |
| 201 | 0 | clientProtocol = KEWConstants.WEBSERVICE_CLIENT_PROTOCOL; |
| 202 | |
} else { |
| 203 | 0 | clientProtocol = KEWConstants.LOCAL_CLIENT_PROTOCOL; |
| 204 | |
} |
| 205 | |
} |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | 0 | if (!KEWConstants.CLIENT_PROTOCOLS.contains(clientProtocol)) { |
| 213 | 0 | throw new ConfigurationException("Invalid client protocol specified '" + clientProtocol + "'."); |
| 214 | |
} |
| 215 | 0 | config.putProperty(Config.CLIENT_PROTOCOL, clientProtocol); |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
protected void configureDataSource(Config config) { |
| 219 | 0 | if (getDataSource() != null) { |
| 220 | 0 | config.putObject(KEW_DATASOURCE_OBJ, getDataSource()); |
| 221 | 0 | } else if (!StringUtils.isBlank(getDataSourceJndiName())) { |
| 222 | 0 | config.putProperty(KEW_DATASOURCE_JNDI, getDataSourceJndiName()); |
| 223 | |
} |
| 224 | 0 | } |
| 225 | |
|
| 226 | |
public ResourceLoader getResourceLoaderToRegister() throws Exception{ |
| 227 | |
|
| 228 | 0 | PluginRegistry registry = null; |
| 229 | 0 | String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled"); |
| 230 | 0 | if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled)) { |
| 231 | 0 | registry = new PluginRegistryFactory().createPluginRegistry(); |
| 232 | |
} |
| 233 | |
|
| 234 | 0 | CoreResourceLoader coreResourceLoader = |
| 235 | |
new CoreResourceLoader(RiceResourceLoaderFactory.getSpringResourceLoader(), registry); |
| 236 | 0 | coreResourceLoader.start(); |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | 0 | GlobalResourceLoader.addResourceLoader(coreResourceLoader); |
| 243 | |
|
| 244 | |
|
| 245 | 0 | if (registry != null) { |
| 246 | 0 | registry.start(); |
| 247 | |
|
| 248 | |
|
| 249 | |
} |
| 250 | 0 | return coreResourceLoader; |
| 251 | |
} |
| 252 | |
|
| 253 | |
public String getClientProtocol() { |
| 254 | 0 | return clientProtocol; |
| 255 | |
} |
| 256 | |
|
| 257 | |
public void setClientProtocol(String clientProtocol) { |
| 258 | 0 | this.clientProtocol = clientProtocol; |
| 259 | 0 | } |
| 260 | |
|
| 261 | |
public DataSource getDataSource() { |
| 262 | 0 | return dataSource; |
| 263 | |
} |
| 264 | |
|
| 265 | |
public void setDataSource(DataSource dataSource) { |
| 266 | 0 | this.dataSource = dataSource; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
public String getDataSourceJndiName() { |
| 270 | 0 | return dataSourceJndiName; |
| 271 | |
} |
| 272 | |
|
| 273 | |
public void setDataSourceJndiName(String jndiDatasourceLocation) { |
| 274 | 0 | this.dataSourceJndiName = jndiDatasourceLocation; |
| 275 | 0 | } |
| 276 | |
|
| 277 | |
} |