Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
QuickConfigurationBuilder |
|
| 1.7837837837837838;1.784 |
1 | /* | |
2 | * $Id: QuickConfigurationBuilder.java 7976 2007-08-21 14:26:13Z dirk.olmes $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.config.builders; | |
12 | ||
13 | import org.mule.MuleManager; | |
14 | import org.mule.config.ConfigurationBuilder; | |
15 | import org.mule.config.ConfigurationException; | |
16 | import org.mule.config.ReaderResource; | |
17 | import org.mule.config.i18n.CoreMessages; | |
18 | import org.mule.impl.MuleDescriptor; | |
19 | import org.mule.impl.endpoint.MuleEndpoint; | |
20 | import org.mule.impl.endpoint.MuleEndpointURI; | |
21 | import org.mule.impl.internal.admin.MuleAdminAgent; | |
22 | import org.mule.impl.model.ModelFactory; | |
23 | import org.mule.impl.model.seda.SedaModel; | |
24 | import org.mule.providers.service.TransportFactory; | |
25 | import org.mule.umo.UMOComponent; | |
26 | import org.mule.umo.UMODescriptor; | |
27 | import org.mule.umo.UMOException; | |
28 | import org.mule.umo.UMOFilter; | |
29 | import org.mule.umo.endpoint.UMOEndpoint; | |
30 | import org.mule.umo.endpoint.UMOEndpointURI; | |
31 | import org.mule.umo.lifecycle.InitialisationException; | |
32 | import org.mule.umo.manager.UMOContainerContext; | |
33 | import org.mule.umo.manager.UMOManager; | |
34 | import org.mule.umo.model.UMOModel; | |
35 | import org.mule.umo.provider.UMOConnector; | |
36 | import org.mule.util.MuleObjectHelper; | |
37 | import org.mule.util.StringUtils; | |
38 | ||
39 | import java.util.Map; | |
40 | import java.util.Properties; | |
41 | ||
42 | /** | |
43 | * <code>QuickConfigurationBuilder</code> is a configuration helper that can be | |
44 | * used by clients, configuration scripts or test cases to quickly configure a | |
45 | * manager. | |
46 | */ | |
47 | public class QuickConfigurationBuilder implements ConfigurationBuilder | |
48 | { | |
49 | private static final String MODEL_NOT_SET = "not set"; | |
50 | ||
51 | private UMOManager manager; | |
52 | ||
53 | private UMOModel model; | |
54 | ||
55 | /** | |
56 | * Constructs a default builder | |
57 | */ | |
58 | public QuickConfigurationBuilder() | |
59 | 0 | { |
60 | 0 | manager = MuleManager.getInstance(); |
61 | 0 | } |
62 | ||
63 | /** | |
64 | * Will construct a new Quick Config builder with the option of disposing of the | |
65 | * current Manager if one exists | |
66 | * | |
67 | * @param disposeCurrent true to dispose the current manager | |
68 | */ | |
69 | public QuickConfigurationBuilder(boolean disposeCurrent) | |
70 | 0 | { |
71 | 0 | if (disposeCurrent) |
72 | { | |
73 | 0 | disposeCurrent(); |
74 | } | |
75 | ||
76 | 0 | manager = MuleManager.getInstance(); |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * Disposes the current MuleManager if there is one. | |
81 | */ | |
82 | public void disposeCurrent() | |
83 | { | |
84 | 0 | if (MuleManager.isInstanciated()) |
85 | { | |
86 | 0 | MuleManager.getInstance().dispose(); |
87 | } | |
88 | 0 | } |
89 | ||
90 | public void disableAdminAgent() | |
91 | { | |
92 | 0 | MuleManager.getConfiguration().setServerUrl(StringUtils.EMPTY); |
93 | 0 | if (manager != null) |
94 | { | |
95 | try | |
96 | { | |
97 | 0 | manager.unregisterAgent(MuleAdminAgent.AGENT_NAME); |
98 | } | |
99 | 0 | catch (UMOException e) |
100 | { | |
101 | // TODO MULE-863: fix API or handle | |
102 | 0 | } |
103 | } | |
104 | 0 | } |
105 | ||
106 | public void registerModel(String modelType, String name) throws UMOException | |
107 | { | |
108 | 0 | UMOModel model = ModelFactory.createModel(modelType); |
109 | 0 | model.setName(name); |
110 | 0 | manager.registerModel(model); |
111 | 0 | } |
112 | ||
113 | /** | |
114 | * Configures a started manager. This method will throw InitialisationException | |
115 | * if the current manager is already started | |
116 | * | |
117 | * @param synchronous whether to start the manager in synchronous mode | |
118 | * @param serverUrl the url used to receive client requests, or null if the | |
119 | * server listening components should not be set up | |
120 | * @return the configured manager | |
121 | * @throws UMOException if the manager is already started or it fails to start | |
122 | */ | |
123 | public UMOManager createStartedManager(boolean synchronous, String serverUrl, String modeltype) | |
124 | throws UMOException | |
125 | { | |
126 | 0 | if (manager.isStarted()) |
127 | { | |
128 | 0 | throw new InitialisationException(CoreMessages.managerAlreadyStarted(), this); |
129 | } | |
130 | 0 | if (serverUrl == null) |
131 | { | |
132 | 0 | serverUrl = ""; |
133 | } | |
134 | 0 | MuleManager.getConfiguration().setServerUrl(serverUrl); |
135 | 0 | MuleManager.getConfiguration().setSynchronous(synchronous); |
136 | 0 | if (!MODEL_NOT_SET.equals(modeltype)) |
137 | { | |
138 | 0 | model = ModelFactory.createModel(modeltype); |
139 | } | |
140 | else | |
141 | { | |
142 | 0 | model = ModelFactory.createModel("seda"); |
143 | } | |
144 | 0 | manager.registerModel(model); |
145 | ||
146 | 0 | manager.start(); |
147 | 0 | return manager; |
148 | } | |
149 | ||
150 | /** | |
151 | * Configures a started manager. This method will throw InitialisationException | |
152 | * if the current manager is already started | |
153 | * | |
154 | * @param synchronous whether to start the manager in synchronous mode | |
155 | * @param serverUrl the url used to receive client requests, or null if the | |
156 | * server listening components should not be set up | |
157 | * @return the configured manager | |
158 | * @throws UMOException if the manager is already started or it fails to start | |
159 | */ | |
160 | public UMOManager createStartedManager(boolean synchronous, String serverUrl) throws UMOException | |
161 | { | |
162 | 0 | return createStartedManager(synchronous, serverUrl, MODEL_NOT_SET); |
163 | } | |
164 | ||
165 | /** | |
166 | * Configures a started manager. This method will throw InitialisationException | |
167 | * if the current manager is already started | |
168 | * | |
169 | * @param synchronous whether to start the manager in synchronous mode | |
170 | * @param serverUrl the url used to receive client requests, or null if the | |
171 | * server listening components should not be set up | |
172 | * @param serverConnector The server connector to use for the serverUrl | |
173 | * @return the configured manager | |
174 | * @throws UMOException if the manager is already started or it fails to start | |
175 | */ | |
176 | public UMOManager createStartedManager(boolean synchronous, String serverUrl, UMOConnector serverConnector) | |
177 | throws UMOException | |
178 | { | |
179 | 0 | if (serverConnector != null) |
180 | { | |
181 | 0 | manager.registerConnector(serverConnector); |
182 | } | |
183 | else | |
184 | { | |
185 | 0 | throw new IllegalArgumentException("Cannot create started manager from null serverConnector"); |
186 | } | |
187 | ||
188 | // set the connector on the endpointUri | |
189 | 0 | int param = serverUrl.indexOf('?'); |
190 | 0 | if (param == -1) |
191 | { | |
192 | 0 | serverUrl += '?'; |
193 | } | |
194 | else | |
195 | { | |
196 | 0 | serverUrl += '&'; |
197 | } | |
198 | ||
199 | 0 | serverUrl += UMOEndpointURI.PROPERTY_CREATE_CONNECTOR + "=" + serverConnector.getName(); |
200 | 0 | return createStartedManager(synchronous, serverUrl); |
201 | } | |
202 | ||
203 | /** | |
204 | * Registers a java object as a Umo pcomponent that listens for events on the | |
205 | * given url. By default the ThreadingProfile for the components will be set so | |
206 | * that there will only be one thread of execution. | |
207 | * | |
208 | * @param component any java object, Mule will it's endpointUri discovery to | |
209 | * determine which event to invoke based on the evnet payload type | |
210 | * @param name The identifying name of the components. This can be used to later | |
211 | * unregister it | |
212 | * @param listenerEndpointUri The url endpointUri to listen to | |
213 | * @throws org.mule.umo.UMOException | |
214 | */ | |
215 | public UMODescriptor registerComponentInstance(Object component, | |
216 | String name, | |
217 | UMOEndpointURI listenerEndpointUri) throws UMOException | |
218 | { | |
219 | 0 | return registerComponentInstance(component, name, listenerEndpointUri, null); |
220 | } | |
221 | ||
222 | /** | |
223 | * Registers a java object as a Umo pcomponent that listens for and sends events | |
224 | * on the given urls. By default the ThreadingProfile for the components will be | |
225 | * set so that there will only be one thread of execution. | |
226 | * | |
227 | * @param component any java object, Mule will it's endpointUri discovery to | |
228 | * determine which event to invoke based on the evnet payload type | |
229 | * @param name The identifying name of the components. This can be used to later | |
230 | * unregister it | |
231 | * @param listenerEndpointUri The url endpointUri to listen to | |
232 | * @param sendEndpointUri The url endpointUri to dispatch to | |
233 | * @throws UMOException | |
234 | */ | |
235 | public UMODescriptor registerComponentInstance(Object component, | |
236 | String name, | |
237 | UMOEndpointURI listenerEndpointUri, | |
238 | UMOEndpointURI sendEndpointUri) throws UMOException | |
239 | { | |
240 | 0 | MuleDescriptor descriptor = new MuleDescriptor(); |
241 | 0 | descriptor.setName(name); |
242 | 0 | descriptor.setImplementationInstance(component); |
243 | ||
244 | // Create the endpoints | |
245 | 0 | UMOEndpoint inboundProvider = null; |
246 | 0 | UMOEndpoint outboundProvider = null; |
247 | 0 | if (listenerEndpointUri != null) |
248 | { | |
249 | 0 | inboundProvider = TransportFactory.createEndpoint(listenerEndpointUri, |
250 | UMOEndpoint.ENDPOINT_TYPE_RECEIVER); | |
251 | } | |
252 | 0 | if (sendEndpointUri != null) |
253 | { | |
254 | 0 | outboundProvider = TransportFactory.createEndpoint(sendEndpointUri, |
255 | UMOEndpoint.ENDPOINT_TYPE_SENDER); | |
256 | } | |
257 | 0 | descriptor.setInboundEndpoint(inboundProvider); |
258 | 0 | descriptor.setOutboundEndpoint(outboundProvider); |
259 | ||
260 | // register the components descriptor | |
261 | 0 | getModel().registerComponent(descriptor); |
262 | 0 | return descriptor; |
263 | } | |
264 | ||
265 | public UMOComponent registerComponent(String implementation, | |
266 | String name, | |
267 | String inboundEndpoint, | |
268 | String outboundEndpoint, | |
269 | Map properties) throws UMOException | |
270 | { | |
271 | 0 | UMOEndpoint inEndpoint = null; |
272 | 0 | UMOEndpoint outEndpoint = null; |
273 | 0 | if (inboundEndpoint != null) |
274 | { | |
275 | 0 | inEndpoint = manager.lookupEndpoint(inboundEndpoint); |
276 | 0 | if (inEndpoint == null) |
277 | { | |
278 | 0 | inEndpoint = createEndpoint(inboundEndpoint, null, true); |
279 | } | |
280 | } | |
281 | 0 | if (outboundEndpoint != null) |
282 | { | |
283 | 0 | outEndpoint = manager.lookupEndpoint(outboundEndpoint); |
284 | 0 | if (outEndpoint == null) |
285 | { | |
286 | 0 | outEndpoint = createEndpoint(outboundEndpoint, null, false); |
287 | } | |
288 | } | |
289 | 0 | UMODescriptor d = createDescriptor(implementation, name, inEndpoint, outEndpoint, properties); |
290 | 0 | return registerComponent(d); |
291 | } | |
292 | ||
293 | public UMOComponent registerComponent(String implementation, | |
294 | String name, | |
295 | UMOEndpoint inEndpoint, | |
296 | UMOEndpoint outEndpoint, | |
297 | Map properties) throws UMOException | |
298 | { | |
299 | 0 | UMODescriptor d = createDescriptor(implementation, name, inEndpoint, outEndpoint, properties); |
300 | 0 | return registerComponent(d); |
301 | } | |
302 | ||
303 | /** | |
304 | * Registers a user configured MuleDescriptor of a components to the server. If | |
305 | * users want to register object instances with the server rather than class | |
306 | * names that get created at runtime or reference to objects in the container, | |
307 | * the user must call the descriptors setImplementationInstance() method - <code> | |
308 | * MyBean implementation = new MyBean(); | |
309 | * descriptor.setImplementationInstance(implementation); | |
310 | * </code> | |
311 | * Calling this method is equivilent to calling UMOModel.registerComponent(..) | |
312 | * | |
313 | * @param descriptor the componet descriptor to register | |
314 | * @throws UMOException the descriptor is invalid or cannot be initialised or | |
315 | * started | |
316 | * @see org.mule.umo.model.UMOModel | |
317 | */ | |
318 | public UMOComponent registerComponent(UMODescriptor descriptor) throws UMOException | |
319 | { | |
320 | 0 | return getModel().registerComponent(descriptor); |
321 | } | |
322 | ||
323 | /** | |
324 | * Registers a java object as a Umo pcomponent that listens for events on the | |
325 | * given url. By default the ThreadingProfile for the components will be set so | |
326 | * that there will only be one thread of execution. | |
327 | * | |
328 | * @param implementation either a container refernece to an object or a fully | |
329 | * qualified class name to use as the component implementation | |
330 | * @param name The identifying name of the components. This can be used to later | |
331 | * unregister it | |
332 | * @param inboundEndpointUri The url endpointUri to listen to | |
333 | * @throws org.mule.umo.UMOException | |
334 | */ | |
335 | public UMOComponent registerComponent(String implementation, | |
336 | String name, | |
337 | UMOEndpointURI inboundEndpointUri) throws UMOException | |
338 | { | |
339 | 0 | return registerComponent(implementation, name, inboundEndpointUri, null, null); |
340 | } | |
341 | ||
342 | /** | |
343 | * Registers a java object as a Umo pcomponent that listens for events on the | |
344 | * given url. By default the ThreadingProfile for the components will be set so | |
345 | * that there will only be one thread of execution. | |
346 | * | |
347 | * @param implementation either a container refernece to an object or a fully | |
348 | * qualified class name to use as the component implementation | |
349 | * @param name The identifying name of the components. This can be used to later | |
350 | * unregister it | |
351 | * @param inboundEndpointUri The url endpointUri to listen to | |
352 | * @param properties properties to set on the component | |
353 | * @throws org.mule.umo.UMOException | |
354 | */ | |
355 | public UMOComponent registerComponent(String implementation, | |
356 | String name, | |
357 | UMOEndpointURI inboundEndpointUri, | |
358 | Map properties) throws UMOException | |
359 | { | |
360 | 0 | return registerComponent(implementation, name, inboundEndpointUri, null, properties); |
361 | } | |
362 | ||
363 | /** | |
364 | * Registers a java object as a Umo pcomponent that listens for and sends events | |
365 | * on the given urls. By default the ThreadingProfile for the components will be | |
366 | * set so that there will only be one thread of execution. | |
367 | * | |
368 | * @param implementation either a container refernece to an object or a fully | |
369 | * qualified class name to use as the component implementation which | |
370 | * event to invoke based on the evnet payload type | |
371 | * @param name The identifying name of the components. This can be used to later | |
372 | * unregister it | |
373 | * @param inboundEndpointUri The url endpointUri to listen to | |
374 | * @param outboundEndpointUri The url endpointUri to dispatch to | |
375 | * @throws UMOException | |
376 | */ | |
377 | public UMOComponent registerComponent(String implementation, | |
378 | String name, | |
379 | UMOEndpointURI inboundEndpointUri, | |
380 | UMOEndpointURI outboundEndpointUri) throws UMOException | |
381 | { | |
382 | 0 | return registerComponent(implementation, name, inboundEndpointUri, outboundEndpointUri, null); |
383 | } | |
384 | ||
385 | /** | |
386 | * Registers a java object as a Umo pcomponent that listens for and sends events | |
387 | * on the given urls. By default the ThreadingProfile for the components will be | |
388 | * set so that there will only be one thread of execution. | |
389 | * | |
390 | * @param implementation either a container refernece to an object or a fully | |
391 | * qualified class name to use as the component implementation which | |
392 | * event to invoke based on the evnet payload type | |
393 | * @param name The identifying name of the components. This can be used to later | |
394 | * unregister it | |
395 | * @param inboundEndpointUri The url endpointUri to listen to | |
396 | * @param outboundEndpointUri The url endpointUri to dispatch to | |
397 | * @param properties properties to set on the component | |
398 | * @throws UMOException | |
399 | */ | |
400 | public UMOComponent registerComponent(String implementation, | |
401 | String name, | |
402 | UMOEndpointURI inboundEndpointUri, | |
403 | UMOEndpointURI outboundEndpointUri, | |
404 | Map properties) throws UMOException | |
405 | { | |
406 | 0 | UMODescriptor d = createDescriptor(implementation, name, inboundEndpointUri, outboundEndpointUri, |
407 | properties); | |
408 | 0 | return getModel().registerComponent(d); |
409 | } | |
410 | ||
411 | /** | |
412 | * Creates a Mule Descriptor that can be further maniputalted by the calling | |
413 | * class before registering it with the UMOModel | |
414 | * | |
415 | * @param implementation either a container refernece to an object or a fully | |
416 | * qualified class name to use as the component implementation which | |
417 | * event to invoke based on the evnet payload type | |
418 | * @param name The identifying name of the component. This can be used to later | |
419 | * unregister it | |
420 | * @param inboundEndpointUri The url endpointUri to listen to. Can be null | |
421 | * @param outboundEndpointUri The url endpointUri to dispatch to. Can be null | |
422 | * @param properties properties to set on the component. Can be null | |
423 | * @throws UMOException | |
424 | */ | |
425 | public UMODescriptor createDescriptor(String implementation, | |
426 | String name, | |
427 | String inboundEndpointUri, | |
428 | String outboundEndpointUri, | |
429 | Map properties) throws UMOException | |
430 | { | |
431 | 0 | UMOEndpointURI inEndpointUri = null; |
432 | 0 | UMOEndpointURI outEndpointUri = null; |
433 | 0 | if (inboundEndpointUri != null) |
434 | { | |
435 | 0 | inEndpointUri = new MuleEndpointURI(inboundEndpointUri); |
436 | } | |
437 | 0 | if (outboundEndpointUri != null) |
438 | { | |
439 | 0 | outEndpointUri = new MuleEndpointURI(outboundEndpointUri); |
440 | } | |
441 | ||
442 | 0 | return createDescriptor(implementation, name, inEndpointUri, outEndpointUri, properties); |
443 | } | |
444 | ||
445 | /** | |
446 | * Creates a Mule Descriptor that can be further maniputalted by the calling | |
447 | * class before registering it with the UMOModel | |
448 | * | |
449 | * @param implementation either a container refernece to an object or a fully | |
450 | * qualified class name to use as the component implementation which | |
451 | * event to invoke based on the evnet payload type | |
452 | * @param name The identifying name of the component. This can be used to later | |
453 | * unregister it | |
454 | * @param inboundEndpointUri The url endpointUri to listen to. Can be null | |
455 | * @param outboundEndpointUri The url endpointUri to dispatch to. Can be null | |
456 | * @param properties properties to set on the component. Can be null | |
457 | * @throws UMOException | |
458 | */ | |
459 | public UMODescriptor createDescriptor(String implementation, | |
460 | String name, | |
461 | UMOEndpointURI inboundEndpointUri, | |
462 | UMOEndpointURI outboundEndpointUri, | |
463 | Map properties) throws UMOException | |
464 | { | |
465 | // Create the endpoints | |
466 | 0 | UMOEndpoint inboundEndpoint = null; |
467 | 0 | UMOEndpoint outboundEndpoint = null; |
468 | 0 | if (inboundEndpointUri != null) |
469 | { | |
470 | 0 | inboundEndpoint = TransportFactory.createEndpoint(inboundEndpointUri, |
471 | UMOEndpoint.ENDPOINT_TYPE_RECEIVER); | |
472 | } | |
473 | 0 | if (outboundEndpointUri != null) |
474 | { | |
475 | 0 | outboundEndpoint = TransportFactory.createEndpoint(outboundEndpointUri, |
476 | UMOEndpoint.ENDPOINT_TYPE_SENDER); | |
477 | } | |
478 | 0 | return createDescriptor(implementation, name, inboundEndpoint, outboundEndpoint, properties); |
479 | } | |
480 | ||
481 | /** | |
482 | * Creates a Mule Descriptor that can be further maniputalted by the calling | |
483 | * class before registering it with the UMOModel | |
484 | * | |
485 | * @param implementation either a container refernece to an object or a fully | |
486 | * qualified class name to use as the component implementation which | |
487 | * event to invoke based on the evnet payload type | |
488 | * @param name The identifying name of the component. This can be used to later | |
489 | * unregister it | |
490 | * @param inboundEndpoint The endpoint to listen to. Can be null | |
491 | * @param outboundEndpoint The endpoint to dispatch to. Can be null | |
492 | * @param properties properties to set on the component. Can be null | |
493 | * @throws UMOException | |
494 | */ | |
495 | public UMODescriptor createDescriptor(String implementation, | |
496 | String name, | |
497 | UMOEndpoint inboundEndpoint, | |
498 | UMOEndpoint outboundEndpoint, | |
499 | Map properties) throws UMOException | |
500 | { | |
501 | 0 | MuleDescriptor descriptor = new MuleDescriptor(); |
502 | 0 | descriptor.setImplementation(implementation); |
503 | 0 | descriptor.setName(name); |
504 | 0 | if (properties != null) |
505 | { | |
506 | 0 | descriptor.getProperties().putAll(properties); |
507 | } | |
508 | ||
509 | 0 | descriptor.setInboundEndpoint(inboundEndpoint); |
510 | 0 | descriptor.setOutboundEndpoint(outboundEndpoint); |
511 | ||
512 | 0 | return descriptor; |
513 | } | |
514 | ||
515 | /** | |
516 | * Sets the component resolver on the model. Component resolver is used to look | |
517 | * up components in an external container such as Spring or Pico | |
518 | * | |
519 | * @param ctx | |
520 | * @throws UMOException | |
521 | */ | |
522 | public void setContainerContext(UMOContainerContext ctx) throws UMOException | |
523 | { | |
524 | 0 | manager.setContainerContext(ctx); |
525 | 0 | } |
526 | ||
527 | /** | |
528 | * Unregisters a previously register components. This will also unregister any | |
529 | * listeners for the components Calling this method is equivilent to calling | |
530 | * UMOModel.unregisterComponent(..) | |
531 | * | |
532 | * @param name the name of the componet to unregister | |
533 | * @throws UMOException if unregistering the components fails, i.e. The | |
534 | * underlying transport fails to unregister a listener. If the | |
535 | * components does not exist, this method should not throw an | |
536 | * exception. | |
537 | * @see org.mule.umo.model.UMOModel | |
538 | */ | |
539 | public void unregisterComponent(String name) throws UMOException | |
540 | { | |
541 | 0 | UMODescriptor descriptor = model.getDescriptor(name); |
542 | 0 | if (descriptor != null) |
543 | { | |
544 | 0 | getModel().unregisterComponent(descriptor); |
545 | } | |
546 | 0 | } |
547 | ||
548 | public UMOEndpoint createEndpoint(String uri, String name, boolean inbound) throws UMOException | |
549 | { | |
550 | 0 | return createEndpoint(uri, name, inbound, null, null); |
551 | } | |
552 | ||
553 | public UMOEndpoint createEndpoint(String uri, String name, boolean inbound, String transformers) | |
554 | throws UMOException | |
555 | { | |
556 | 0 | return createEndpoint(uri, name, inbound, transformers, null); |
557 | } | |
558 | ||
559 | public UMOEndpoint createEndpoint(String uri, String name, boolean inbound, UMOFilter filter) | |
560 | throws UMOException | |
561 | { | |
562 | 0 | return createEndpoint(uri, name, inbound, null, filter); |
563 | } | |
564 | ||
565 | public UMOEndpoint createEndpoint(String uri, | |
566 | String name, | |
567 | boolean inbound, | |
568 | String transformers, | |
569 | UMOFilter filter) throws UMOException | |
570 | { | |
571 | 0 | UMOEndpoint ep = MuleEndpoint.createEndpointFromUri(new MuleEndpointURI(uri), (inbound |
572 | ? UMOEndpoint.ENDPOINT_TYPE_RECEIVER : UMOEndpoint.ENDPOINT_TYPE_SENDER)); | |
573 | 0 | ep.setName(name); |
574 | 0 | if (transformers != null) |
575 | { | |
576 | 0 | String delim = (transformers.indexOf(",") > -1 ? "," : " "); |
577 | 0 | ep.setTransformer(MuleObjectHelper.getTransformer(transformers, delim)); |
578 | } | |
579 | 0 | ep.setFilter(filter); |
580 | 0 | return ep; |
581 | } | |
582 | ||
583 | public UMOEndpoint registerEndpoint(String uri, String name, boolean inbound) throws UMOException | |
584 | { | |
585 | 0 | UMOEndpoint ep = createEndpoint(uri, name, inbound); |
586 | 0 | ep.initialise(); |
587 | 0 | manager.registerEndpoint(ep); |
588 | 0 | return ep; |
589 | } | |
590 | ||
591 | public UMOEndpoint registerEndpoint(String uri, String name, boolean inbound, Map properties) | |
592 | throws UMOException | |
593 | { | |
594 | 0 | UMOEndpoint ep = createEndpoint(uri, name, inbound); |
595 | 0 | ep.getProperties().putAll(properties); |
596 | 0 | ep.initialise(); |
597 | 0 | manager.registerEndpoint(ep); |
598 | 0 | return ep; |
599 | } | |
600 | ||
601 | public UMOEndpoint registerEndpoint(String uri, | |
602 | String name, | |
603 | boolean inbound, | |
604 | Map properties, | |
605 | UMOFilter filter) throws UMOException | |
606 | { | |
607 | 0 | UMOEndpoint ep = createEndpoint(uri, name, inbound); |
608 | 0 | if (properties != null) |
609 | { | |
610 | 0 | ep.getProperties().putAll(properties); |
611 | } | |
612 | 0 | if (filter != null) |
613 | { | |
614 | 0 | ep.setFilter(filter); |
615 | } | |
616 | 0 | ep.initialise(); |
617 | 0 | manager.registerEndpoint(ep); |
618 | 0 | return ep; |
619 | } | |
620 | ||
621 | public void registerModel(UMOModel model) throws UMOException | |
622 | { | |
623 | 0 | this.model = model; |
624 | 0 | manager.registerModel(model); |
625 | 0 | } |
626 | ||
627 | public UMOManager getManager() | |
628 | { | |
629 | 0 | return manager; |
630 | } | |
631 | ||
632 | public UMOManager configure(String configResources) throws ConfigurationException | |
633 | { | |
634 | 0 | return configure(configResources, null); |
635 | } | |
636 | ||
637 | public UMOManager configure(String configResources, String startupPropertiesFile) | |
638 | throws ConfigurationException | |
639 | { | |
640 | 0 | return configure(new ReaderResource[0], null); |
641 | } | |
642 | ||
643 | public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException | |
644 | { | |
645 | 0 | return configure(configResources, null); |
646 | } | |
647 | ||
648 | public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) | |
649 | throws ConfigurationException | |
650 | { | |
651 | try | |
652 | { | |
653 | 0 | manager.start(); |
654 | } | |
655 | 0 | catch (UMOException e) |
656 | { | |
657 | 0 | throw new ConfigurationException(e); |
658 | 0 | } |
659 | 0 | return manager; |
660 | } | |
661 | ||
662 | public boolean isConfigured() | |
663 | { | |
664 | 0 | return manager != null; |
665 | } | |
666 | ||
667 | protected UMOModel getModel() throws UMOException | |
668 | { | |
669 | 0 | if (model == null) |
670 | { | |
671 | 0 | model = new SedaModel(); |
672 | 0 | model.setName("main"); |
673 | 0 | manager.registerModel(model); |
674 | } | |
675 | 0 | return model; |
676 | } | |
677 | } |