Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExceptionTypeFilter |
|
| 2.0;2 |
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 | 0 | super(); |
24 | 0 | } |
25 | ||
26 | ||
27 | public ExceptionTypeFilter(String expectedType) throws ClassNotFoundException | |
28 | { | |
29 | 0 | this(ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class)); |
30 | 0 | } |
31 | ||
32 | public ExceptionTypeFilter(Class expectedType) | |
33 | { | |
34 | 0 | super(expectedType); |
35 | 0 | } |
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 | 0 | ExceptionPayload epl = message.getExceptionPayload(); |
46 | ||
47 | 0 | if (getExpectedType() == null) |
48 | { | |
49 | 0 | return epl != null; |
50 | } | |
51 | 0 | else if (epl != null) |
52 | { | |
53 | 0 | return getExpectedType().isAssignableFrom(epl.getException().getClass()); |
54 | } | |
55 | else | |
56 | { | |
57 | 0 | return false; |
58 | } | |
59 | } | |
60 | ||
61 | } |