KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > diagnostics > StackTrace


1 package com.sun.enterprise.util.diagnostics;
2
3 import java.io.*;
4 import java.util.*;
5 /*
6  * The contents of this file are subject to the terms
7  * of the Common Development and Distribution License
8  * (the License). You may not use this file except in
9  * compliance with the License.
10  *
11  * You can obtain a copy of the license at
12  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
13  * glassfish/bootstrap/legal/CDDLv1.0.txt.
14  * See the License for the specific language governing
15  * permissions and limitations under the License.
16  *
17  * When distributing Covered Code, include this CDDL
18  * Header Notice in each file and include the License file
19  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
20  * If applicable, add the following below the CDDL Header,
21  * with the fields enclosed by brackets [] replaced by
22  * you own identifying information:
23  * "Portions Copyrighted [year] [name of copyright owner]"
24  *
25  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26  */

27
28 /**
29  * The class <code>StackTrace</code> is a simple class -- its toString() method generates a stack trace
30  * @author Byron Nevins
31  * @see com.elf.diagnostics.Reporter
32  * @since iAB 6.0
33  */

34
35 public class StackTrace
36 {
37     /** Creates a new StackTrace object, which is based at the execution location.
38      *
39      * This is useful for finding out who called a function.
40      */

41     public StackTrace()
42     {
43         throwable = new Throwable JavaDoc();
44     }
45
46         /** create a stackTrace object for the given Throwable
47          * @param t The Throwable that you are interested in.
48          */

49     public StackTrace(Throwable JavaDoc t)
50     {
51         throwable = t;
52     }
53
54         /** Used by the Reporter class
55          * @return The text of a stack trace.
56          * @see Reporter
57          */

58     public String JavaDoc toString()
59     {
60         ByteArrayOutputStream baos = new ByteArrayOutputStream();
61         PrintWriter pw = new PrintWriter(baos);
62
63         // create the stack trace
64
throwable.printStackTrace(pw);
65         pw.flush();
66         return baos.toString();
67     }
68     
69         /** This really should be private. Do not use this.
70          */

71     Throwable JavaDoc throwable = null;
72 }
73
74
Popular Tags