1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.processor.chain; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleEvent; |
11 | |
import org.mule.api.MuleException; |
12 | |
import org.mule.api.context.MuleContextAware; |
13 | |
import org.mule.api.processor.MessageProcessor; |
14 | |
import org.mule.api.processor.MessageProcessorChain; |
15 | |
import org.mule.api.processor.policy.Policies; |
16 | |
import org.mule.context.notification.MessageProcessorNotification; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class InterceptingChainLifecycleWrapper extends AbstractMessageProcessorChain |
27 | |
{ |
28 | |
private MessageProcessorChain chain; |
29 | |
|
30 | |
public InterceptingChainLifecycleWrapper(MessageProcessorChain chain, |
31 | |
List<MessageProcessor> processors, |
32 | |
String name) |
33 | |
{ |
34 | 0 | super(name, processors); |
35 | 0 | this.chain = chain; |
36 | 0 | } |
37 | |
|
38 | |
@Override |
39 | |
public List<MessageProcessor> getMessageProcessors() |
40 | |
{ |
41 | 0 | return chain.getMessageProcessors(); |
42 | |
} |
43 | |
|
44 | |
@Override |
45 | |
public String getName() |
46 | |
{ |
47 | 0 | return chain.getName(); |
48 | |
} |
49 | |
|
50 | |
@Override |
51 | |
public Policies getPolicies() |
52 | |
{ |
53 | 0 | return chain.getPolicies(); |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
protected MuleEvent doProcess(MuleEvent event) throws MuleException |
58 | |
{ |
59 | 0 | return chain.process(event); |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public void setMuleContext(MuleContext context) |
64 | |
{ |
65 | 0 | super.setMuleContext(context); |
66 | 0 | for (MessageProcessor processor : processors) |
67 | |
{ |
68 | 0 | if (processor instanceof MuleContextAware) |
69 | |
{ |
70 | 0 | ((MuleContextAware) processor).setMuleContext(context); |
71 | |
} |
72 | |
} |
73 | 0 | if (chain instanceof MuleContextAware) |
74 | |
{ |
75 | 0 | ((MuleContextAware) chain).setMuleContext(context); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
@Override |
80 | |
public MuleEvent process(MuleEvent event) throws MuleException |
81 | |
{ |
82 | 0 | if (event == null) |
83 | |
{ |
84 | 0 | return null; |
85 | |
} |
86 | |
|
87 | 0 | fireNotification(event.getFlowConstruct(), event, this, |
88 | |
MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE); |
89 | |
|
90 | 0 | MuleEvent result = super.process(event); |
91 | |
|
92 | 0 | fireNotification(event.getFlowConstruct(), result, this, |
93 | |
MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE); |
94 | |
|
95 | 0 | return result; |
96 | |
} |
97 | |
} |