Coverage Report - org.mule.processor.AbstractFilteringMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFilteringMessageProcessor
0%
0/19
0%
0/8
1.875
 
 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.MuleEvent;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.construct.FlowConstruct;
 12  
 import org.mule.api.processor.InterceptingMessageProcessor;
 13  
 import org.mule.api.processor.MessageProcessor;
 14  
 import org.mule.api.routing.filter.FilterUnacceptedException;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 
 17  
 /**
 18  
  * Abstract {@link InterceptingMessageProcessor} that can be easily be extended and
 19  
  * used for filtering message flow through a {@link MessageProcessor} chain. The
 20  
  * default behaviour when the filter is not accepted is to return the request event.
 21  
  */
 22  0
 public abstract class AbstractFilteringMessageProcessor extends AbstractInterceptingMessageProcessor
 23  
 {
 24  
     /** 
 25  
      * Throw a FilterUnacceptedException when a message is rejected by the filter? 
 26  
      */
 27  0
     protected boolean throwOnUnaccepted = false;
 28  
     protected boolean onUnacceptedFlowConstruct;
 29  
 
 30  
     
 31  
     /** 
 32  
      * The <code>MessageProcessor</code> that should be used to handle messages that are not accepted by the filter.
 33  
      */
 34  
     protected MessageProcessor unacceptedMessageProcessor;
 35  
 
 36  
     public MuleEvent process(MuleEvent event) throws MuleException
 37  
     {
 38  0
         if (accept(event))
 39  
         {
 40  0
             return processNext(event);
 41  
         }
 42  
         else
 43  
         {
 44  0
             return handleUnaccepted(event);
 45  
         }
 46  
     }
 47  
 
 48  
     protected abstract boolean accept(MuleEvent event);
 49  
 
 50  
     protected MuleEvent handleUnaccepted(MuleEvent event) throws MuleException
 51  
     {        
 52  0
         if (unacceptedMessageProcessor != null)
 53  
         {
 54  0
             return unacceptedMessageProcessor.process(event);
 55  
         }
 56  0
         else if (throwOnUnaccepted)
 57  
         {
 58  0
             throw filterUnacceptedException(event);
 59  
         }
 60  
         else
 61  
         {
 62  0
             return null;
 63  
         }
 64  
     }
 65  
 
 66  
     protected MuleException filterUnacceptedException(MuleEvent event)
 67  
     {
 68  0
         return new FilterUnacceptedException(CoreMessages.messageRejectedByFilter(), event);        
 69  
     }
 70  
     
 71  
     public MessageProcessor getUnacceptedMessageProcessor()
 72  
     {
 73  0
         return unacceptedMessageProcessor;
 74  
     }
 75  
 
 76  
     public void setUnacceptedMessageProcessor(MessageProcessor unacceptedMessageProcessor)
 77  
     {
 78  0
         this.unacceptedMessageProcessor = unacceptedMessageProcessor;
 79  0
         if (unacceptedMessageProcessor instanceof FlowConstruct)
 80  
         {
 81  0
             onUnacceptedFlowConstruct = true;
 82  
         }
 83  0
     }
 84  
 
 85  
     public boolean isThrowOnUnaccepted()
 86  
     {
 87  0
         return throwOnUnaccepted;
 88  
     }
 89  
 
 90  
     public void setThrowOnUnaccepted(boolean throwOnUnaccepted)
 91  
     {
 92  0
         this.throwOnUnaccepted = throwOnUnaccepted;
 93  0
     }
 94  
 }