KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > filters > ExceptionTypeFilter


1 /*
2  * $Id: ExceptionTypeFilter.java 4219 2006-12-09 10:15:14Z lajos $
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 MuleSource MPL
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 JavaDoc 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 }
59
Popular Tags