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