1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring.util;
12
13 import org.mule.api.lifecycle.InitialisationException;
14 import org.mule.config.i18n.MessageFactory;
15 import org.mule.object.AbstractObjectFactory;
16
17 import org.springframework.beans.BeansException;
18 import org.springframework.context.ApplicationContext;
19 import org.springframework.context.ApplicationContextAware;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class SpringBeanLookup extends AbstractObjectFactory implements ApplicationContextAware
52 {
53 private ApplicationContext applicationContext;
54 private String bean;
55
56 public void initialise() throws InitialisationException
57 {
58 if (bean == null)
59 {
60 throw new InitialisationException(MessageFactory.createStaticMessage("Bean name has not been set."), this);
61 }
62 if (applicationContext == null)
63 {
64 throw new InitialisationException(
65 MessageFactory.createStaticMessage("ApplicationContext has not been injected."), this);
66 }
67 }
68
69 public void dispose()
70 {
71
72 }
73
74 public Class getObjectClass()
75 {
76 return applicationContext.getType(bean);
77 }
78
79 public Object getInstance() throws Exception
80 {
81 Object instance = applicationContext.getBean(bean);
82 fireInitialisationCallbacks(instance);
83 return instance;
84 }
85
86 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
87 {
88 this.applicationContext = applicationContext;
89 }
90
91 public String getBean()
92 {
93 return bean;
94 }
95
96 public void setBean(String bean)
97 {
98 this.bean = bean;
99 }
100
101
102 public boolean isSingleton()
103 {
104 return applicationContext.isSingleton(bean);
105 }
106
107 }