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