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; 017 018public class StackTraceElementProxy implements Serializable { 019 020 private static final long serialVersionUID = -2374374378980555982L; 021 022 final StackTraceElement ste; 023 // save a byte or two during serialization, as we can 024 // reconstruct this field from 'ste' 025 transient private String steAsString; 026 private ClassPackagingData cpd; 027 028 public StackTraceElementProxy(StackTraceElement ste) { 029 if (ste == null) { 030 throw new IllegalArgumentException("ste cannot be null"); 031 } 032 this.ste = ste; 033 } 034 035 public String getSTEAsString() { 036 if (steAsString == null) { 037 steAsString = "at " + ste.toString(); 038 } 039 return steAsString; 040 } 041 042 public StackTraceElement getStackTraceElement() { 043 return ste; 044 } 045 046 public void setClassPackagingData(ClassPackagingData cpd) { 047 if (this.cpd != null) { 048 throw new IllegalStateException("Packaging data has been already set"); 049 } 050 this.cpd = cpd; 051 } 052 053 public ClassPackagingData getClassPackagingData() { 054 return cpd; 055 } 056 057 @Override 058 public int hashCode() { 059 return ste.hashCode(); 060 } 061 062 @Override 063 public boolean equals(Object obj) { 064 if (this == obj) 065 return true; 066 if (obj == null) 067 return false; 068 if (getClass() != obj.getClass()) 069 return false; 070 final StackTraceElementProxy other = (StackTraceElementProxy) obj; 071 072 if (!ste.equals(other.ste)) { 073 return false; 074 } 075 if (cpd == null) { 076 if (other.cpd != null) { 077 return false; 078 } 079 } else if (!cpd.equals(other.cpd)) { 080 return false; 081 } 082 return true; 083 } 084 085 @Override 086 public String toString() { 087 return getSTEAsString(); 088 } 089}