View Javadoc
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 message;
25      private int commonFramesCount;
26      private StackTraceElementProxy[] stackTraceElementProxyArray;
27      private IThrowableProxy cause;
28      private IThrowableProxy[] suppressed;
29  
30      public String getMessage() {
31          return message;
32      }
33  
34      public String getClassName() {
35          return className;
36      }
37  
38      public int getCommonFrames() {
39          return commonFramesCount;
40      }
41  
42      public IThrowableProxy getCause() {
43          return cause;
44      }
45  
46      public StackTraceElementProxy[] getStackTraceElementProxyArray() {
47          return stackTraceElementProxyArray;
48      }
49  
50      public IThrowableProxy[] getSuppressed() {
51          return suppressed;
52      }
53  
54      @Override
55      public int hashCode() {
56          final int prime = 31;
57          int result = 1;
58          result = prime * result + ((className == null) ? 0 : className.hashCode());
59          return result;
60      }
61  
62      @Override
63      public boolean equals(Object obj) {
64          if (this == obj)
65              return true;
66          if (obj == null)
67              return false;
68          if (getClass() != obj.getClass())
69              return false;
70          final ThrowableProxyVO other = (ThrowableProxyVO) obj;
71  
72          if (className == null) {
73              if (other.className != null)
74                  return false;
75          } else if (!className.equals(other.className))
76              return false;
77  
78          if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray))
79              return false;
80  
81          if (!Arrays.equals(suppressed, other.suppressed))
82              return false;
83  
84          if (cause == null) {
85              if (other.cause != null)
86                  return false;
87          } else if (!cause.equals(other.cause))
88              return false;
89  
90          return true;
91      }
92  
93      public static ThrowableProxyVO build(IThrowableProxy throwableProxy) {
94          if (throwableProxy == null) {
95              return null;
96          }
97          ThrowableProxyVO tpvo = new ThrowableProxyVO();
98          tpvo.className = throwableProxy.getClassName();
99          tpvo.message = throwableProxy.getMessage();
100         tpvo.commonFramesCount = throwableProxy.getCommonFrames();
101         tpvo.stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
102         IThrowableProxy cause = throwableProxy.getCause();
103         if (cause != null) {
104             tpvo.cause = ThrowableProxyVO.build(cause);
105         }
106         IThrowableProxy[] suppressed = throwableProxy.getSuppressed();
107         if (suppressed != null) {
108             tpvo.suppressed = new IThrowableProxy[suppressed.length];
109             for (int i = 0; i < suppressed.length; i++) {
110                 tpvo.suppressed[i] = ThrowableProxyVO.build(suppressed[i]);
111             }
112         }
113         return tpvo;
114     }
115 }