1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.core.resourceloader;
18
19 import javax.xml.namespace.QName;
20
21 import org.springframework.beans.BeansException;
22 import org.springframework.beans.factory.BeanFactory;
23 import org.springframework.beans.factory.BeanFactoryAware;
24
25
26
27
28
29
30
31 public class SpringBeanFactoryResourceLoader extends BaseResourceLoader implements BeanFactoryAware {
32
33 private BeanFactory beanFactory;
34
35 public SpringBeanFactoryResourceLoader() {
36 this(new QName("", "BeanFactoryResourceLoader"));
37 }
38
39 public SpringBeanFactoryResourceLoader(QName name) {
40 super(name);
41 }
42
43 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
44 this.beanFactory = beanFactory;
45 }
46
47 protected BeanFactory getBeanFactory() {
48 return this.beanFactory;
49 }
50
51 @Override
52 public Object getService(QName serviceName) {
53 String resolvedServiceName = resolveServiceName(serviceName);
54 if (this.beanFactory.containsBean(resolvedServiceName)) {
55 Object service = this.beanFactory.getBean(resolvedServiceName);
56 if (service != null) {
57 return postProcessService(serviceName, service);
58 }
59 }
60 return super.getService(serviceName);
61 }
62
63
64
65
66
67
68 protected String resolveServiceName(QName serviceName) {
69 return serviceName.toString();
70 }
71
72
73
74 }