Coverage Report - org.mule.routing.filters.ExceptionTypeFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionTypeFilter
100%
12/12
100%
6/6
2
 
 1  
 /*
 2  
  * $Id: ExceptionTypeFilter.java 11477 2008-03-22 00:18:50Z rossmason $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.routing.filters;
 12  
 
 13  
 import org.mule.api.ExceptionPayload;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.util.ClassUtils;
 16  
 
 17  
 /**
 18  
  * A filter that accepts messages that have an exception payload. An Exception type
 19  
  * can also be set on this filter to allow it to accept Exception messages of a
 20  
  * particular Exception class only.
 21  
  */
 22  
 public class ExceptionTypeFilter extends PayloadTypeFilter
 23  
 {
 24  
 
 25  
     public ExceptionTypeFilter()
 26  
     {
 27  2
         super();
 28  2
     }
 29  
 
 30  
 
 31  
     public ExceptionTypeFilter(String expectedType) throws ClassNotFoundException
 32  
     {
 33  8
         this(ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class));
 34  8
     }
 35  
 
 36  
     public ExceptionTypeFilter(Class expectedType)
 37  
     {
 38  10
         super(expectedType);
 39  10
     }
 40  
 
 41  
     /**
 42  
      * Check a given message against this filter.
 43  
      * 
 44  
      * @param message a non null message to filter.
 45  
      * @return <code>true</code> if the message matches the filter
 46  
      */
 47  
     public boolean accept(MuleMessage message)
 48  
     {
 49  16
         ExceptionPayload epl = message.getExceptionPayload();
 50  
 
 51  16
         if (getExpectedType() == null)
 52  
         {
 53  4
             return epl != null;
 54  
         }
 55  12
         else if (epl != null)
 56  
         {
 57  10
             return getExpectedType().isAssignableFrom(epl.getException().getClass());
 58  
         }
 59  
         else
 60  
         {
 61  2
             return false;
 62  
         }
 63  
     }
 64  
 
 65  
 }