1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.processor; |
12 | |
|
13 | |
import org.mule.DefaultMuleEvent; |
14 | |
import org.mule.api.MuleContext; |
15 | |
import org.mule.api.MuleEvent; |
16 | |
import org.mule.api.MuleException; |
17 | |
import org.mule.api.context.MuleContextAware; |
18 | |
import org.mule.api.context.notification.ServerNotificationHandler; |
19 | |
import org.mule.api.endpoint.OutboundEndpoint; |
20 | |
import org.mule.api.processor.InterceptingMessageProcessor; |
21 | |
import org.mule.api.processor.MessageProcessor; |
22 | |
import org.mule.context.notification.MessageProcessorNotification; |
23 | |
import org.mule.util.ObjectUtils; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public abstract class AbstractInterceptingMessageProcessor implements InterceptingMessageProcessor, MuleContextAware |
34 | |
{ |
35 | 0 | protected Log logger = LogFactory.getLog(getClass()); |
36 | |
|
37 | |
protected ServerNotificationHandler notificationHandler; |
38 | |
|
39 | |
protected MuleContext muleContext; |
40 | |
|
41 | |
public void setMuleContext(MuleContext context) |
42 | |
{ |
43 | 0 | this.muleContext = context; |
44 | 0 | notificationHandler = muleContext.getNotificationManager(); |
45 | 0 | } |
46 | |
|
47 | |
public void setListener(MessageProcessor next) |
48 | |
{ |
49 | 0 | this.next = next; |
50 | 0 | } |
51 | |
|
52 | |
protected MessageProcessor next; |
53 | |
|
54 | |
protected MuleEvent processNext(MuleEvent event) throws MuleException |
55 | |
{ |
56 | 0 | if (next == null) |
57 | |
{ |
58 | 0 | return event; |
59 | |
} |
60 | |
else |
61 | |
{ |
62 | 0 | if (logger.isTraceEnabled()) |
63 | |
{ |
64 | 0 | logger.trace("Invoking next MessageProcessor: '" + next.getClass().getName() + "' "); |
65 | |
} |
66 | |
|
67 | |
|
68 | 0 | fireNotification(event, next, MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE); |
69 | |
|
70 | |
|
71 | 0 | if (next instanceof OutboundEndpoint) |
72 | |
{ |
73 | 0 | event = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint) next, event.getSession()); |
74 | |
} |
75 | 0 | final MuleEvent result = next.process(event); |
76 | |
|
77 | 0 | fireNotification(event, next, MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE); |
78 | |
|
79 | 0 | return result; |
80 | |
} |
81 | |
} |
82 | |
|
83 | |
public MuleContext getMuleContext() |
84 | |
{ |
85 | 0 | return muleContext; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public String toString() |
90 | |
{ |
91 | 0 | return ObjectUtils.toString(this); |
92 | |
} |
93 | |
|
94 | |
protected void fireNotification(MuleEvent event, MessageProcessor processor, int action) |
95 | |
{ |
96 | 0 | if (notificationHandler != null && notificationHandler.isNotificationEnabled(MessageProcessorNotification.class)) |
97 | |
{ |
98 | 0 | notificationHandler.fireNotification(new MessageProcessorNotification(event, processor, action)); |
99 | |
} |
100 | 0 | } |
101 | |
|
102 | |
} |