1
2
3
4
5
6
7 package org.mule.processor;
8
9 import org.mule.api.MuleContext;
10 import org.mule.api.MuleException;
11 import org.mule.api.construct.FlowConstruct;
12 import org.mule.api.construct.FlowConstructAware;
13 import org.mule.api.context.MuleContextAware;
14 import org.mule.api.lifecycle.Disposable;
15 import org.mule.api.lifecycle.Initialisable;
16 import org.mule.api.lifecycle.InitialisationException;
17 import org.mule.api.lifecycle.Lifecycle;
18 import org.mule.api.lifecycle.Startable;
19 import org.mule.api.lifecycle.Stoppable;
20 import org.mule.api.processor.MessageProcessor;
21
22 import java.util.List;
23
24
25
26
27 public abstract class AbstractMessageProcessorOwner implements Lifecycle, MuleContextAware, FlowConstructAware
28 {
29 protected MuleContext muleContext;
30 protected FlowConstruct flowConstruct;
31
32 public void setMuleContext(MuleContext context)
33 {
34 this.muleContext = context;
35 }
36
37 public void setFlowConstruct(FlowConstruct flowConstruct)
38 {
39 this.flowConstruct = flowConstruct;
40 }
41
42 public void initialise() throws InitialisationException
43 {
44 for (MessageProcessor processor : getOwnedMessageProcessors())
45 {
46 if (processor instanceof MuleContextAware)
47 {
48 ((MuleContextAware) processor).setMuleContext(muleContext);
49 }
50 if (processor instanceof FlowConstructAware)
51 {
52 ((FlowConstructAware) processor).setFlowConstruct(flowConstruct);
53 }
54 if (processor instanceof Initialisable)
55 {
56 ((Initialisable) processor).initialise();
57 }
58 }
59 }
60
61 public void dispose()
62 {
63 for (MessageProcessor processor : getOwnedMessageProcessors())
64 {
65
66 if (processor instanceof Disposable)
67 {
68 ((Disposable) processor).dispose();
69 }
70 }
71 }
72
73
74 public void start() throws MuleException
75 {
76
77 for (MessageProcessor processor : getOwnedMessageProcessors())
78 {
79 if (processor instanceof Startable)
80 {
81 ((Startable) processor).start();
82 }
83 }
84 }
85
86
87 public void stop() throws MuleException
88 {
89
90 for (MessageProcessor processor : getOwnedMessageProcessors())
91 {
92 if (processor instanceof Stoppable)
93 {
94 ((Stoppable) processor).stop();
95 }
96
97 }
98 }
99
100 protected abstract List<MessageProcessor> getOwnedMessageProcessors();
101
102 }
103