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