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
027    @Deprecated
028    ClassPackagingData classPackagingData;
029
030    public StackTraceElementProxy(StackTraceElement ste) {
031        if (ste == null) {
032            throw new IllegalArgumentException("ste cannot be null");
033        }
034        this.ste = ste;
035    }
036
037    public String getSTEAsString() {
038        if (steAsString == null) {
039            steAsString = "at " + ste.toString();
040        }
041        return steAsString;
042    }
043
044    public StackTraceElement getStackTraceElement() {
045        return ste;
046    }
047
048    public void setClassPackagingData(ClassPackagingData cpd) {
049        if (this.classPackagingData != null) {
050            throw new IllegalStateException("Packaging data has been already set");
051        }
052        this.classPackagingData = cpd;
053    }
054
055    public ClassPackagingData getClassPackagingData() {
056        return classPackagingData;
057    }
058
059    @Override
060    public int hashCode() {
061        return ste.hashCode();
062    }
063
064    @Override
065    public boolean equals(Object obj) {
066        if (this == obj)
067            return true;
068        if (obj == null)
069            return false;
070        if (getClass() != obj.getClass())
071            return false;
072        final StackTraceElementProxy other = (StackTraceElementProxy) obj;
073
074        if (!ste.equals(other.ste)) {
075            return false;
076        }
077        if (classPackagingData == null) {
078            if (other.classPackagingData != null) {
079                return false;
080            }
081        } else if (!classPackagingData.equals(other.classPackagingData)) {
082            return false;
083        }
084        return true;
085    }
086
087    @Override
088    public String toString() {
089        return getSTEAsString();
090    }
091}