1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  import java.io.Serializable;
17  import java.util.Arrays;
18  
19  public class ThrowableProxyVO implements IThrowableProxy, Serializable {
20  
21      private static final long serialVersionUID = -773438177285807139L;
22  
23      private String className;
24      private String overridingMessage;
25      private String message;
26      private int commonFramesCount;
27      private StackTraceElementProxy[] stackTraceElementProxyArray;
28      private IThrowableProxy cause;
29      private IThrowableProxy[] suppressed;
30      private boolean cyclic;
31  
32      public String getMessage() {
33          return message;
34      }
35      /**
36       * Return the overriding message if any. This method returns null
37       * if there is no overriding message.
38       *
39       * <p>Overriding message exists only if the original throwable implementation overrides the toString() method.</p>
40       *
41       * @return the overriding message or null
42       * @since 1.5.22
43       */
44      @Override
45      public String getOverridingMessage() { return overridingMessage;}
46  
47      public String getClassName() {
48          return className;
49      }
50  
51      public int getCommonFrames() {
52          return commonFramesCount;
53      }
54  
55      public IThrowableProxy getCause() {
56          return cause;
57      }
58  
59      public StackTraceElementProxy[] getStackTraceElementProxyArray() {
60          return stackTraceElementProxyArray;
61      }
62  
63      public IThrowableProxy[] getSuppressed() {
64          return suppressed;
65      }
66  
67      public boolean isCyclic() {
68          return cyclic;
69      }
70  
71      @Override
72      public int hashCode() {
73          final int prime = 31;
74          int result = 1;
75          result = prime * result + ((className == null) ? 0 : className.hashCode());
76          return result;
77      }
78  
79      @Override
80      public boolean equals(Object obj) {
81          if (this == obj)
82              return true;
83          if (obj == null)
84              return false;
85          if (getClass() != obj.getClass())
86              return false;
87          final ThrowableProxyVO other = (ThrowableProxyVO) obj;
88  
89          if (className == null) {
90              if (other.className != null)
91                  return false;
92          } else if (!className.equals(other.className))
93              return false;
94  
95          if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray))
96              return false;
97  
98          if (!Arrays.equals(suppressed, other.suppressed))
99              return false;
100 
101         if (cause == null) {
102             if (other.cause != null)
103                 return false;
104         } else if (!cause.equals(other.cause))
105             return false;
106 
107         return true;
108     }
109 
110     public static ThrowableProxyVO build(IThrowableProxy throwableProxy) {
111         if (throwableProxy == null) {
112             return null;
113         }
114         ThrowableProxyVO tpvo = new ThrowableProxyVO();
115         tpvo.className = throwableProxy.getClassName();
116         tpvo.message = throwableProxy.getMessage();
117         tpvo.overridingMessage = throwableProxy.getOverridingMessage();
118         tpvo.commonFramesCount = throwableProxy.getCommonFrames();
119         tpvo.stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
120         tpvo.cyclic = throwableProxy.isCyclic();
121 
122         IThrowableProxy cause = throwableProxy.getCause();
123         if (cause != null) {
124             tpvo.cause = ThrowableProxyVO.build(cause);
125         }
126         IThrowableProxy[] suppressed = throwableProxy.getSuppressed();
127         if (suppressed != null) {
128             tpvo.suppressed = new IThrowableProxy[suppressed.length];
129             for (int i = 0; i < suppressed.length; i++) {
130                 tpvo.suppressed[i] = ThrowableProxyVO.build(suppressed[i]);
131             }
132         }
133 
134         return tpvo;
135     }
136 }