1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl;
12
13 import org.mule.MuleManager;
14 import org.mule.config.MuleConfiguration;
15 import org.mule.config.PoolingProfile;
16 import org.mule.config.QueueProfile;
17 import org.mule.config.ThreadingProfile;
18 import org.mule.impl.container.ContainerKeyPair;
19 import org.mule.impl.container.DescriptorContainerContext;
20 import org.mule.impl.container.DescriptorContainerKeyPair;
21 import org.mule.impl.container.MuleContainerContext;
22 import org.mule.impl.endpoint.MuleEndpoint;
23 import org.mule.routing.inbound.InboundPassThroughRouter;
24 import org.mule.routing.inbound.InboundRouterCollection;
25 import org.mule.routing.outbound.OutboundPassThroughRouter;
26 import org.mule.routing.outbound.OutboundRouterCollection;
27 import org.mule.umo.UMOException;
28 import org.mule.umo.UMOImmutableDescriptor;
29 import org.mule.umo.endpoint.UMOEndpoint;
30 import org.mule.umo.lifecycle.Initialisable;
31 import org.mule.umo.lifecycle.InitialisationException;
32 import org.mule.umo.manager.ContainerException;
33 import org.mule.umo.routing.UMOInboundRouterCollection;
34 import org.mule.umo.routing.UMONestedRouter;
35 import org.mule.umo.routing.UMONestedRouterCollection;
36 import org.mule.umo.routing.UMOOutboundRouter;
37 import org.mule.umo.routing.UMOOutboundRouterCollection;
38 import org.mule.umo.routing.UMOResponseRouterCollection;
39 import org.mule.umo.transformer.UMOTransformer;
40
41 import java.beans.ExceptionListener;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.Iterator;
45 import java.util.List;
46 import java.util.Map;
47
48 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
49
50
51
52
53
54
55 public class ImmutableMuleDescriptor implements UMOImmutableDescriptor
56 {
57
58
59
60 public static final String INITIAL_STATE_STOPPED = "stopped";
61 public static final String INITIAL_STATE_STARTED = "started";
62 public static final String INITIAL_STATE_PAUSED = "paused";
63
64
65
66
67 protected static final String MULE_PROPERTY_DOT_PROPERTIES = "org.mule.dotProperties";
68
69
70
71
72 protected ExceptionListener exceptionListener;
73
74
75
76
77
78
79 protected Object implementationReference;
80
81
82
83
84 protected String name;
85
86
87
88
89 protected Map properties = new HashMap();
90
91
92
93
94 protected String version = "1.0";
95
96
97
98
99 protected List intecerptorList = new CopyOnWriteArrayList();
100
101 protected UMOInboundRouterCollection inboundRouter;
102
103 protected UMOOutboundRouterCollection outboundRouter;
104
105 protected UMONestedRouterCollection nestedRouter;
106
107 protected UMOResponseRouterCollection responseRouter;
108
109 protected String modelName;
110
111
112
113
114
115
116
117 protected UMOEndpoint inboundEndpoint;
118
119
120
121
122
123
124
125 protected UMOTransformer inboundTransformer = null;
126
127
128
129
130
131
132
133 protected UMOEndpoint outboundEndpoint;
134
135
136
137
138
139
140
141 protected UMOTransformer outboundTransformer = null;
142
143
144
145
146
147
148
149 protected UMOTransformer responseTransformer = null;
150
151
152
153
154
155 protected ThreadingProfile threadingProfile;
156
157
158
159
160
161 protected PoolingProfile poolingProfile;
162
163
164
165
166 protected QueueProfile queueProfile;
167
168
169
170
171
172
173
174
175 protected boolean containerManaged = true;
176
177
178
179
180
181 protected String initialState = INITIAL_STATE_STARTED;
182
183
184
185
186 protected boolean singleton = false;
187
188 protected List initialisationCallbacks = new ArrayList();
189
190 protected String encoding = null;
191
192
193
194
195
196
197 protected String container = null;
198
199
200
201
202
203
204
205 public ImmutableMuleDescriptor(ImmutableMuleDescriptor descriptor)
206 {
207 inboundRouter = descriptor.getInboundRouter();
208 outboundRouter = descriptor.getOutboundRouter();
209 responseRouter = descriptor.getResponseRouter();
210 inboundTransformer = descriptor.getInboundTransformer();
211 outboundTransformer = descriptor.getOutboundTransformer();
212 responseTransformer = descriptor.getResponseTransformer();
213 implementationReference = descriptor.getImplementation();
214 version = descriptor.getVersion();
215 intecerptorList = descriptor.getInterceptors();
216 properties = descriptor.getProperties();
217 name = descriptor.getName();
218 encoding = descriptor.getEncoding();
219
220 threadingProfile = descriptor.getThreadingProfile();
221 poolingProfile = descriptor.getPoolingProfile();
222 queueProfile = descriptor.getQueueProfile();
223 exceptionListener = descriptor.getExceptionListener();
224 initialState = descriptor.getInitialState();
225 singleton = descriptor.isSingleton();
226 containerManaged = descriptor.isContainerManaged();
227 }
228
229
230
231
232
233 protected ImmutableMuleDescriptor()
234 {
235 inboundRouter = new InboundRouterCollection();
236 inboundRouter.addRouter(new InboundPassThroughRouter());
237 }
238
239 public void initialise() throws InitialisationException
240 {
241 MuleConfiguration config = MuleManager.getConfiguration();
242 if (threadingProfile == null)
243 {
244 threadingProfile = config.getComponentThreadingProfile();
245 }
246 if (poolingProfile == null)
247 {
248 poolingProfile = config.getPoolingProfile();
249 }
250 if (queueProfile == null)
251 {
252 queueProfile = config.getQueueProfile();
253 }
254
255 else if (exceptionListener instanceof Initialisable)
256 {
257 ((Initialisable) exceptionListener).initialise();
258 }
259
260 if (inboundEndpoint != null)
261 {
262 if (inboundTransformer != null)
263 {
264 inboundEndpoint.setTransformer(inboundTransformer);
265 }
266 ((MuleEndpoint) inboundEndpoint).initialise();
267
268
269
270 if (inboundTransformer == null)
271 {
272 inboundTransformer = inboundEndpoint.getTransformer();
273 }
274 }
275
276 if (outboundEndpoint != null)
277 {
278 if (outboundTransformer != null)
279 {
280 outboundEndpoint.setTransformer(outboundTransformer);
281 }
282 ((MuleEndpoint) outboundEndpoint).initialise();
283
284
285
286 if (outboundTransformer == null)
287 {
288 outboundTransformer = outboundEndpoint.getTransformer();
289 }
290 }
291
292 if (exceptionListener instanceof Initialisable)
293 {
294 ((Initialisable) exceptionListener).initialise();
295 }
296
297 MuleEndpoint endpoint;
298 if (inboundRouter == null)
299 {
300
301
302 inboundRouter = new InboundRouterCollection();
303 inboundRouter.addRouter(new InboundPassThroughRouter());
304 }
305 else
306 {
307 if (inboundRouter.getCatchAllStrategy() != null
308 && inboundRouter.getCatchAllStrategy().getEndpoint() != null)
309 {
310 ((MuleEndpoint) inboundRouter.getCatchAllStrategy().getEndpoint()).initialise();
311 }
312 for (Iterator iterator = inboundRouter.getEndpoints().iterator(); iterator.hasNext();)
313 {
314 endpoint = (MuleEndpoint) iterator.next();
315 endpoint.initialise();
316 }
317 }
318
319 if (responseRouter != null)
320 {
321 for (Iterator iterator = responseRouter.getEndpoints().iterator(); iterator.hasNext();)
322 {
323 endpoint = (MuleEndpoint) iterator.next();
324 endpoint.initialise();
325 }
326 }
327
328 if (nestedRouter != null)
329 {
330 for (Iterator it = nestedRouter.getRouters().iterator(); it.hasNext();)
331 {
332 UMONestedRouter nestedRouter = (UMONestedRouter) it.next();
333 endpoint = (MuleEndpoint) nestedRouter.getEndpoint();
334 endpoint.initialise();
335 }
336 }
337
338 if (outboundRouter == null)
339 {
340 outboundRouter = new OutboundRouterCollection();
341 outboundRouter.addRouter(new OutboundPassThroughRouter(this));
342 }
343 else
344 {
345 if (outboundRouter.getCatchAllStrategy() != null
346 && outboundRouter.getCatchAllStrategy().getEndpoint() != null)
347 {
348 outboundRouter.getCatchAllStrategy().getEndpoint().initialise();
349 }
350 UMOOutboundRouter router;
351 for (Iterator iterator = outboundRouter.getRouters().iterator(); iterator.hasNext();)
352 {
353 router = (UMOOutboundRouter) iterator.next();
354 for (Iterator iterator1 = router.getEndpoints().iterator(); iterator1.hasNext();)
355 {
356 endpoint = (MuleEndpoint) iterator1.next();
357 endpoint.initialise();
358 }
359 }
360 }
361
362 if (implementationReference instanceof String)
363 {
364 if (DescriptorContainerContext.DESCRIPTOR_CONTAINER_NAME.equals(container))
365 {
366 implementationReference = new DescriptorContainerKeyPair(name, implementationReference);
367 }
368 else
369 {
370 implementationReference = new ContainerKeyPair(container, implementationReference);
371 }
372 }
373 }
374
375
376
377
378
379
380 public ExceptionListener getExceptionListener()
381 {
382 return exceptionListener;
383 }
384
385
386
387
388
389
390 public UMOTransformer getInboundTransformer()
391 {
392 return inboundTransformer;
393 }
394
395
396
397
398
399
400 public String getName()
401 {
402 return name;
403 }
404
405
406
407
408
409
410 public UMOTransformer getOutboundTransformer()
411 {
412 return outboundTransformer;
413 }
414
415
416
417
418
419
420 public UMOTransformer getResponseTransformer()
421 {
422 return responseTransformer;
423 }
424
425
426
427
428
429
430
431
432 public Map getProperties()
433 {
434 return properties;
435 }
436
437
438
439
440
441
442 public String getVersion()
443 {
444 return version;
445 }
446
447
448
449
450
451
452 public List getInterceptors()
453 {
454 return intecerptorList;
455 }
456
457 public String getEncoding()
458 {
459 return encoding;
460 }
461
462
463
464
465
466
467 public String toString()
468 {
469 StringBuffer buffer = new StringBuffer();
470 buffer.append("name=").append(name);
471 buffer.append(", outbound endpoint=").append(outboundEndpoint);
472 buffer.append(", send transformer=").append(outboundTransformer);
473 buffer.append(", inbound endpointUri=").append(inboundEndpoint);
474 buffer.append(", receive transformer=").append(inboundTransformer);
475 buffer.append(", encoding=").append(encoding);
476 return buffer.toString();
477 }
478
479
480
481
482
483
484 public Object getImplementation()
485 {
486 return implementationReference;
487 }
488
489 public UMOInboundRouterCollection getInboundRouter()
490 {
491 return inboundRouter;
492 }
493
494 public UMOOutboundRouterCollection getOutboundRouter()
495 {
496 return outboundRouter;
497 }
498
499 public UMONestedRouterCollection getNestedRouter()
500 {
501 return nestedRouter;
502 }
503
504
505
506
507
508 public ThreadingProfile getThreadingProfile()
509 {
510 return threadingProfile;
511 }
512
513 public PoolingProfile getPoolingProfile()
514 {
515 return poolingProfile;
516 }
517
518 public QueueProfile getQueueProfile()
519 {
520 return queueProfile;
521 }
522
523 public boolean isContainerManaged()
524 {
525 return !MuleContainerContext.MULE_CONTAINER_NAME.equalsIgnoreCase(container);
526 }
527
528 public Class getImplementationClass() throws UMOException
529 {
530
531 Class implClass;
532 if (implementationReference instanceof String || implementationReference instanceof ContainerKeyPair)
533 {
534 Object object = MuleManager.getInstance().getContainerContext().getComponent(
535 implementationReference);
536 implClass = object.getClass();
537 }
538 else
539 {
540 implClass = implementationReference.getClass();
541 }
542
543 return implClass;
544 }
545
546
547
548
549
550
551
552
553
554 protected Class getImplementationForReference(String reference) throws ContainerException
555 {
556 Object object = MuleManager.getInstance().getContainerContext().getComponent(reference);
557 return object.getClass();
558 }
559
560 public void fireInitialisationCallbacks(Object component) throws InitialisationException
561 {
562 InitialisationCallback callback;
563 for (Iterator iterator = initialisationCallbacks.iterator(); iterator.hasNext();)
564 {
565 callback = (InitialisationCallback) iterator.next();
566 callback.initialise(component);
567 }
568 }
569
570
571
572
573
574
575
576
577 public UMOEndpoint getInboundEndpoint()
578 {
579 return inboundEndpoint;
580 }
581
582
583
584
585
586
587
588
589 public UMOEndpoint getOutboundEndpoint()
590 {
591 return outboundEndpoint;
592 }
593
594 public UMOResponseRouterCollection getResponseRouter()
595 {
596 return responseRouter;
597 }
598
599 public boolean isSingleton()
600 {
601 return singleton;
602 }
603
604 public String getInitialState()
605 {
606 return initialState;
607 }
608
609
610
611
612
613
614
615
616
617 public String getContainer()
618 {
619 return container;
620 }
621
622
623 public String getModelName()
624 {
625 return modelName;
626 }
627 }