View Javadoc

1   /*
2    * $Id: ExceptionTypeFilter.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.umo.UMOExceptionPayload;
14  import org.mule.umo.UMOMessage;
15  
16  /**
17   * A filter that accepts messages that have an exception payload. An Exception type
18   * can also be set on this filter to allow it to accept Exception messages of a
19   * particular Exception class only.
20   */
21  public class ExceptionTypeFilter extends PayloadTypeFilter
22  {
23  
24      public ExceptionTypeFilter()
25      {
26          super();
27      }
28  
29      public ExceptionTypeFilter(Class expectedType)
30      {
31          super(expectedType);
32      }
33  
34      /**
35       * Check a given message against this filter.
36       * 
37       * @param message a non null message to filter.
38       * @return <code>true</code> if the message matches the filter
39       */
40      public boolean accept(UMOMessage message)
41      {
42          UMOExceptionPayload epl = message.getExceptionPayload();
43  
44          if (getExpectedType() == null)
45          {
46              return epl != null;
47          }
48          else if (epl != null)
49          {
50              return getExpectedType().isAssignableFrom(epl.getException().getClass());
51          }
52          else
53          {
54              return false;
55          }
56      }
57  
58  }