1
2
3
4
5
6
7 package org.mule.config;
8
9 import org.mule.api.config.ExceptionReader;
10
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import javax.naming.Name;
16 import javax.naming.NamingException;
17
18 public class NamingExceptionReader implements ExceptionReader
19 {
20
21
22
23 protected static final String MISSING_NAME_DISPLAY_VALUE = "<none>";
24
25 public String getMessage(Throwable t)
26 {
27 return (t instanceof NamingException ? ((NamingException) t).toString(true) : "<unknown>");
28 }
29
30 public Throwable getCause(Throwable t)
31 {
32 return (t instanceof NamingException ? ((NamingException) t).getCause() : null);
33 }
34
35 public Class<?> getExceptionType()
36 {
37 return NamingException.class;
38 }
39
40
41
42
43
44
45
46 public Map<?, ?> getInfo(Throwable t)
47 {
48 if (t instanceof NamingException)
49 {
50 NamingException e = (NamingException) t;
51
52 Map<String, Object> info = new HashMap<String, Object>();
53 final Name remainingName = e.getRemainingName();
54 final Name resolvedName = e.getResolvedName();
55 info.put("Remaining Name", remainingName == null ?
56 MISSING_NAME_DISPLAY_VALUE : remainingName.toString());
57 info.put("Resolved Name", resolvedName == null ?
58 MISSING_NAME_DISPLAY_VALUE : resolvedName.toString());
59 return info;
60 }
61 else
62 {
63 return Collections.EMPTY_MAP;
64 }
65 }
66 }