View Javadoc
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  
27      @Deprecated
28      ClassPackagingData classPackagingData;
29  
30      public StackTraceElementProxy(StackTraceElement ste) {
31          if (ste == null) {
32              throw new IllegalArgumentException("ste cannot be null");
33          }
34          this.ste = ste;
35      }
36  
37      public String getSTEAsString() {
38          if (steAsString == null) {
39              steAsString = "at " + ste.toString();
40          }
41          return steAsString;
42      }
43  
44      public StackTraceElement getStackTraceElement() {
45          return ste;
46      }
47  
48      public void setClassPackagingData(ClassPackagingData cpd) {
49          if (this.classPackagingData != null) {
50              throw new IllegalStateException("Packaging data has been already set");
51          }
52          this.classPackagingData = cpd;
53      }
54  
55      public ClassPackagingData getClassPackagingData() {
56          return classPackagingData;
57      }
58  
59      @Override
60      public int hashCode() {
61          return ste.hashCode();
62      }
63  
64      @Override
65      public boolean equals(Object obj) {
66          if (this == obj)
67              return true;
68          if (obj == null)
69              return false;
70          if (getClass() != obj.getClass())
71              return false;
72          final StackTraceElementProxy other = (StackTraceElementProxy) obj;
73  
74          if (!ste.equals(other.ste)) {
75              return false;
76          }
77          if (classPackagingData == null) {
78              if (other.classPackagingData != null) {
79                  return false;
80              }
81          } else if (!classPackagingData.equals(other.classPackagingData)) {
82              return false;
83          }
84          return true;
85      }
86  
87      @Override
88      public String toString() {
89          return getSTEAsString();
90      }
91  }