1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.bo;
17
18 import org.kuali.rice.krad.datadictionary.DataDictionaryLocationConfigurer;
19 import org.kuali.rice.krad.service.DataDictionaryService;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.service.PersistenceService;
22 import org.springframework.beans.factory.InitializingBean;
23 import org.springframework.context.ApplicationContext;
24 import org.springframework.context.ApplicationContextAware;
25
26 import javax.persistence.EntityManager;
27 import java.lang.reflect.Modifier;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37
38
39 public class ModuleConfiguration implements InitializingBean, ApplicationContextAware {
40
41
42
43 protected String namespaceCode;
44 protected ApplicationContext applicationContext;
45
46 protected List<String> packagePrefixes;
47
48 protected List<String> databaseRepositoryFilePaths;
49
50 protected List<String> dataDictionaryPackages;
51
52 protected List<String> scriptConfigurationFilePaths;
53
54 protected List<String> jobNames;
55
56 protected List<String> triggerNames;
57
58
59 protected String dataSourceName;
60
61
62 protected EntityManager entityManager;
63
64 protected Map<Class, Class> externalizableBusinessObjectImplementations;
65
66 protected boolean initializeDataDictionary;
67
68 protected PersistenceService persistenceService;
69
70 protected DataDictionaryService dataDictionaryService;
71
72 public ModuleConfiguration() {
73 databaseRepositoryFilePaths = new ArrayList<String>();
74 dataDictionaryPackages = new ArrayList<String>();
75 scriptConfigurationFilePaths = new ArrayList<String>();
76 jobNames = new ArrayList<String>();
77 triggerNames = new ArrayList<String>();
78 }
79
80
81
82
83 public List<String> getDatabaseRepositoryFilePaths() {
84 return this.databaseRepositoryFilePaths;
85 }
86
87
88
89
90 public void setDatabaseRepositoryFilePaths(
91 List<String> databaseRepositoryFilePaths) {
92 this.trimList(databaseRepositoryFilePaths);
93 this.databaseRepositoryFilePaths = databaseRepositoryFilePaths;
94 }
95
96
97
98
99 public List<String> getDataDictionaryPackages() {
100 return this.dataDictionaryPackages;
101 }
102
103
104
105
106 public void setDataDictionaryPackages(List<String> dataDictionaryPackages) {
107 this.trimList(dataDictionaryPackages);
108 this.dataDictionaryPackages = dataDictionaryPackages;
109 }
110
111
112
113
114 public Map<Class, Class> getExternalizableBusinessObjectImplementations() {
115 if (this.externalizableBusinessObjectImplementations == null)
116 return null;
117 return Collections.unmodifiableMap(this.externalizableBusinessObjectImplementations);
118 }
119
120
121
122
123 public void setExternalizableBusinessObjectImplementations(
124 Map<Class, Class> externalizableBusinessObjectImplementations) {
125 if (externalizableBusinessObjectImplementations != null) {
126 for (Class implClass : externalizableBusinessObjectImplementations.values()) {
127 int implModifiers = implClass.getModifiers();
128 if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) {
129 throw new RuntimeException("Externalizable business object implementation class " +
130 implClass.getName() + " must be a non-interface, non-abstract class");
131 }
132 }
133 }
134 this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations;
135 }
136
137 public List<String> getPackagePrefixes(){
138 return this.packagePrefixes;
139 }
140
141 public void setPackagePrefixes(List<String> packagePrefixes){
142 this.trimList(packagePrefixes);
143 this.packagePrefixes = packagePrefixes;
144 }
145
146 public void setInitializeDataDictionary(boolean initializeDataDictionary){
147 this.initializeDataDictionary = initializeDataDictionary;
148 }
149
150 public List<String> getScriptConfigurationFilePaths(){
151 return this.scriptConfigurationFilePaths;
152 }
153
154
155
156
157 public List<String> getJobNames() {
158 return this.jobNames;
159 }
160
161
162
163
164 public void setJobNames(List<String> jobNames) {
165 this.jobNames = jobNames;
166 }
167
168
169
170
171
172 public List<String> getTriggerNames() {
173 return this.triggerNames;
174 }
175
176
177
178
179 public void setTriggerNames(List<String> triggerNames) {
180 this.triggerNames = triggerNames;
181 }
182
183
184
185
186 public boolean isInitializeDataDictionary() {
187 return this.initializeDataDictionary;
188 }
189
190
191
192
193 public void setScriptConfigurationFilePaths(
194 List<String> scriptConfigurationFilePaths) {
195 this.scriptConfigurationFilePaths = scriptConfigurationFilePaths;
196 }
197
198 @Override
199 public void afterPropertiesSet() throws Exception {
200 if (isInitializeDataDictionary() && getDataDictionaryPackages() != null && !getDataDictionaryPackages().isEmpty() ) {
201 if ( getDataDictionaryService() == null ) {
202 setDataDictionaryService(KRADServiceLocatorWeb.getDataDictionaryService());
203 }
204 if ( getDataDictionaryService() == null ) {
205 setDataDictionaryService((DataDictionaryService)applicationContext.getBean( KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE ));
206 }
207 DataDictionaryLocationConfigurer ddl = new DataDictionaryLocationConfigurer( getDataDictionaryService() );
208 ddl.setDataDictionaryPackages(getDataDictionaryPackages());
209 ddl.afterPropertiesSet();
210 }
211 if (getDatabaseRepositoryFilePaths() != null) {
212 for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
213
214 if (getPersistenceService() == null) {
215 setPersistenceService(KRADServiceLocatorWeb.getPersistenceServiceOjb());
216 }
217 if ( persistenceService == null ) {
218 setPersistenceService((PersistenceService)applicationContext.getBean( KRADServiceLocatorWeb.PERSISTENCE_SERVICE_OJB ));
219 }
220 getPersistenceService().loadRepositoryDescriptor( repositoryLocation );
221 }
222 }
223 }
224
225
226
227
228 public String getNamespaceCode() {
229 return this.namespaceCode;
230 }
231
232
233
234
235 public void setNamespaceCode(String namespaceCode) {
236 this.namespaceCode = namespaceCode;
237 }
238
239 @Override
240 public void setApplicationContext(ApplicationContext applicationContext) {
241 this.applicationContext = applicationContext;
242 }
243
244
245
246
247 public DataDictionaryService getDataDictionaryService() {
248 return this.dataDictionaryService;
249 }
250
251
252
253
254 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
255 this.dataDictionaryService = dataDictionaryService;
256 }
257
258
259
260
261 public PersistenceService getPersistenceService() {
262 return this.persistenceService;
263 }
264
265
266
267
268 public void setPersistenceService(PersistenceService persistenceService) {
269 this.persistenceService = persistenceService;
270 }
271
272 public String getDataSourceName() {
273 return this.dataSourceName;
274 }
275
276 public void setDataSourceName(String dataSourceName) {
277 this.dataSourceName = dataSourceName;
278 }
279
280 public EntityManager getEntityManager() {
281 return this.entityManager;
282 }
283
284 public void setEntityManager(EntityManager entityManager) {
285 this.entityManager = entityManager;
286 }
287
288
289
290
291
292
293
294 protected void trimList(List<String> stringList){
295 if(stringList != null){
296
297
298 for(int i=0; i<stringList.size(); i++){
299 String elmt = stringList.get(i);
300 elmt = elmt.trim();
301 stringList.set(i, elmt);
302 }
303 }
304 }
305
306 }