Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NamingExceptionReader |
|
| 1.5;1.5 |
1 | /* | |
2 | * $Id: NamingExceptionReader.java 10489 2008-01-23 17:53:38Z dfeist $ | |
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.config; | |
12 | ||
13 | import org.mule.api.config.ExceptionReader; | |
14 | ||
15 | import java.util.Collections; | |
16 | import java.util.HashMap; | |
17 | import java.util.Map; | |
18 | ||
19 | import javax.naming.Name; | |
20 | import javax.naming.NamingException; | |
21 | ||
22 | 2 | public class NamingExceptionReader implements ExceptionReader |
23 | { | |
24 | /** | |
25 | * Displayed when no remaining or resolved name found. | |
26 | */ | |
27 | protected static final String MISSING_NAME_DISPLAY_VALUE = "<none>"; | |
28 | ||
29 | public String getMessage(Throwable t) | |
30 | { | |
31 | 0 | return (t instanceof NamingException ? ((NamingException) t).toString(true) : "<unknown>"); |
32 | } | |
33 | ||
34 | public Throwable getCause(Throwable t) | |
35 | { | |
36 | 0 | return (t instanceof NamingException ? ((NamingException) t).getCause() : null); |
37 | } | |
38 | ||
39 | public Class getExceptionType() | |
40 | { | |
41 | 22 | return NamingException.class; |
42 | } | |
43 | ||
44 | /** | |
45 | * Returns a map of the non-stanard information stored on the exception | |
46 | * | |
47 | * @param t the exception to extract the information from | |
48 | * @return a map of the non-stanard information stored on the exception | |
49 | */ | |
50 | public Map getInfo(Throwable t) | |
51 | { | |
52 | 0 | if (t instanceof NamingException) |
53 | { | |
54 | 0 | NamingException e = (NamingException) t; |
55 | 0 | Map info = new HashMap(); |
56 | 0 | final Name remainingName = e.getRemainingName(); |
57 | 0 | final Name resolvedName = e.getResolvedName(); |
58 | 0 | info.put("Remaining Name", remainingName == null |
59 | ? MISSING_NAME_DISPLAY_VALUE : remainingName.toString()); | |
60 | 0 | info.put("Resolved Name", resolvedName == null ? MISSING_NAME_DISPLAY_VALUE : resolvedName.toString()); |
61 | 0 | return info; |
62 | } | |
63 | else | |
64 | { | |
65 | 0 | return Collections.EMPTY_MAP; |
66 | } | |
67 | } | |
68 | } |