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