View Javadoc
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.routing.filters;
8   
9   import org.mule.api.ExceptionPayload;
10  import org.mule.api.MuleMessage;
11  import org.mule.util.ClassUtils;
12  
13  /**
14   * A filter that accepts messages that have an exception payload. An Exception type
15   * can also be set on this filter to allow it to accept Exception messages of a
16   * particular Exception class only.
17   */
18  public class ExceptionTypeFilter extends PayloadTypeFilter
19  {
20  
21      public ExceptionTypeFilter()
22      {
23          super();
24      }
25  
26  
27      public ExceptionTypeFilter(String expectedType) throws ClassNotFoundException
28      {
29          this(ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class));
30      }
31  
32      public ExceptionTypeFilter(Class expectedType)
33      {
34          super(expectedType);
35      }
36  
37      /**
38       * Check a given message against this filter.
39       * 
40       * @param message a non null message to filter.
41       * @return <code>true</code> if the message matches the filter
42       */
43      public boolean accept(MuleMessage message)
44      {
45          ExceptionPayload epl = message.getExceptionPayload();
46  
47          if (getExpectedType() == null)
48          {
49              return epl != null;
50          }
51          else if (epl != null)
52          {
53              return getExpectedType().isAssignableFrom(epl.getException().getClass());
54          }
55          else
56          {
57              return false;
58          }
59      }
60  
61  }