1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.util; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.construct.FlowConstructAware; |
11 | |
import org.mule.api.lifecycle.InitialisationException; |
12 | |
import org.mule.api.service.Service; |
13 | |
import org.mule.api.service.ServiceAware; |
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 | 0 | public class SpringBeanLookup extends AbstractObjectFactory implements ApplicationContextAware |
52 | |
{ |
53 | |
private ApplicationContext applicationContext; |
54 | |
private String bean; |
55 | |
|
56 | |
@Override |
57 | |
public void initialise() throws InitialisationException |
58 | |
{ |
59 | 0 | if (bean == null) |
60 | |
{ |
61 | 0 | throw new InitialisationException(MessageFactory.createStaticMessage("Bean name has not been set."), this); |
62 | |
} |
63 | 0 | if (applicationContext == null) |
64 | |
{ |
65 | 0 | throw new InitialisationException( |
66 | |
MessageFactory.createStaticMessage("ApplicationContext has not been injected."), this); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | objectClass = applicationContext.getBean(bean).getClass(); |
75 | 0 | } |
76 | |
|
77 | |
@Override |
78 | |
public void dispose() |
79 | |
{ |
80 | |
|
81 | 0 | } |
82 | |
|
83 | |
@Override |
84 | |
public Object getInstance(MuleContext muleContext) throws Exception |
85 | |
{ |
86 | 0 | Object instance = applicationContext.getBean(bean); |
87 | 0 | if(instance instanceof FlowConstructAware) |
88 | |
{ |
89 | |
|
90 | 0 | ((FlowConstructAware)instance).setFlowConstruct(flowConstruct); |
91 | |
} |
92 | 0 | if(instance instanceof ServiceAware && flowConstruct instanceof Service) |
93 | |
{ |
94 | |
|
95 | 0 | ((ServiceAware)instance).setService((Service) flowConstruct); |
96 | |
} |
97 | 0 | fireInitialisationCallbacks(instance); |
98 | 0 | return instance; |
99 | |
} |
100 | |
|
101 | |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException |
102 | |
{ |
103 | 0 | this.applicationContext = applicationContext; |
104 | 0 | } |
105 | |
|
106 | |
public String getBean() |
107 | |
{ |
108 | 0 | return bean; |
109 | |
} |
110 | |
|
111 | |
public void setBean(String bean) |
112 | |
{ |
113 | 0 | this.bean = bean; |
114 | 0 | } |
115 | |
|
116 | |
@Override |
117 | |
public boolean isSingleton() |
118 | |
{ |
119 | 0 | return applicationContext.isSingleton(bean); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public boolean isExternallyManagedLifecycle() |
124 | |
{ |
125 | 0 | return true; |
126 | |
} |
127 | |
|
128 | |
public boolean isAutoWireObject() |
129 | |
{ |
130 | |
|
131 | 0 | return false; |
132 | |
} |
133 | |
} |