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 public abstract class AbstractInterceptingMessageProcessor implements InterceptingMessageProcessor, MuleContextAware
34 {
35 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 this.muleContext = context;
44 notificationHandler = muleContext.getNotificationManager();
45 }
46
47 public void setListener(MessageProcessor next)
48 {
49 this.next = next;
50 }
51
52 protected MessageProcessor next;
53
54 protected MuleEvent processNext(MuleEvent event) throws MuleException
55 {
56 if (next == null)
57 {
58 return event;
59 }
60 else
61 {
62 if (logger.isTraceEnabled())
63 {
64 logger.trace("Invoking next MessageProcessor: '" + next.getClass().getName() + "' ");
65 }
66
67
68 fireNotification(event, next, MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE);
69
70
71 if (next instanceof OutboundEndpoint)
72 {
73 event = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint) next, event.getSession());
74 }
75 final MuleEvent result = next.process(event);
76
77 fireNotification(event, next, MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE);
78
79 return result;
80 }
81 }
82
83 public MuleContext getMuleContext()
84 {
85 return muleContext;
86 }
87
88 @Override
89 public String toString()
90 {
91 return ObjectUtils.toString(this);
92 }
93
94 protected void fireNotification(MuleEvent event, MessageProcessor processor, int action)
95 {
96 if (notificationHandler != null && notificationHandler.isNotificationEnabled(MessageProcessorNotification.class))
97 {
98 notificationHandler.fireNotification(new MessageProcessorNotification(event, processor, action));
99 }
100 }
101
102 }