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 | 502 | protected Map properties = new HashMap(); |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | 502 | protected String version = "1.0"; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | 502 | 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 | 502 | protected UMOTransformer inboundTransformer = null; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
protected UMOEndpoint outboundEndpoint; |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | 502 | protected UMOTransformer outboundTransformer = null; |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | 502 | 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 | 502 | protected boolean containerManaged = true; |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | 502 | protected String initialState = INITIAL_STATE_STARTED; |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | 502 | protected boolean singleton = false; |
187 | |
|
188 | 502 | protected List initialisationCallbacks = new ArrayList(); |
189 | |
|
190 | 502 | protected String encoding = null; |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | 502 | protected String container = null; |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
public ImmutableMuleDescriptor(ImmutableMuleDescriptor descriptor) |
206 | 80 | { |
207 | 80 | inboundRouter = descriptor.getInboundRouter(); |
208 | 80 | outboundRouter = descriptor.getOutboundRouter(); |
209 | 80 | responseRouter = descriptor.getResponseRouter(); |
210 | 80 | inboundTransformer = descriptor.getInboundTransformer(); |
211 | 80 | outboundTransformer = descriptor.getOutboundTransformer(); |
212 | 80 | responseTransformer = descriptor.getResponseTransformer(); |
213 | 80 | implementationReference = descriptor.getImplementation(); |
214 | 80 | version = descriptor.getVersion(); |
215 | 80 | intecerptorList = descriptor.getInterceptors(); |
216 | 80 | properties = descriptor.getProperties(); |
217 | 80 | name = descriptor.getName(); |
218 | 80 | encoding = descriptor.getEncoding(); |
219 | |
|
220 | 80 | threadingProfile = descriptor.getThreadingProfile(); |
221 | 80 | poolingProfile = descriptor.getPoolingProfile(); |
222 | 80 | queueProfile = descriptor.getQueueProfile(); |
223 | 80 | exceptionListener = descriptor.getExceptionListener(); |
224 | 80 | initialState = descriptor.getInitialState(); |
225 | 80 | singleton = descriptor.isSingleton(); |
226 | 80 | containerManaged = descriptor.isContainerManaged(); |
227 | 80 | } |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
protected ImmutableMuleDescriptor() |
234 | 422 | { |
235 | 422 | inboundRouter = new InboundRouterCollection(); |
236 | 422 | inboundRouter.addRouter(new InboundPassThroughRouter()); |
237 | 422 | } |
238 | |
|
239 | |
public void initialise() throws InitialisationException |
240 | |
{ |
241 | 432 | MuleConfiguration config = MuleManager.getConfiguration(); |
242 | 432 | if (threadingProfile == null) |
243 | |
{ |
244 | 410 | threadingProfile = config.getComponentThreadingProfile(); |
245 | |
} |
246 | 432 | if (poolingProfile == null) |
247 | |
{ |
248 | 410 | poolingProfile = config.getPoolingProfile(); |
249 | |
} |
250 | 432 | if (queueProfile == null) |
251 | |
{ |
252 | 410 | queueProfile = config.getQueueProfile(); |
253 | |
} |
254 | |
|
255 | 22 | else if (exceptionListener instanceof Initialisable) |
256 | |
{ |
257 | 22 | ((Initialisable) exceptionListener).initialise(); |
258 | |
} |
259 | |
|
260 | 432 | if (inboundEndpoint != null) |
261 | |
{ |
262 | 22 | if (inboundTransformer != null) |
263 | |
{ |
264 | 0 | inboundEndpoint.setTransformer(inboundTransformer); |
265 | |
} |
266 | 22 | ((MuleEndpoint) inboundEndpoint).initialise(); |
267 | |
|
268 | |
|
269 | |
|
270 | 22 | if (inboundTransformer == null) |
271 | |
{ |
272 | 22 | inboundTransformer = inboundEndpoint.getTransformer(); |
273 | |
} |
274 | |
} |
275 | |
|
276 | 432 | if (outboundEndpoint != null) |
277 | |
{ |
278 | 402 | if (outboundTransformer != null) |
279 | |
{ |
280 | 0 | outboundEndpoint.setTransformer(outboundTransformer); |
281 | |
} |
282 | 402 | ((MuleEndpoint) outboundEndpoint).initialise(); |
283 | |
|
284 | |
|
285 | |
|
286 | 402 | if (outboundTransformer == null) |
287 | |
{ |
288 | 402 | outboundTransformer = outboundEndpoint.getTransformer(); |
289 | |
} |
290 | |
} |
291 | |
|
292 | 432 | if (exceptionListener instanceof Initialisable) |
293 | |
{ |
294 | 420 | ((Initialisable) exceptionListener).initialise(); |
295 | |
} |
296 | |
|
297 | |
MuleEndpoint endpoint; |
298 | 432 | if (inboundRouter == null) |
299 | |
{ |
300 | |
|
301 | |
|
302 | 0 | inboundRouter = new InboundRouterCollection(); |
303 | 0 | inboundRouter.addRouter(new InboundPassThroughRouter()); |
304 | |
} |
305 | |
else |
306 | |
{ |
307 | 432 | if (inboundRouter.getCatchAllStrategy() != null |
308 | |
&& inboundRouter.getCatchAllStrategy().getEndpoint() != null) |
309 | |
{ |
310 | 0 | ((MuleEndpoint) inboundRouter.getCatchAllStrategy().getEndpoint()).initialise(); |
311 | |
} |
312 | 432 | for (Iterator iterator = inboundRouter.getEndpoints().iterator(); iterator.hasNext();) |
313 | |
{ |
314 | 0 | endpoint = (MuleEndpoint) iterator.next(); |
315 | 0 | endpoint.initialise(); |
316 | |
} |
317 | |
} |
318 | |
|
319 | 432 | if (responseRouter != null) |
320 | |
{ |
321 | 0 | for (Iterator iterator = responseRouter.getEndpoints().iterator(); iterator.hasNext();) |
322 | |
{ |
323 | 0 | endpoint = (MuleEndpoint) iterator.next(); |
324 | 0 | endpoint.initialise(); |
325 | |
} |
326 | |
} |
327 | |
|
328 | 432 | if (nestedRouter != null) |
329 | |
{ |
330 | 0 | for (Iterator it = nestedRouter.getRouters().iterator(); it.hasNext();) |
331 | |
{ |
332 | 0 | UMONestedRouter nestedRouter = (UMONestedRouter) it.next(); |
333 | 0 | endpoint = (MuleEndpoint) nestedRouter.getEndpoint(); |
334 | 0 | endpoint.initialise(); |
335 | 0 | } |
336 | |
} |
337 | |
|
338 | 432 | if (outboundRouter == null) |
339 | |
{ |
340 | 410 | outboundRouter = new OutboundRouterCollection(); |
341 | 410 | outboundRouter.addRouter(new OutboundPassThroughRouter(this)); |
342 | |
} |
343 | |
else |
344 | |
{ |
345 | 22 | if (outboundRouter.getCatchAllStrategy() != null |
346 | |
&& outboundRouter.getCatchAllStrategy().getEndpoint() != null) |
347 | |
{ |
348 | 0 | outboundRouter.getCatchAllStrategy().getEndpoint().initialise(); |
349 | |
} |
350 | |
UMOOutboundRouter router; |
351 | 22 | for (Iterator iterator = outboundRouter.getRouters().iterator(); iterator.hasNext();) |
352 | |
{ |
353 | 22 | router = (UMOOutboundRouter) iterator.next(); |
354 | 22 | for (Iterator iterator1 = router.getEndpoints().iterator(); iterator1.hasNext();) |
355 | |
{ |
356 | 22 | endpoint = (MuleEndpoint) iterator1.next(); |
357 | 22 | endpoint.initialise(); |
358 | |
} |
359 | |
} |
360 | |
} |
361 | |
|
362 | 432 | if (implementationReference instanceof String) |
363 | |
{ |
364 | 398 | if (DescriptorContainerContext.DESCRIPTOR_CONTAINER_NAME.equals(container)) |
365 | |
{ |
366 | 0 | implementationReference = new DescriptorContainerKeyPair(name, implementationReference); |
367 | |
} |
368 | |
else |
369 | |
{ |
370 | 398 | implementationReference = new ContainerKeyPair(container, implementationReference); |
371 | |
} |
372 | |
} |
373 | 432 | } |
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
public ExceptionListener getExceptionListener() |
381 | |
{ |
382 | 284 | return exceptionListener; |
383 | |
} |
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
public UMOTransformer getInboundTransformer() |
391 | |
{ |
392 | 82 | return inboundTransformer; |
393 | |
} |
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
public String getName() |
401 | |
{ |
402 | 1120 | return name; |
403 | |
} |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
public UMOTransformer getOutboundTransformer() |
411 | |
{ |
412 | 82 | return outboundTransformer; |
413 | |
} |
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
public UMOTransformer getResponseTransformer() |
421 | |
{ |
422 | 80 | return responseTransformer; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
public Map getProperties() |
433 | |
{ |
434 | 248 | return properties; |
435 | |
} |
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
public String getVersion() |
443 | |
{ |
444 | 82 | return version; |
445 | |
} |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
public List getInterceptors() |
453 | |
{ |
454 | 244 | return intecerptorList; |
455 | |
} |
456 | |
|
457 | |
public String getEncoding() |
458 | |
{ |
459 | 80 | return encoding; |
460 | |
} |
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
public String toString() |
468 | |
{ |
469 | 0 | StringBuffer buffer = new StringBuffer(); |
470 | 0 | buffer.append("name=").append(name); |
471 | 0 | buffer.append(", outbound endpoint=").append(outboundEndpoint); |
472 | 0 | buffer.append(", send transformer=").append(outboundTransformer); |
473 | 0 | buffer.append(", inbound endpointUri=").append(inboundEndpoint); |
474 | 0 | buffer.append(", receive transformer=").append(inboundTransformer); |
475 | 0 | buffer.append(", encoding=").append(encoding); |
476 | 0 | return buffer.toString(); |
477 | |
} |
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
public Object getImplementation() |
485 | |
{ |
486 | 166 | return implementationReference; |
487 | |
} |
488 | |
|
489 | |
public UMOInboundRouterCollection getInboundRouter() |
490 | |
{ |
491 | 286 | return inboundRouter; |
492 | |
} |
493 | |
|
494 | |
public UMOOutboundRouterCollection getOutboundRouter() |
495 | |
{ |
496 | 128 | return outboundRouter; |
497 | |
} |
498 | |
|
499 | |
public UMONestedRouterCollection getNestedRouter() |
500 | |
{ |
501 | 80 | return nestedRouter; |
502 | |
} |
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
public ThreadingProfile getThreadingProfile() |
509 | |
{ |
510 | 158 | return threadingProfile; |
511 | |
} |
512 | |
|
513 | |
public PoolingProfile getPoolingProfile() |
514 | |
{ |
515 | 120 | return poolingProfile; |
516 | |
} |
517 | |
|
518 | |
public QueueProfile getQueueProfile() |
519 | |
{ |
520 | 116 | return queueProfile; |
521 | |
} |
522 | |
|
523 | |
public boolean isContainerManaged() |
524 | |
{ |
525 | 80 | return !MuleContainerContext.MULE_CONTAINER_NAME.equalsIgnoreCase(container); |
526 | |
} |
527 | |
|
528 | |
public Class getImplementationClass() throws UMOException |
529 | |
{ |
530 | |
|
531 | |
Class implClass; |
532 | 0 | if (implementationReference instanceof String || implementationReference instanceof ContainerKeyPair) |
533 | |
{ |
534 | 0 | Object object = MuleManager.getInstance().getContainerContext().getComponent( |
535 | |
implementationReference); |
536 | 0 | implClass = object.getClass(); |
537 | 0 | } |
538 | |
else |
539 | |
{ |
540 | 0 | implClass = implementationReference.getClass(); |
541 | |
} |
542 | |
|
543 | 0 | return implClass; |
544 | |
} |
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
protected Class getImplementationForReference(String reference) throws ContainerException |
555 | |
{ |
556 | 0 | Object object = MuleManager.getInstance().getContainerContext().getComponent(reference); |
557 | 0 | return object.getClass(); |
558 | |
} |
559 | |
|
560 | |
public void fireInitialisationCallbacks(Object component) throws InitialisationException |
561 | |
{ |
562 | |
InitialisationCallback callback; |
563 | 80 | for (Iterator iterator = initialisationCallbacks.iterator(); iterator.hasNext();) |
564 | |
{ |
565 | 0 | callback = (InitialisationCallback) iterator.next(); |
566 | 0 | callback.initialise(component); |
567 | |
} |
568 | 80 | } |
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
public UMOEndpoint getInboundEndpoint() |
578 | |
{ |
579 | 230 | return inboundEndpoint; |
580 | |
} |
581 | |
|
582 | |
|
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
public UMOEndpoint getOutboundEndpoint() |
590 | |
{ |
591 | 796 | return outboundEndpoint; |
592 | |
} |
593 | |
|
594 | |
public UMOResponseRouterCollection getResponseRouter() |
595 | |
{ |
596 | 232 | return responseRouter; |
597 | |
} |
598 | |
|
599 | |
public boolean isSingleton() |
600 | |
{ |
601 | 150 | return singleton; |
602 | |
} |
603 | |
|
604 | |
public String getInitialState() |
605 | |
{ |
606 | 104 | return initialState; |
607 | |
} |
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
public String getContainer() |
618 | |
{ |
619 | 0 | return container; |
620 | |
} |
621 | |
|
622 | |
|
623 | |
public String getModelName() |
624 | |
{ |
625 | 0 | return modelName; |
626 | |
} |
627 | |
} |