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