Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExceptionTypeFilter |
|
| 2.3333333333333335;2.333 |
1 | /* | |
2 | * $Id: ExceptionTypeFilter.java 7963 2007-08-21 08:53:15Z 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 | 2 | super(); |
27 | 2 | } |
28 | ||
29 | public ExceptionTypeFilter(Class expectedType) | |
30 | { | |
31 | 2 | super(expectedType); |
32 | 2 | } |
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 | 8 | UMOExceptionPayload epl = message.getExceptionPayload(); |
43 | ||
44 | 8 | if (getExpectedType() == null) |
45 | { | |
46 | 4 | return epl != null; |
47 | } | |
48 | 4 | else if (epl != null) |
49 | { | |
50 | 4 | return getExpectedType().isAssignableFrom(epl.getException().getClass()); |
51 | } | |
52 | else | |
53 | { | |
54 | 0 | return false; |
55 | } | |
56 | } | |
57 | ||
58 | } |