View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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    
36    public String getSTEAsString() {
37      if (steAsString == null) {
38        steAsString = "at " + ste.toString();
39      }
40      return steAsString;
41    }
42    
43    public StackTraceElement getStackTraceElement() {
44      return ste;
45    }
46    
47    public void setClassPackagingData(ClassPackagingData cpd) {
48      if(this.cpd != null) {
49        throw new IllegalStateException("Packaging data has been already set");
50      }
51      this.cpd = cpd;
52    }
53  
54    public ClassPackagingData getClassPackagingData() {
55      return cpd;
56    }
57  
58    @Override
59    public int hashCode() {
60      return ste.hashCode();
61    }
62  
63    @Override
64    public boolean equals(Object obj) {
65      if (this == obj)
66        return true;
67      if (obj == null)
68        return false;
69      if (getClass() != obj.getClass())
70        return false;
71      final StackTraceElementProxy other = (StackTraceElementProxy) obj;
72  
73      if (!ste.equals(other.ste)) {
74        return false;
75      }
76      if (cpd == null) {
77        if (other.cpd != null) {
78          return false;
79        }
80      } else if (!cpd.equals(other.cpd)) {
81        return false;
82      }
83      return true;
84    }
85  
86    @Override
87    public String toString() {
88      return getSTEAsString();
89    }
90  }