1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.routing; |
8 | |
|
9 | |
import org.apache.commons.lang.Validate; |
10 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
11 | |
import org.apache.commons.lang.builder.ToStringStyle; |
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 | |
import org.mule.api.routing.filter.Filter; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class MessageProcessorFilterPair implements FlowConstructAware, MuleContextAware, Lifecycle |
30 | |
{ |
31 | |
private final MessageProcessor messageProcessor; |
32 | |
private final Filter filter; |
33 | |
|
34 | |
public MessageProcessorFilterPair(MessageProcessor messageProcessor, Filter filter) |
35 | 0 | { |
36 | 0 | Validate.notNull(messageProcessor, "messageProcessor can't be null"); |
37 | 0 | Validate.notNull(filter, "filter can't be null"); |
38 | 0 | this.messageProcessor = messageProcessor; |
39 | 0 | this.filter = filter; |
40 | 0 | } |
41 | |
|
42 | |
public MessageProcessor getMessageProcessor() |
43 | |
{ |
44 | 0 | return messageProcessor; |
45 | |
} |
46 | |
|
47 | |
public Filter getFilter() |
48 | |
{ |
49 | 0 | return filter; |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
public String toString() |
54 | |
{ |
55 | 0 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
62 | |
{ |
63 | 0 | if (messageProcessor instanceof FlowConstructAware) |
64 | |
{ |
65 | 0 | ((FlowConstructAware) messageProcessor).setFlowConstruct(flowConstruct); |
66 | |
} |
67 | 0 | if (filter instanceof FlowConstructAware) |
68 | |
{ |
69 | 0 | ((FlowConstructAware) filter).setFlowConstruct(flowConstruct); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
public void setMuleContext(MuleContext context) |
74 | |
{ |
75 | 0 | if (messageProcessor instanceof MuleContextAware) |
76 | |
{ |
77 | 0 | ((MuleContextAware) messageProcessor).setMuleContext(context); |
78 | |
} |
79 | 0 | if (filter instanceof MuleContextAware) |
80 | |
{ |
81 | 0 | ((MuleContextAware) filter).setMuleContext(context); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public void initialise() throws InitialisationException |
86 | |
{ |
87 | 0 | if (messageProcessor instanceof Initialisable) |
88 | |
{ |
89 | 0 | ((Initialisable) messageProcessor).initialise(); |
90 | |
} |
91 | 0 | if (filter instanceof Initialisable) |
92 | |
{ |
93 | 0 | ((Initialisable) filter).initialise(); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
public void start() throws MuleException |
98 | |
{ |
99 | 0 | if (messageProcessor instanceof Startable) |
100 | |
{ |
101 | 0 | ((Startable) messageProcessor).start(); |
102 | |
} |
103 | 0 | if (filter instanceof Startable) |
104 | |
{ |
105 | 0 | ((Startable) filter).start(); |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
public void stop() throws MuleException |
110 | |
{ |
111 | 0 | if (messageProcessor instanceof Stoppable) |
112 | |
{ |
113 | 0 | ((Stoppable) messageProcessor).stop(); |
114 | |
} |
115 | 0 | if (filter instanceof Stoppable) |
116 | |
{ |
117 | 0 | ((Stoppable) filter).stop(); |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
public void dispose() |
122 | |
{ |
123 | 0 | if (messageProcessor instanceof Disposable) |
124 | |
{ |
125 | 0 | ((Disposable) messageProcessor).dispose(); |
126 | |
} |
127 | 0 | if (filter instanceof Disposable) |
128 | |
{ |
129 | 0 | ((Disposable) filter).dispose(); |
130 | |
} |
131 | 0 | } |
132 | |
} |