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