KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > NamingExceptionReader


1 /*
2  * $Id: NamingExceptionReader.java 4259 2006-12-14 03:12:07Z aperepel $
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 MuleSource MPL
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 javax.naming.Name JavaDoc;
14 import javax.naming.NamingException JavaDoc;
15
16 import java.util.Collections JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 public class NamingExceptionReader implements ExceptionReader
21 {
22     /**
23      * Displayed when no remaining or resolved name found.
24      */

25     protected static final String JavaDoc MISSING_NAME_DISPLAY_VALUE = "<none>";
26
27     public String JavaDoc getMessage(Throwable JavaDoc t)
28     {
29         return (t instanceof NamingException JavaDoc ? ((NamingException JavaDoc)t).toString(true) : "<unknown>");
30     }
31
32     public Throwable JavaDoc getCause(Throwable JavaDoc t)
33     {
34         return (t instanceof NamingException JavaDoc ? ((NamingException JavaDoc)t).getCause() : null);
35     }
36
37     public Class JavaDoc getExceptionType()
38     {
39         return NamingException JavaDoc.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 JavaDoc getInfo(Throwable JavaDoc t)
49     {
50         if (t instanceof NamingException JavaDoc)
51         {
52             NamingException JavaDoc e = (NamingException JavaDoc)t;
53             Map JavaDoc info = new HashMap JavaDoc();
54             final Name JavaDoc remainingName = e.getRemainingName();
55             final Name JavaDoc resolvedName = e.getResolvedName();
56             info.put("Remaining Name", remainingName == null
57                             ? MISSING_NAME_DISPLAY_VALUE : remainingName.toString());
58             info.put("Resolved Name", resolvedName == null ? MISSING_NAME_DISPLAY_VALUE : resolvedName.toString());
59             return info;
60         }
61         else
62         {
63             return Collections.EMPTY_MAP;
64         }
65     }
66 }
67
Popular Tags