View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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 = 685387990886325422L;
22    
23    private String className;
24    private String message;
25    private int commonFramesCount;
26    private StackTraceElementProxy[] stackTraceElementProxyArray;
27    private IThrowableProxy cause;
28  
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    @Override
51    public int hashCode() {
52      final int prime = 31;
53      int result = 1;
54      result = prime * result
55          + ((className == null) ? 0 : className.hashCode());
56      return result;
57    }
58  
59    @Override
60    public boolean equals(Object obj) {
61      if (this == obj)
62        return true;
63      if (obj == null)
64        return false;
65      if (getClass() != obj.getClass())
66        return false;
67      final ThrowableProxyVO other = (ThrowableProxyVO) obj;
68  
69      if (className == null) {
70        if (other.className != null)
71          return false;
72      } else if (!className.equals(other.className))
73        return false;
74  
75      if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray))
76        return false;
77      
78      if (cause == null) {
79        if (other.cause != null)
80          return false;
81      } else if (!cause.equals(other.cause))
82        return false;
83      
84      return true;
85    }
86  
87    public static ThrowableProxyVO build(IThrowableProxy throwableProxy) {
88      if(throwableProxy == null) {
89        return null;
90      }
91      ThrowableProxyVO tpvo = new ThrowableProxyVO();
92      tpvo.className = throwableProxy.getClassName();
93      tpvo.message = throwableProxy.getMessage();
94      tpvo.commonFramesCount = throwableProxy.getCommonFrames();
95      tpvo.stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
96      if(throwableProxy.getCause() != null) {
97        tpvo.cause = ThrowableProxyVO.build(throwableProxy.getCause());
98      }
99      return tpvo;
100   }
101 }