| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.core.config; |
| 18 | |
|
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import javax.sql.DataSource; |
| 24 | |
import javax.transaction.TransactionManager; |
| 25 | |
import javax.transaction.UserTransaction; |
| 26 | |
|
| 27 | |
import org.apache.commons.lang.StringUtils; |
| 28 | |
import org.apache.log4j.Logger; |
| 29 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
| 30 | |
import org.kuali.rice.core.lifecycle.Lifecycle; |
| 31 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
| 32 | |
import org.kuali.rice.core.security.credentials.CredentialsSourceFactory; |
| 33 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
| 34 | |
import org.kuali.rice.core.util.RiceConstants; |
| 35 | |
import org.kuali.rice.kcb.config.KCBConfigurer; |
| 36 | |
import org.kuali.rice.ken.config.KENConfigurer; |
| 37 | |
import org.kuali.rice.kew.config.KEWConfigurer; |
| 38 | |
import org.kuali.rice.kim.config.KIMConfigurer; |
| 39 | |
import org.kuali.rice.kns.config.KNSConfigurer; |
| 40 | |
import org.kuali.rice.kns.web.servlet.dwr.GlobalResourceDelegatingSpringCreator; |
| 41 | |
import org.kuali.rice.ksb.messaging.MessageFetcher; |
| 42 | |
import org.kuali.rice.ksb.messaging.config.KSBConfigurer; |
| 43 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | public class RiceConfigurer extends RiceConfigurerBase { |
| 52 | |
|
| 53 | 0 | private static final Logger LOG = Logger.getLogger(RiceConfigurer.class); |
| 54 | |
|
| 55 | |
private DataSource dataSource; |
| 56 | |
private DataSource nonTransactionalDataSource; |
| 57 | |
private DataSource serverDataSource; |
| 58 | |
private String platform; |
| 59 | |
private UserTransaction userTransaction; |
| 60 | |
private TransactionManager transactionManager; |
| 61 | |
private String dataSourceJndiLocation; |
| 62 | |
private String nonTransactionalDataSourceJndiLocation; |
| 63 | |
private String serverDataSourceJndiLocation; |
| 64 | |
private String userTransactionJndiLocation; |
| 65 | |
private String transactionManagerJndiLocation; |
| 66 | |
private CredentialsSourceFactory credentialsSourceFactory; |
| 67 | |
|
| 68 | |
private KSBConfigurer ksbConfigurer; |
| 69 | |
private KNSConfigurer knsConfigurer; |
| 70 | |
private KIMConfigurer kimConfigurer; |
| 71 | |
private KCBConfigurer kcbConfigurer; |
| 72 | |
private KEWConfigurer kewConfigurer; |
| 73 | |
private KENConfigurer kenConfigurer; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
public void start() throws Exception { |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | 0 | int index = 0; |
| 83 | 0 | if(getKsbConfigurer()!=null) getModules().add(index++,getKsbConfigurer()); |
| 84 | 0 | if(getKnsConfigurer()!=null) getModules().add(index++,getKnsConfigurer()); |
| 85 | 0 | if(getKimConfigurer()!=null) getModules().add(index++,getKimConfigurer()); |
| 86 | 0 | if(getKcbConfigurer()!=null) getModules().add(index++,getKcbConfigurer()); |
| 87 | 0 | if(getKewConfigurer()!=null) getModules().add(index++,getKewConfigurer()); |
| 88 | 0 | if(getKenConfigurer()!=null) getModules().add(index++,getKenConfigurer()); |
| 89 | |
|
| 90 | 0 | super.start(); |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | 0 | MessageFetcher messageFetcher = new MessageFetcher((Integer) null); |
| 95 | 0 | KSBServiceLocator.getThreadPool().execute(messageFetcher); |
| 96 | |
|
| 97 | 0 | } |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
@Override |
| 112 | |
protected void addModulesResourceLoaders() throws Exception { |
| 113 | 0 | if(getKewConfigurer()!=null){ |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | getKewConfigurer().getResourceLoaderToRegister(); |
| 118 | |
} |
| 119 | 0 | if(getKsbConfigurer()!=null){ |
| 120 | 0 | GlobalResourceLoader.addResourceLoader(getKsbConfigurer().getResourceLoaderToRegister()); |
| 121 | |
} |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
protected List<Lifecycle> loadLifecycles() throws Exception { |
| 129 | 0 | GlobalResourceDelegatingSpringCreator.APPLICATION_BEAN_FACTORY = getBeanFactory(); |
| 130 | 0 | return super.loadLifecycles(); |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
@SuppressWarnings("unchecked") |
| 135 | |
@Override |
| 136 | |
protected void initializeBaseConfiguration(Config currentConfig) throws Exception { |
| 137 | 0 | super.initializeBaseConfiguration(currentConfig); |
| 138 | 0 | configureJta(currentConfig); |
| 139 | 0 | configureDataSource(currentConfig); |
| 140 | 0 | configurePlatform(currentConfig); |
| 141 | 0 | configureCredentialsSourceFactory(currentConfig); |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
protected void configureCredentialsSourceFactory(final Config rootConfig) { |
| 145 | 0 | if (credentialsSourceFactory != null) { |
| 146 | 0 | rootConfig.putObject(Config.CREDENTIALS_SOURCE_FACTORY, this.credentialsSourceFactory); |
| 147 | |
} |
| 148 | |
|
| 149 | 0 | } |
| 150 | |
|
| 151 | |
protected void configurePlatform(Config config) { |
| 152 | 0 | if (!StringUtils.isBlank(this.platform)) { |
| 153 | 0 | String platformClassName = "org.kuali.rice.core.database.platform."+this.platform+"DatabasePlatform"; |
| 154 | 0 | config.putProperty(Config.DATASOURCE_PLATFORM, platformClassName); |
| 155 | 0 | config.putProperty(Config.OJB_PLATFORM, this.platform); |
| 156 | |
} |
| 157 | 0 | } |
| 158 | |
|
| 159 | |
protected void configureDataSource(Config config) { |
| 160 | 0 | if (this.dataSource != null) { |
| 161 | 0 | config.putObject(RiceConstants.DATASOURCE_OBJ, this.dataSource); |
| 162 | 0 | } else if (!StringUtils.isBlank(this.dataSourceJndiLocation)) { |
| 163 | 0 | config.putProperty(RiceConstants.DATASOURCE_JNDI, this.dataSourceJndiLocation); |
| 164 | |
} |
| 165 | 0 | if (this.nonTransactionalDataSource != null) { |
| 166 | 0 | config.putObject(RiceConstants.NON_TRANSACTIONAL_DATASOURCE_OBJ, this.nonTransactionalDataSource); |
| 167 | 0 | } else if (!StringUtils.isBlank(this.nonTransactionalDataSourceJndiLocation)) { |
| 168 | 0 | config.putProperty(RiceConstants.NON_TRANSACTIONAL_DATASOURCE_JNDI, this.nonTransactionalDataSourceJndiLocation); |
| 169 | |
} |
| 170 | 0 | if (this.serverDataSource != null) { |
| 171 | 0 | config.putObject(RiceConstants.SERVER_DATASOURCE_OBJ, this.serverDataSource); |
| 172 | 0 | } else if (!StringUtils.isBlank(this.serverDataSourceJndiLocation)) { |
| 173 | 0 | config.putProperty(RiceConstants.SERVER_DATASOURCE_JNDI, this.serverDataSourceJndiLocation); |
| 174 | |
} |
| 175 | 0 | } |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
protected void configureJta(Config config) { |
| 183 | 0 | if (this.userTransaction != null) { |
| 184 | 0 | config.putObject(RiceConstants.USER_TRANSACTION_OBJ, this.userTransaction); |
| 185 | |
} |
| 186 | 0 | if (this.transactionManager != null) { |
| 187 | 0 | config.putObject(RiceConstants.TRANSACTION_MANAGER_OBJ, this.transactionManager); |
| 188 | |
} |
| 189 | 0 | if (!StringUtils.isEmpty(this.userTransactionJndiLocation)) { |
| 190 | 0 | config.putProperty(RiceConstants.USER_TRANSACTION_JNDI, this.userTransactionJndiLocation); |
| 191 | |
} |
| 192 | 0 | if (!StringUtils.isEmpty(this.transactionManagerJndiLocation)) { |
| 193 | 0 | config.putProperty(RiceConstants.TRANSACTION_MANAGER_JNDI, this.transactionManagerJndiLocation); |
| 194 | |
} |
| 195 | 0 | boolean userTransactionConfigured = this.userTransaction != null || !StringUtils.isEmpty(this.userTransactionJndiLocation); |
| 196 | 0 | boolean transactionManagerConfigured = this.transactionManager != null || !StringUtils.isEmpty(this.transactionManagerJndiLocation); |
| 197 | 0 | if (userTransactionConfigured && !transactionManagerConfigured) { |
| 198 | 0 | throw new ConfigurationException("When configuring JTA, both a UserTransaction and a TransactionManager are required. Only the UserTransaction was configured."); |
| 199 | |
} |
| 200 | 0 | if (transactionManagerConfigured && !userTransactionConfigured) { |
| 201 | 0 | throw new ConfigurationException("When configuring JTA, both a UserTransaction and a TransactionManager are required. Only the TransactionManager was configured."); |
| 202 | |
} |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
public DataSource getDataSource() { |
| 206 | 0 | return this.dataSource; |
| 207 | |
} |
| 208 | |
|
| 209 | |
public void setDataSource(DataSource dataSource) { |
| 210 | 0 | this.dataSource = dataSource; |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
public DataSource getNonTransactionalDataSource() { |
| 214 | 0 | return this.nonTransactionalDataSource; |
| 215 | |
} |
| 216 | |
|
| 217 | |
public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource) { |
| 218 | 0 | this.nonTransactionalDataSource = nonTransactionalDataSource; |
| 219 | 0 | } |
| 220 | |
|
| 221 | |
public DataSource getServerDataSource() { |
| 222 | 0 | return this.serverDataSource; |
| 223 | |
} |
| 224 | |
|
| 225 | |
public void setServerDataSource(DataSource serverDataSource) { |
| 226 | 0 | this.serverDataSource = serverDataSource; |
| 227 | 0 | } |
| 228 | |
|
| 229 | |
public String getPlatform() { |
| 230 | 0 | return this.platform; |
| 231 | |
} |
| 232 | |
|
| 233 | |
public void setPlatform(String platform) { |
| 234 | 0 | this.platform = platform; |
| 235 | 0 | } |
| 236 | |
|
| 237 | |
public TransactionManager getTransactionManager() { |
| 238 | 0 | return this.transactionManager; |
| 239 | |
} |
| 240 | |
|
| 241 | |
public void setTransactionManager(TransactionManager transactionManager) { |
| 242 | 0 | this.transactionManager = transactionManager; |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
public UserTransaction getUserTransaction() { |
| 246 | 0 | return this.userTransaction; |
| 247 | |
} |
| 248 | |
|
| 249 | |
public void setUserTransaction(UserTransaction userTransaction) { |
| 250 | 0 | this.userTransaction = userTransaction; |
| 251 | 0 | } |
| 252 | |
|
| 253 | |
public void setDataSourceJndiLocation(String dataSourceJndiLocation) { |
| 254 | 0 | this.dataSourceJndiLocation = dataSourceJndiLocation; |
| 255 | 0 | } |
| 256 | |
|
| 257 | |
public void setNonTransactionalDataSourceJndiLocation(String nonTransactionalDataSourceJndiLocation) { |
| 258 | 0 | this.nonTransactionalDataSourceJndiLocation = nonTransactionalDataSourceJndiLocation; |
| 259 | 0 | } |
| 260 | |
|
| 261 | |
public void setServerDataSourceJndiLocation(String serverDataSourceJndiLocation) { |
| 262 | 0 | this.serverDataSourceJndiLocation = serverDataSourceJndiLocation; |
| 263 | 0 | } |
| 264 | |
|
| 265 | |
public String getTransactionManagerJndiLocation() { |
| 266 | 0 | return this.transactionManagerJndiLocation; |
| 267 | |
} |
| 268 | |
|
| 269 | |
public void setTransactionManagerJndiLocation(String transactionManagerJndiLocation) { |
| 270 | 0 | this.transactionManagerJndiLocation = transactionManagerJndiLocation; |
| 271 | 0 | } |
| 272 | |
|
| 273 | |
public String getUserTransactionJndiLocation() { |
| 274 | 0 | return this.userTransactionJndiLocation; |
| 275 | |
} |
| 276 | |
|
| 277 | |
public void setUserTransactionJndiLocation(String userTransactionJndiLocation) { |
| 278 | 0 | this.userTransactionJndiLocation = userTransactionJndiLocation; |
| 279 | 0 | } |
| 280 | |
|
| 281 | |
public CredentialsSourceFactory getCredentialsSourceFactory() { |
| 282 | 0 | return credentialsSourceFactory; |
| 283 | |
} |
| 284 | |
|
| 285 | |
public void setCredentialsSourceFactory( |
| 286 | |
final CredentialsSourceFactory credentialsSourceFactory) { |
| 287 | 0 | this.credentialsSourceFactory = credentialsSourceFactory; |
| 288 | 0 | } |
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
public KCBConfigurer getKcbConfigurer() { |
| 294 | 0 | return this.kcbConfigurer; |
| 295 | |
} |
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
public void setKcbConfigurer(KCBConfigurer kcbConfigurer) { |
| 301 | 0 | this.kcbConfigurer = kcbConfigurer; |
| 302 | 0 | } |
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
public KENConfigurer getKenConfigurer() { |
| 308 | 0 | return this.kenConfigurer; |
| 309 | |
} |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
public void setKenConfigurer(KENConfigurer kenConfigurer) { |
| 315 | 0 | this.kenConfigurer = kenConfigurer; |
| 316 | 0 | } |
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
public KEWConfigurer getKewConfigurer() { |
| 322 | 0 | return this.kewConfigurer; |
| 323 | |
} |
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
public void setKewConfigurer(KEWConfigurer kewConfigurer) { |
| 329 | 0 | this.kewConfigurer = kewConfigurer; |
| 330 | 0 | } |
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
public KIMConfigurer getKimConfigurer() { |
| 336 | 0 | return this.kimConfigurer; |
| 337 | |
} |
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
public void setKimConfigurer(KIMConfigurer kimConfigurer) { |
| 343 | 0 | this.kimConfigurer = kimConfigurer; |
| 344 | 0 | } |
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
public KNSConfigurer getKnsConfigurer() { |
| 350 | 0 | return this.knsConfigurer; |
| 351 | |
} |
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
public void setKnsConfigurer(KNSConfigurer knsConfigurer) { |
| 357 | 0 | this.knsConfigurer = knsConfigurer; |
| 358 | 0 | } |
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
public KSBConfigurer getKsbConfigurer() { |
| 364 | 0 | return this.ksbConfigurer; |
| 365 | |
} |
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
public void setKsbConfigurer(KSBConfigurer ksbConfigurer) { |
| 371 | 0 | this.ksbConfigurer = ksbConfigurer; |
| 372 | 0 | } |
| 373 | |
|
| 374 | |
} |