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 overridingMessage; 025 private String message; 026 private int commonFramesCount; 027 private StackTraceElementProxy[] stackTraceElementProxyArray; 028 private IThrowableProxy cause; 029 private IThrowableProxy[] suppressed; 030 private boolean cyclic; 031 032 public String getMessage() { 033 return message; 034 } 035 /** 036 * Return the overriding message if any. This method returns null 037 * if there is no overriding message. 038 * 039 * <p>Overriding message exists only if the original throwable implementation overrides the toString() method.</p> 040 * 041 * @return the overriding message or null 042 * @since 1.5.22 043 */ 044 @Override 045 public String getOverridingMessage() { return overridingMessage;} 046 047 public String getClassName() { 048 return className; 049 } 050 051 public int getCommonFrames() { 052 return commonFramesCount; 053 } 054 055 public IThrowableProxy getCause() { 056 return cause; 057 } 058 059 public StackTraceElementProxy[] getStackTraceElementProxyArray() { 060 return stackTraceElementProxyArray; 061 } 062 063 public IThrowableProxy[] getSuppressed() { 064 return suppressed; 065 } 066 067 public boolean isCyclic() { 068 return cyclic; 069 } 070 071 @Override 072 public int hashCode() { 073 final int prime = 31; 074 int result = 1; 075 result = prime * result + ((className == null) ? 0 : className.hashCode()); 076 return result; 077 } 078 079 @Override 080 public boolean equals(Object obj) { 081 if (this == obj) 082 return true; 083 if (obj == null) 084 return false; 085 if (getClass() != obj.getClass()) 086 return false; 087 final ThrowableProxyVO other = (ThrowableProxyVO) obj; 088 089 if (className == null) { 090 if (other.className != null) 091 return false; 092 } else if (!className.equals(other.className)) 093 return false; 094 095 if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray)) 096 return false; 097 098 if (!Arrays.equals(suppressed, other.suppressed)) 099 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}