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