View Javadoc

1   /*
2    * $Id: NamingExceptionReader.java 7976 2007-08-21 14:26:13Z 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  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          return (t instanceof NamingException ? ((NamingException) t).toString(true) : "<unknown>");
30      }
31  
32      public Throwable getCause(Throwable t)
33      {
34          return (t instanceof NamingException ? ((NamingException) t).getCause() : null);
35      }
36  
37      public Class getExceptionType()
38      {
39          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          if (t instanceof NamingException)
51          {
52              NamingException e = (NamingException) t;
53              Map info = new HashMap();
54              final Name remainingName = e.getRemainingName();
55              final Name 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  }