1 /**
2  * Logback: the reliable, generic, fast and flexible logging framework.
3  * Copyright (C) 1999-2015, 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
18 public class StackTraceElementProxy implements Serializable {
19
20     private static final long serialVersionUID = -2374374378980555982L;
21
22     final StackTraceElement ste;
23     // save a byte or two during serialization, as we can
24     // reconstruct this field from 'ste'
25     transient private String steAsString;
26     private ClassPackagingData cpd;
27
28     public StackTraceElementProxy(StackTraceElement ste) {
29         if (ste == null) {
30             throw new IllegalArgumentException("ste cannot be null");
31         }
32         this.ste = ste;
33     }
34
35     public String getSTEAsString() {
36         if (steAsString == null) {
37             steAsString = "at " + ste.toString();
38         }
39         return steAsString;
40     }
41
42     public StackTraceElement getStackTraceElement() {
43         return ste;
44     }
45
46     public void setClassPackagingData(ClassPackagingData cpd) {
47         if (this.cpd != null) {
48             throw new IllegalStateException("Packaging data has been already set");
49         }
50         this.cpd = cpd;
51     }
52
53     public ClassPackagingData getClassPackagingData() {
54         return cpd;
55     }
56
57     @Override
58     public int hashCode() {
59         return ste.hashCode();
60     }
61
62     @Override
63     public boolean equals(Object obj) {
64         if (this == obj)
65             return true;
66         if (obj == null)
67             return false;
68         if (getClass() != obj.getClass())
69             return false;
70         final StackTraceElementProxy other = (StackTraceElementProxy) obj;
71
72         if (!ste.equals(other.ste)) {
73             return false;
74         }
75         if (cpd == null) {
76             if (other.cpd != null) {
77                 return false;
78             }
79         } else if (!cpd.equals(other.cpd)) {
80             return false;
81         }
82         return true;
83     }
84
85     @Override
86     public String toString() {
87         return getSTEAsString();
88     }
89 }
90