home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / ccs_util.jar / com / commerceone / util / debug / StackTrace.class (.txt) < prev   
Encoding:
Java Class File  |  1999-12-09  |  3.7 KB  |  131 lines

  1. package com.commerceone.util.debug;
  2.  
  3. import com.commerceone.util.contract.Contract;
  4. import java.io.PrintWriter;
  5. import java.io.StringWriter;
  6. import java.util.StringTokenizer;
  7.  
  8. public class StackTrace {
  9.    private int stackLevels;
  10.    private int skipDepth;
  11.    private int savedLines;
  12.    // $FF: renamed from: sw java.io.StringWriter
  13.    private StringWriter field_0;
  14.    private StringTokenizer strTok;
  15.    // $FF: renamed from: t java.lang.Throwable
  16.    private Throwable field_1;
  17.    private String fileName;
  18.    private String myName;
  19.    private String tmpStr;
  20.    private String className;
  21.    private String kitchenSink;
  22.    private String methodName;
  23.    private String fullClassName;
  24.    private StringBuffer stackTrace;
  25.    private int lineNum;
  26.  
  27.    public String getClassName() {
  28.       return this.className;
  29.    }
  30.  
  31.    public String getMethodName() {
  32.       return this.methodName;
  33.    }
  34.  
  35.    public int getLineNum() {
  36.       return this.lineNum;
  37.    }
  38.  
  39.    public String toString() {
  40.       return this.stackTrace.toString();
  41.    }
  42.  
  43.    public StackTrace() {
  44.       this(1, 0);
  45.    }
  46.  
  47.    public StackTrace(int stackLevels) {
  48.       this(stackLevels, 0);
  49.    }
  50.  
  51.    public StackTrace(int stackLevels, int skipDepth) {
  52.       this.stackLevels = 1;
  53.       this.skipDepth = 0;
  54.       this.savedLines = 0;
  55.       this.field_0 = null;
  56.       this.strTok = null;
  57.       this.field_1 = null;
  58.       this.fileName = null;
  59.       this.myName = this.getClass().getName();
  60.       this.tmpStr = null;
  61.       this.className = null;
  62.       this.kitchenSink = null;
  63.       this.methodName = null;
  64.       this.fullClassName = null;
  65.       this.stackTrace = null;
  66.       this.lineNum = -1;
  67.       Contract.require(stackLevels > 0);
  68.       Contract.require(skipDepth >= 0);
  69.       this.stackLevels = stackLevels;
  70.       this.skipDepth = skipDepth;
  71.       this.field_0 = new StringWriter();
  72.       this.field_1 = new Throwable();
  73.       this.field_1.printStackTrace(new PrintWriter(this.field_0));
  74.       this.stackTrace = new StringBuffer();
  75.       this.strTok = new StringTokenizer(this.field_0.toString(), "\n\r");
  76.  
  77.       try {
  78.          if (this.strTok.hasMoreTokens()) {
  79.             this.strTok.nextToken();
  80.          }
  81.  
  82.          while(this.strTok.hasMoreTokens()) {
  83.             this.tmpStr = this.strTok.nextToken().replace('/', '.');
  84.             if (this.tmpStr.indexOf(this.myName, 0) == -1) {
  85.                if (skipDepth <= 0) {
  86.                   break;
  87.                }
  88.  
  89.                --skipDepth;
  90.             }
  91.          }
  92.  
  93.          while(this.savedLines < stackLevels) {
  94.             this.stackTrace.append(this.tmpStr.trim());
  95.             this.stackTrace.append("\n");
  96.             ++this.savedLines;
  97.             if (!this.strTok.hasMoreTokens()) {
  98.                break;
  99.             }
  100.  
  101.             this.tmpStr = this.strTok.nextToken();
  102.          }
  103.  
  104.          this.strTok = new StringTokenizer(this.stackTrace.toString(), " ():");
  105.          this.strTok.nextToken();
  106.          this.kitchenSink = this.strTok.nextToken();
  107.          this.fileName = this.strTok.nextToken();
  108.          this.tmpStr = this.strTok.nextToken();
  109.          this.lineNum = Integer.parseInt(this.tmpStr);
  110.          this.className = this.fileName.substring(0, this.fileName.indexOf(".java")) + ".class";
  111.          this.methodName = this.kitchenSink.substring(this.kitchenSink.lastIndexOf(".") + 1);
  112.          this.fullClassName = this.kitchenSink.substring(0, this.kitchenSink.lastIndexOf(".")) + ".class";
  113.       } catch (Exception e) {
  114.          System.err.println("Exception: " + ((Throwable)e).getMessage());
  115.       }
  116.  
  117.    }
  118.  
  119.    public String getFullClassName() {
  120.       return this.fullClassName;
  121.    }
  122.  
  123.    public String getFileAndLineNum() {
  124.       return this.fileName + ":" + this.lineNum;
  125.    }
  126.  
  127.    public String getFileName() {
  128.       return this.fileName;
  129.    }
  130. }
  131.