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.service.DataDictionaryService;
19 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20 import org.kuali.rice.krad.service.PersistenceService;
21 import org.springframework.beans.factory.InitializingBean;
22 import org.springframework.context.ApplicationContext;
23 import org.springframework.context.ApplicationContextAware;
24
25 import javax.persistence.EntityManager;
26 import java.lang.reflect.Modifier;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public class ModuleConfiguration implements InitializingBean, ApplicationContextAware {
59
60
61
62
63 protected String namespaceCode;
64 protected ApplicationContext applicationContext;
65
66
67
68
69 protected List<String> packagePrefixes;
70
71
72
73
74
75
76
77 protected List<String> databaseRepositoryFilePaths;
78
79
80
81
82
83 protected List<String> dataDictionaryPackages;
84
85 protected List<String> scriptConfigurationFilePaths;
86
87 protected List<String> jobNames;
88
89 protected List<String> triggerNames;
90
91 protected List<String> resourceBundleNames;
92
93
94 protected String dataSourceName;
95
96
97 protected EntityManager entityManager;
98
99 protected Map<Class, Class> externalizableBusinessObjectImplementations;
100
101 protected boolean initializeDataDictionary;
102
103 protected PersistenceService persistenceService;
104
105
106
107
108 protected DataDictionaryService dataDictionaryService;
109
110
111
112
113
114
115
116
117 public ModuleConfiguration() {
118 databaseRepositoryFilePaths = new ArrayList<String>();
119 dataDictionaryPackages = new ArrayList<String>();
120 scriptConfigurationFilePaths = new ArrayList<String>();
121 jobNames = new ArrayList<String>();
122 triggerNames = new ArrayList<String>();
123 resourceBundleNames = new ArrayList<String>();
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 @Override
138 public void afterPropertiesSet() throws Exception {
139 if (isInitializeDataDictionary() && getDataDictionaryPackages() != null &&
140 !getDataDictionaryPackages().isEmpty()) {
141 if (getDataDictionaryService() == null) {
142 setDataDictionaryService(KRADServiceLocatorWeb.getDataDictionaryService());
143 }
144
145 if (getDataDictionaryService() == null) {
146 setDataDictionaryService((DataDictionaryService) applicationContext.getBean(
147 KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE));
148 }
149
150 if (dataDictionaryService != null) {
151 dataDictionaryService.addDataDictionaryLocations(getNamespaceCode(), getDataDictionaryPackages());
152 }
153 }
154
155 if (getDatabaseRepositoryFilePaths() != null) {
156 for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
157
158 if (getPersistenceService() == null) {
159 setPersistenceService(KRADServiceLocatorWeb.getPersistenceServiceOjb());
160 }
161 if (persistenceService == null) {
162 setPersistenceService((PersistenceService) applicationContext.getBean(
163 KRADServiceLocatorWeb.PERSISTENCE_SERVICE_OJB));
164 }
165 getPersistenceService().loadRepositoryDescriptor(repositoryLocation);
166 }
167 }
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181 public List<String> getDatabaseRepositoryFilePaths() {
182 return this.databaseRepositoryFilePaths;
183 }
184
185
186
187
188
189
190
191
192
193
194
195 public void setDatabaseRepositoryFilePaths(
196 List<String> databaseRepositoryFilePaths) {
197 this.trimList(databaseRepositoryFilePaths);
198 this.databaseRepositoryFilePaths = databaseRepositoryFilePaths;
199 }
200
201
202
203
204
205
206
207
208
209
210
211 public List<String> getDataDictionaryPackages() {
212 return this.dataDictionaryPackages;
213 }
214
215
216
217
218
219
220
221
222
223
224
225 public void setDataDictionaryPackages(List<String> dataDictionaryPackages) {
226 this.trimList(dataDictionaryPackages);
227 this.dataDictionaryPackages = dataDictionaryPackages;
228 }
229
230
231
232
233 public Map<Class, Class> getExternalizableBusinessObjectImplementations() {
234 if (this.externalizableBusinessObjectImplementations == null)
235 return null;
236 return Collections.unmodifiableMap(this.externalizableBusinessObjectImplementations);
237 }
238
239
240
241
242 public void setExternalizableBusinessObjectImplementations(
243 Map<Class, Class> externalizableBusinessObjectImplementations) {
244 if (externalizableBusinessObjectImplementations != null) {
245 for (Class implClass : externalizableBusinessObjectImplementations.values()) {
246 int implModifiers = implClass.getModifiers();
247 if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) {
248 throw new RuntimeException("Externalizable business object implementation class " +
249 implClass.getName() + " must be a non-interface, non-abstract class");
250 }
251 }
252 }
253 this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations;
254 }
255
256 public List<String> getPackagePrefixes(){
257 return this.packagePrefixes;
258 }
259
260 public void setPackagePrefixes(List<String> packagePrefixes){
261 this.trimList(packagePrefixes);
262 this.packagePrefixes = packagePrefixes;
263 }
264
265 public void setInitializeDataDictionary(boolean initializeDataDictionary){
266 this.initializeDataDictionary = initializeDataDictionary;
267 }
268
269 public List<String> getScriptConfigurationFilePaths(){
270 return this.scriptConfigurationFilePaths;
271 }
272
273
274
275
276 public List<String> getJobNames() {
277 return this.jobNames;
278 }
279
280
281
282
283 public void setJobNames(List<String> jobNames) {
284 this.jobNames = jobNames;
285 }
286
287
288
289
290 public List<String> getTriggerNames() {
291 return this.triggerNames;
292 }
293
294
295
296
297 public void setTriggerNames(List<String> triggerNames) {
298 this.triggerNames = triggerNames;
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312
313 public List<String> getResourceBundleNames() {
314 return resourceBundleNames;
315 }
316
317
318
319
320
321
322 public void setResourceBundleNames(List<String> resourceBundleNames) {
323 this.resourceBundleNames = resourceBundleNames;
324 }
325
326
327
328
329 public boolean isInitializeDataDictionary() {
330 return this.initializeDataDictionary;
331 }
332
333
334
335
336 public void setScriptConfigurationFilePaths(
337 List<String> scriptConfigurationFilePaths) {
338 this.scriptConfigurationFilePaths = scriptConfigurationFilePaths;
339 }
340
341
342
343
344 public String getNamespaceCode() {
345 return this.namespaceCode;
346 }
347
348
349
350
351 public void setNamespaceCode(String namespaceCode) {
352 this.namespaceCode = namespaceCode;
353 }
354
355 @Override
356 public void setApplicationContext(ApplicationContext applicationContext) {
357 this.applicationContext = applicationContext;
358 }
359
360
361
362
363 public DataDictionaryService getDataDictionaryService() {
364 return this.dataDictionaryService;
365 }
366
367
368
369
370 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
371 this.dataDictionaryService = dataDictionaryService;
372 }
373
374
375
376
377 public PersistenceService getPersistenceService() {
378 return this.persistenceService;
379 }
380
381
382
383
384 public void setPersistenceService(PersistenceService persistenceService) {
385 this.persistenceService = persistenceService;
386 }
387
388 public String getDataSourceName() {
389 return this.dataSourceName;
390 }
391
392 public void setDataSourceName(String dataSourceName) {
393 this.dataSourceName = dataSourceName;
394 }
395
396 public EntityManager getEntityManager() {
397 return this.entityManager;
398 }
399
400 public void setEntityManager(EntityManager entityManager) {
401 this.entityManager = entityManager;
402 }
403
404
405
406
407
408
409
410 protected void trimList(List<String> stringList){
411 if(stringList != null){
412
413
414 for(int i=0; i<stringList.size(); i++){
415 String elmt = stringList.get(i);
416 elmt = elmt.trim();
417 stringList.set(i, elmt);
418 }
419 }
420 }
421
422 }