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