| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.impl.config.module; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
| 20 | |
import org.kuali.rice.core.api.config.module.RunMode; |
| 21 | |
import org.kuali.rice.core.api.config.property.Config; |
| 22 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 23 | |
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
| 24 | |
import org.kuali.rice.core.api.security.credentials.CredentialsSourceFactory; |
| 25 | |
import org.kuali.rice.core.api.util.RiceConstants; |
| 26 | |
|
| 27 | |
import javax.sql.DataSource; |
| 28 | |
import javax.transaction.TransactionManager; |
| 29 | |
import javax.transaction.UserTransaction; |
| 30 | |
import java.util.ArrayList; |
| 31 | |
import java.util.LinkedList; |
| 32 | |
import java.util.List; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public class CoreConfigurer extends ModuleConfigurer { |
| 38 | |
|
| 39 | |
private DataSource dataSource; |
| 40 | |
private DataSource nonTransactionalDataSource; |
| 41 | |
private DataSource serverDataSource; |
| 42 | |
private String platform; |
| 43 | |
private UserTransaction userTransaction; |
| 44 | |
private TransactionManager transactionManager; |
| 45 | |
private CredentialsSourceFactory credentialsSourceFactory; |
| 46 | |
|
| 47 | |
@Override |
| 48 | |
public List<Lifecycle> loadLifecycles() throws Exception { |
| 49 | 0 | final List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); |
| 50 | 0 | if (isConfigureLogging()) { |
| 51 | 0 | lifecycles.add(new Log4jLifeCycle()); |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | return lifecycles; |
| 55 | |
} |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public void addAdditonalToConfig() { |
| 59 | 0 | configureJta(); |
| 60 | 0 | configureDataSource(); |
| 61 | 0 | configureCredentialsSourceFactory(); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
protected boolean isConfigureLogging() { |
| 65 | 0 | return ConfigContext.getCurrentContextConfig().getBooleanProperty(RiceConstants.RICE_LOGGING_CONFIGURE, false); |
| 66 | |
} |
| 67 | |
|
| 68 | |
protected void configureCredentialsSourceFactory() { |
| 69 | 0 | if (credentialsSourceFactory != null) { |
| 70 | 0 | ConfigContext.getCurrentContextConfig().putObject(Config.CREDENTIALS_SOURCE_FACTORY, this.credentialsSourceFactory); |
| 71 | |
} |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
protected void configureDataSource() { |
| 75 | 0 | if (this.dataSource != null) { |
| 76 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.DATASOURCE_OBJ, this.dataSource); |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | if (this.nonTransactionalDataSource != null) { |
| 80 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.NON_TRANSACTIONAL_DATASOURCE_OBJ, this.nonTransactionalDataSource); |
| 81 | |
} |
| 82 | |
|
| 83 | 0 | if (this.serverDataSource != null) { |
| 84 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.SERVER_DATASOURCE_OBJ, this.serverDataSource); |
| 85 | |
} |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
public List<String> getPrimarySpringFiles() { |
| 90 | 0 | final List<String> springFileLocations = new ArrayList<String>(); |
| 91 | 0 | springFileLocations.add( "classpath:org/kuali/rice/core/config/CORESpringBeans.xml" ); |
| 92 | 0 | if ( getRunMode().equals( RunMode.LOCAL ) || getRunMode().equals( RunMode.EMBEDDED ) ) { |
| 93 | |
|
| 94 | |
} |
| 95 | 0 | if ( isExposeServicesOnBus() ) { |
| 96 | |
|
| 97 | |
|
| 98 | |
} |
| 99 | 0 | if ( isIncludeUserInterfaceComponents() ) { |
| 100 | |
|
| 101 | |
} |
| 102 | 0 | return springFileLocations; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
protected void configureJta() { |
| 111 | 0 | if (this.userTransaction != null) { |
| 112 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.USER_TRANSACTION_OBJ, this.userTransaction); |
| 113 | |
} |
| 114 | 0 | if (this.transactionManager != null) { |
| 115 | 0 | ConfigContext.getCurrentContextConfig().putObject(RiceConstants.TRANSACTION_MANAGER_OBJ, this.transactionManager); |
| 116 | |
} |
| 117 | 0 | boolean userTransactionConfigured = this.userTransaction != null || !StringUtils.isEmpty(ConfigContext.getCurrentContextConfig().getProperty(RiceConstants.USER_TRANSACTION_JNDI)); |
| 118 | 0 | boolean transactionManagerConfigured = this.transactionManager != null || !StringUtils.isEmpty(ConfigContext.getCurrentContextConfig().getProperty(RiceConstants.TRANSACTION_MANAGER_JNDI)); |
| 119 | 0 | if (userTransactionConfigured && !transactionManagerConfigured) { |
| 120 | 0 | throw new ConfigurationException("When configuring JTA, both a UserTransaction and a TransactionManager are required. Only the UserTransaction was configured."); |
| 121 | |
} |
| 122 | 0 | if (transactionManagerConfigured && !userTransactionConfigured) { |
| 123 | 0 | throw new ConfigurationException("When configuring JTA, both a UserTransaction and a TransactionManager are required. Only the TransactionManager was configured."); |
| 124 | |
} |
| 125 | 0 | } |
| 126 | |
|
| 127 | |
public DataSource getDataSource() { |
| 128 | 0 | return this.dataSource; |
| 129 | |
} |
| 130 | |
|
| 131 | |
public void setDataSource(DataSource dataSource) { |
| 132 | 0 | this.dataSource = dataSource; |
| 133 | 0 | } |
| 134 | |
|
| 135 | |
public DataSource getNonTransactionalDataSource() { |
| 136 | 0 | return this.nonTransactionalDataSource; |
| 137 | |
} |
| 138 | |
|
| 139 | |
public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource) { |
| 140 | 0 | this.nonTransactionalDataSource = nonTransactionalDataSource; |
| 141 | 0 | } |
| 142 | |
|
| 143 | |
public DataSource getServerDataSource() { |
| 144 | 0 | return this.serverDataSource; |
| 145 | |
} |
| 146 | |
|
| 147 | |
public void setServerDataSource(DataSource serverDataSource) { |
| 148 | 0 | this.serverDataSource = serverDataSource; |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
public String getPlatform() { |
| 152 | 0 | return this.platform; |
| 153 | |
} |
| 154 | |
|
| 155 | |
public void setPlatform(String platform) { |
| 156 | 0 | this.platform = platform; |
| 157 | 0 | } |
| 158 | |
|
| 159 | |
public TransactionManager getTransactionManager() { |
| 160 | 0 | return this.transactionManager; |
| 161 | |
} |
| 162 | |
|
| 163 | |
public void setTransactionManager(TransactionManager transactionManager) { |
| 164 | 0 | this.transactionManager = transactionManager; |
| 165 | 0 | } |
| 166 | |
|
| 167 | |
public UserTransaction getUserTransaction() { |
| 168 | 0 | return this.userTransaction; |
| 169 | |
} |
| 170 | |
|
| 171 | |
public void setUserTransaction(UserTransaction userTransaction) { |
| 172 | 0 | this.userTransaction = userTransaction; |
| 173 | 0 | } |
| 174 | |
|
| 175 | |
public CredentialsSourceFactory getCredentialsSourceFactory() { |
| 176 | 0 | return credentialsSourceFactory; |
| 177 | |
} |
| 178 | |
|
| 179 | |
public void setCredentialsSourceFactory( |
| 180 | |
final CredentialsSourceFactory credentialsSourceFactory) { |
| 181 | 0 | this.credentialsSourceFactory = credentialsSourceFactory; |
| 182 | 0 | } |
| 183 | |
} |