View Javadoc

1   /*
2    * $Id: DefaultExceptionPayload.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.message;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.ExceptionPayload;
15  import org.mule.config.ExceptionHelper;
16  
17  import java.util.Map;
18  
19  /**
20   * <code>DefaultExceptionPayload</code> TODO
21   */
22  
23  public class DefaultExceptionPayload implements ExceptionPayload
24  {
25      /**
26       * Serial version
27       */
28      private static final long serialVersionUID = -7114836033686599024L;
29  
30      private int code = 0;
31      private String message = null;
32      private Map info = null;
33      private Throwable exception;
34  
35      public DefaultExceptionPayload(Throwable exception)
36      {
37          this.exception = exception;
38          MuleException muleRoot = ExceptionHelper.getRootMuleException(exception);
39          if (muleRoot != null)
40          {
41              message = muleRoot.getMessage();
42              code = muleRoot.getExceptionCode();
43              info = muleRoot.getInfo();
44          }
45          else
46          {
47              message = exception.getMessage();
48          }
49      }
50  
51      public Throwable getRootException()
52      {
53          return ExceptionHelper.getRootException(exception);
54      }
55  
56      public int getCode()
57      {
58          return code;
59      }
60  
61      public String getMessage()
62      {
63          return message;
64      }
65  
66      public Map getInfo()
67      {
68          return info;
69      }
70  
71      public Throwable getException()
72      {
73          return exception;
74      }
75  
76  }