Coverage Report - org.mule.processor.AbstractInterceptingMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractInterceptingMessageProcessor
0%
0/29
0%
0/20
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.processor;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.MuleException;
 12  
 import org.mule.api.construct.FlowConstruct;
 13  
 import org.mule.api.context.MuleContextAware;
 14  
 import org.mule.api.context.notification.ServerNotificationHandler;
 15  
 import org.mule.api.processor.InterceptingMessageProcessor;
 16  
 import org.mule.api.processor.MessageProcessor;
 17  
 import org.mule.api.processor.MessageProcessorChain;
 18  
 import org.mule.context.notification.MessageProcessorNotification;
 19  
 import org.mule.processor.chain.DefaultMessageProcessorChain;
 20  
 import org.mule.util.ObjectUtils;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  * Abstract implementation of {@link InterceptingMessageProcessor} that simply
 27  
  * provides an implementation of setNext and holds the next message processor as an
 28  
  * attribute.
 29  
  */
 30  0
 public abstract class AbstractInterceptingMessageProcessor
 31  
     implements InterceptingMessageProcessor, MuleContextAware
 32  
 {
 33  0
     protected Log logger = LogFactory.getLog(getClass());
 34  
 
 35  
     protected ServerNotificationHandler notificationHandler;
 36  
 
 37  
     protected MuleContext muleContext;
 38  
 
 39  
     public void setMuleContext(MuleContext context)
 40  
     {
 41  0
         this.muleContext = context;
 42  0
         notificationHandler = muleContext.getNotificationManager();
 43  0
         if (next instanceof DefaultMessageProcessorChain)
 44  
         {
 45  0
             ((DefaultMessageProcessorChain) next).setMuleContext(context);
 46  
         }
 47  0
     }
 48  
 
 49  
     public void setListener(MessageProcessor next)
 50  
     {
 51  0
         this.next = next;
 52  0
     }
 53  
 
 54  
     protected MessageProcessor next;
 55  
 
 56  
     protected MuleEvent processNext(MuleEvent event) throws MuleException
 57  
     {
 58  0
         if (next == null)
 59  
         {
 60  0
             return event;
 61  
         }
 62  0
         else if (event == null)
 63  
         {
 64  0
             if (logger.isDebugEnabled())
 65  
             {
 66  0
                 logger.trace("MuleEvent is null.  Next MessageProcessor '" + next.getClass().getName()
 67  
                              + "' will not be invoked.");
 68  
             }
 69  0
             return null;
 70  
         }
 71  
         else
 72  
         {
 73  0
             if (logger.isTraceEnabled())
 74  
             {
 75  0
                 logger.trace("Invoking next MessageProcessor: '" + next.getClass().getName() + "' ");
 76  
             }
 77  
 
 78  0
             boolean fireNotification = !(next instanceof MessageProcessorChain);
 79  
 
 80  0
             if (fireNotification)
 81  
             {
 82  
                 // note that we're firing event for the next in chain, not this MP
 83  0
                 fireNotification(event.getFlowConstruct(), event, next,
 84  
                     MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE);
 85  
             }
 86  0
             final MuleEvent result = next.process(event);
 87  0
             if (fireNotification)
 88  
             {
 89  0
                 fireNotification(event.getFlowConstruct(), result, next,
 90  
                     MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE);
 91  
             }
 92  0
             return result;
 93  
         }
 94  
     }
 95  
 
 96  
     public MuleContext getMuleContext()
 97  
     {
 98  0
         return muleContext;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public String toString()
 103  
     {
 104  0
         return ObjectUtils.toString(this);
 105  
     }
 106  
 
 107  
     protected void fireNotification(FlowConstruct flowConstruct, MuleEvent event, MessageProcessor processor, int action)
 108  
     {
 109  0
         if (notificationHandler != null
 110  
             && notificationHandler.isNotificationEnabled(MessageProcessorNotification.class))
 111  
         {
 112  0
             notificationHandler.fireNotification(new MessageProcessorNotification(flowConstruct, event, processor, action));
 113  
         }
 114  0
     }
 115  
 
 116  
 }