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