1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data;
17
18 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19 import org.kuali.rice.core.framework.resourceloader.BeanFactoryResourceLoader;
20 import org.kuali.rice.krad.data.DataObjectService;
21 import org.kuali.rice.krad.data.KradDataServiceLocator;
22 import org.springframework.beans.factory.FactoryBean;
23 import org.springframework.context.support.ClassPathXmlApplicationContext;
24
25 import javax.xml.namespace.QName;
26
27
28
29
30
31
32
33
34
35
36
37 public class KradDataFactoryBean implements FactoryBean<DataObjectService> {
38
39 private static final String SPRING_FILE = "classpath:org/kuali/rice/krad/data/config/KRADDataSpringBeans.xml";
40
41 @Override
42 public DataObjectService getObject() throws Exception {
43
44 DataObjectService dataObjectService = KradDataServiceLocator.getDataObjectService();
45 if (dataObjectService == null) {
46 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(SPRING_FILE);
47 BeanFactoryResourceLoader rl = new BeanFactoryResourceLoader(new QName("krad-data"), context);
48 rl.start();
49 GlobalResourceLoader.addResourceLoader(rl);
50 dataObjectService = KradDataServiceLocator.getDataObjectService();
51 }
52 if (dataObjectService == null) {
53 throw new IllegalStateException("Failed to locate or initialize krad data framework.");
54 }
55 return dataObjectService;
56 }
57
58 @Override
59 public Class<?> getObjectType() {
60 return DataObjectService.class;
61 }
62
63 @Override
64 public boolean isSingleton() {
65 return true;
66 }
67
68 }