Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NamingExceptionReader |
|
| 0.0;0 |
1 | /* | |
2 | * $Id: NamingExceptionReader.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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 | 0 | 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 | 0 | 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 | ||
56 | 0 | Map<String, Object> info = new HashMap<String, Object>(); |
57 | 0 | final Name remainingName = e.getRemainingName(); |
58 | 0 | final Name resolvedName = e.getResolvedName(); |
59 | 0 | info.put("Remaining Name", remainingName == null ? |
60 | MISSING_NAME_DISPLAY_VALUE : remainingName.toString()); | |
61 | 0 | info.put("Resolved Name", resolvedName == null ? |
62 | MISSING_NAME_DISPLAY_VALUE : resolvedName.toString()); | |
63 | 0 | return info; |
64 | } | |
65 | else | |
66 | { | |
67 | 0 | return Collections.EMPTY_MAP; |
68 | } | |
69 | } | |
70 | } |