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