View Javadoc

1   /*
2    * $Id$
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.processor;
12  
13  import org.mule.DefaultMuleEvent;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.MuleException;
16  import org.mule.api.endpoint.OutboundEndpoint;
17  import org.mule.api.processor.InterceptingMessageProcessor;
18  import org.mule.api.processor.MessageProcessor;
19  import org.mule.util.ObjectUtils;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  /**
25   * Abstract implementation of {@link InterceptingMessageProcessor} that simply
26   * provides an implementation of setNext and holds the next message processor as an
27   * attribute.
28   */
29  public abstract class AbstractInterceptingMessageProcessor implements InterceptingMessageProcessor
30  {
31      protected Log logger = LogFactory.getLog(getClass());
32  
33      public void setListener(MessageProcessor next)
34      {
35          this.next = next;
36      }
37  
38      protected MessageProcessor next;
39  
40      protected MuleEvent processNext(MuleEvent event) throws MuleException
41      {
42          if (next == null)
43          {
44              return event;
45          }
46          else
47          {
48              if (logger.isTraceEnabled())
49              {
50                  logger.trace("Invoking next MessageProcessor: '" + next.getClass().getName() + "' ");
51              }
52              // If the next message processor is an outbound router then create outbound event
53              if (next instanceof OutboundEndpoint)
54              {
55                  event = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint) next, event.getSession());
56              }
57              return next.process(event);
58          }
59      }
60      
61      @Override
62      public String toString()
63      {
64          return ObjectUtils.toString(this);
65      }
66  }