001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.spi; 015 016import java.io.Serializable; 017import java.util.Arrays; 018 019public class ThrowableProxyVO implements IThrowableProxy, Serializable { 020 021 private static final long serialVersionUID = -773438177285807139L; 022 023 private String className; 024 private String message; 025 private int commonFramesCount; 026 private StackTraceElementProxy[] stackTraceElementProxyArray; 027 private IThrowableProxy cause; 028 private IThrowableProxy[] suppressed; 029 private boolean cyclic; 030 031 public String getMessage() { 032 return message; 033 } 034 035 public String getClassName() { 036 return className; 037 } 038 039 public int getCommonFrames() { 040 return commonFramesCount; 041 } 042 043 public IThrowableProxy getCause() { 044 return cause; 045 } 046 047 public StackTraceElementProxy[] getStackTraceElementProxyArray() { 048 return stackTraceElementProxyArray; 049 } 050 051 public IThrowableProxy[] getSuppressed() { 052 return suppressed; 053 } 054 055 public boolean isCyclic() { 056 return cyclic; 057 } 058 059 @Override 060 public int hashCode() { 061 final int prime = 31; 062 int result = 1; 063 result = prime * result + ((className == null) ? 0 : className.hashCode()); 064 return result; 065 } 066 067 @Override 068 public boolean equals(Object obj) { 069 if (this == obj) 070 return true; 071 if (obj == null) 072 return false; 073 if (getClass() != obj.getClass()) 074 return false; 075 final ThrowableProxyVO other = (ThrowableProxyVO) obj; 076 077 if (className == null) { 078 if (other.className != null) 079 return false; 080 } else if (!className.equals(other.className)) 081 return false; 082 083 if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray)) 084 return false; 085 086 if (!Arrays.equals(suppressed, other.suppressed)) 087 return false; 088 089 if (cause == null) { 090 if (other.cause != null) 091 return false; 092 } else if (!cause.equals(other.cause)) 093 return false; 094 095 return true; 096 } 097 098 public static ThrowableProxyVO build(IThrowableProxy throwableProxy) { 099 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}