1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.context; |
12 | |
|
13 | |
import org.mule.MuleServer; |
14 | |
import org.mule.RegistryContext; |
15 | |
import org.mule.api.MuleContext; |
16 | |
import org.mule.api.config.ConfigurationBuilder; |
17 | |
import org.mule.api.config.ConfigurationException; |
18 | |
import org.mule.api.context.MuleContextBuilder; |
19 | |
import org.mule.api.context.MuleContextFactory; |
20 | |
import org.mule.api.lifecycle.InitialisationException; |
21 | |
import org.mule.config.builders.AutoConfigurationBuilder; |
22 | |
import org.mule.config.builders.DefaultsConfigurationBuilder; |
23 | |
import org.mule.config.builders.SimpleConfigurationBuilder; |
24 | |
|
25 | |
import java.util.List; |
26 | |
import java.util.Properties; |
27 | |
|
28 | |
import org.apache.commons.logging.Log; |
29 | |
import org.apache.commons.logging.LogFactory; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 1160 | public class DefaultMuleContextFactory implements MuleContextFactory |
36 | |
{ |
37 | 2 | protected static final Log logger = LogFactory.getLog(DefaultMuleContextBuilder.class); |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public MuleContext createMuleContext() throws InitialisationException, ConfigurationException |
43 | |
{ |
44 | |
|
45 | 4 | return createMuleContext(new DefaultsConfigurationBuilder(), new DefaultMuleContextBuilder()); |
46 | |
} |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public MuleContext createMuleContext(ConfigurationBuilder configurationBuilder) |
52 | |
throws InitialisationException, ConfigurationException |
53 | |
{ |
54 | |
|
55 | 2 | return createMuleContext(configurationBuilder, new DefaultMuleContextBuilder()); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public MuleContext createMuleContext(MuleContextBuilder muleContextBuilder) |
62 | |
throws InitialisationException, ConfigurationException |
63 | |
{ |
64 | |
|
65 | 0 | return createMuleContext(new DefaultsConfigurationBuilder(), muleContextBuilder); |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public MuleContext createMuleContext(List configurationBuilders, MuleContextBuilder muleContextBuilder) |
72 | |
throws InitialisationException, ConfigurationException |
73 | |
{ |
74 | |
|
75 | 1144 | MuleContext muleContext = doCreateMuleContext(muleContextBuilder); |
76 | |
|
77 | |
|
78 | 3432 | for (int i = 0; i < configurationBuilders.size(); i++) |
79 | |
{ |
80 | 2288 | ((ConfigurationBuilder) configurationBuilders.get(i)).configure(muleContext); |
81 | |
} |
82 | |
|
83 | 1144 | return muleContext; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public MuleContext createMuleContext(ConfigurationBuilder configurationBuilder, |
90 | |
MuleContextBuilder muleContextBuilder) |
91 | |
throws InitialisationException, ConfigurationException |
92 | |
{ |
93 | |
|
94 | 10 | MuleContext muleContext = doCreateMuleContext(muleContextBuilder); |
95 | |
|
96 | |
|
97 | 10 | configurationBuilder.configure(muleContext); |
98 | |
|
99 | 10 | return muleContext; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public MuleContext createMuleContext(String resource) |
116 | |
throws InitialisationException, ConfigurationException |
117 | |
{ |
118 | 2 | return createMuleContext(resource, null); |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public MuleContext createMuleContext(String configResources, Properties properties) |
136 | |
throws InitialisationException, ConfigurationException |
137 | |
{ |
138 | |
|
139 | 4 | MuleContext muleContext = doCreateMuleContext(new DefaultMuleContextBuilder()); |
140 | |
|
141 | |
|
142 | 4 | if (properties != null && !properties.isEmpty()) |
143 | |
{ |
144 | 2 | new SimpleConfigurationBuilder(properties).configure(muleContext); |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | 4 | new AutoConfigurationBuilder(configResources).configure(muleContext); |
150 | |
|
151 | 0 | return muleContext; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public MuleContext createMuleContext(ConfigurationBuilder configurationBuilder, Properties properties) |
166 | |
throws InitialisationException, ConfigurationException |
167 | |
{ |
168 | |
|
169 | 2 | MuleContext muleContext = doCreateMuleContext(new DefaultMuleContextBuilder()); |
170 | |
|
171 | |
|
172 | 2 | if (properties != null && !properties.isEmpty()) |
173 | |
{ |
174 | 2 | new SimpleConfigurationBuilder(properties).configure(muleContext); |
175 | |
} |
176 | |
|
177 | |
|
178 | 2 | configurationBuilder.configure(muleContext); |
179 | |
|
180 | 2 | return muleContext; |
181 | |
} |
182 | |
|
183 | |
protected MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder) |
184 | |
throws InitialisationException |
185 | |
{ |
186 | |
|
187 | 1160 | RegistryContext.getOrCreateRegistry(); |
188 | |
|
189 | |
|
190 | 1160 | MuleContext muleContext = buildMuleContext(muleContextBuilder); |
191 | 1160 | MuleServer.setMuleContext(muleContext); |
192 | |
|
193 | |
|
194 | 1160 | muleContext.initialise(); |
195 | |
|
196 | 1160 | return muleContext; |
197 | |
} |
198 | |
|
199 | |
protected MuleContext buildMuleContext(MuleContextBuilder muleContextBuilder) |
200 | |
{ |
201 | 1160 | return muleContextBuilder.buildMuleContext(); |
202 | |
} |
203 | |
|
204 | |
} |