org.jboss.util
Class StackTrace

java.lang.Object
  extended byorg.jboss.util.StackTrace
All Implemented Interfaces:
java.lang.Cloneable, Printable (src) , java.io.Serializable

public final class StackTrace
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, Printable (src)

Provides access to the current stack trace by parsing the output of Throwable.printStackTrace().

See Also:
Serialized Form

Nested Class Summary
static class StackTrace.Entry (src)
          A stack trace entry.
static class StackTrace.Parser (src)
          A parser which takes a standard Throwable and produces StackTrace.Entry (src) objects.
 
Field Summary
protected  java.util.List stack
          List of StackTrace.Entry elements
static int UNLIMITED
          Parse all entries
 
Constructor Summary
  StackTrace()
          Construct a StackTrace.
  StackTrace(int level)
          Construct a StackTrace.
  StackTrace(int level, int limit)
          Construct a StackTrace.
protected StackTrace(java.util.List stack)
          Sub-trace constructor.
  StackTrace(java.lang.Throwable detail)
          Initialize a StackTrace.
  StackTrace(java.lang.Throwable detail, int level)
          Initialize a StackTrace.
  StackTrace(java.lang.Throwable detail, int level, int limit)
          Initialize a StackTrace.
 
Method Summary
static StackTrace.Entry (src) callerEntry()
          Returns a stack trace entry for the calling methods current position in the stack.
 java.lang.Object clone()
          Returns a shallow cloned copy of this object.
static StackTrace.Entry (src) currentEntry()
          Returns a stack trace entry for the current position in the stack.
 boolean equals(java.lang.Object obj)
          Check if the given object is equals to this.
 StackTrace.Entry (src) getCallerEntry()
          Returns the stack trace entry for the calling method.
 StackTrace (src) getCallerTrace()
          Returns the stack trace starting at the calling method.
 StackTrace.Entry (src) getEntry(int level)
          Returns the stack trace entry for the element at the given level.
 StackTrace.Entry (src) getRootEntry()
          Return the root entry for this stack trace.
 StackTrace (src) getSubTrace(int level)
          Returns a sub trace starting at the the given level.
 StackTrace (src) getSubTrace(int level, int limit)
          Returns a sub trace starting at the the given level.
 java.util.Iterator iterator()
          Returns an iterator over all of the entries in the stack trace.
 void print()
          Print this stack trace to System.err.
 void print(java.io.PrintStream stream)
          Print this stack trace.
 void print(java.io.PrintStream stream, java.lang.String prefix)
          Print this stack trace.
 void print(java.io.PrintWriter writer)
          Print this stack trace.
 void print(java.io.PrintWriter writer, java.lang.String prefix)
          Print this stack trace.
 void print(java.lang.String prefix)
          Print this stack trace to System.err.
static StackTrace.Entry (src) rootEntry()
          Returns a stack trace entry for the root calling method of the current execution thread.
 int size()
          Returns the number of entries (or size) of the stack trace.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNLIMITED

public static final int UNLIMITED
Parse all entries

See Also:
Constant Field Values (src)

stack

protected final java.util.List stack
List of StackTrace.Entry elements

Constructor Detail

StackTrace

public StackTrace(java.lang.Throwable detail,
                  int level,
                  int limit)
Initialize a StackTrace.

Parameters:
detail - Detail throwable to determine stack entries from.
level - Number of levels to go down into the trace.
limit - The maximum number of entries to parse (does not include skipped levels or the description). A value <= zero results in all entries being parsed.
Throws:
java.lang.IllegalArgumentException - Invalid level or limit.
NestedRuntimeException (src) - Failed to create Parser.
NestedRuntimeException (src) - Failed to parse stack trace.

StackTrace

public StackTrace(java.lang.Throwable detail,
                  int level)
Initialize a StackTrace.

Parameters:
detail - Detail throwable to determine stack entries from.
level - Number of levels to go down into the trace.
Throws:
java.lang.IllegalArgumentException - Invalid level.
NestedRuntimeException (src) - Failed to create Parser.
NestedRuntimeException (src) - Failed to parse stack trace.

StackTrace

public StackTrace(java.lang.Throwable detail)
Initialize a StackTrace.

Parameters:
detail - Detail throwable to determine stack entries from.
Throws:
NestedRuntimeException (src) - Failed to create Parser.
NestedRuntimeException (src) - Failed to parse stack trace.

StackTrace

public StackTrace(int level,
                  int limit)
Construct a StackTrace.

Parameters:
level - Number of levels to go down into the trace.
limit - The maximum number of entries to parse (does not include skipped levels or the description). A value <= zero results in all entries being parsed.

StackTrace

public StackTrace(int level)
Construct a StackTrace.

Parameters:
level - Number of levels to go down into the trace.

StackTrace

public StackTrace()
Construct a StackTrace.


StackTrace

protected StackTrace(java.util.List stack)
Sub-trace constructor.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Check if the given object is equals to this.

Parameters:
obj - Object to test equality with.
Returns:
True if object is equal to this.

clone

public java.lang.Object clone()
Returns a shallow cloned copy of this object.

Returns:
A shallow cloned copy of this object.

getEntry

public StackTrace.Entry (src)  getEntry(int level)
Returns the stack trace entry for the element at the given level.

Parameters:
level - Number of levels.
Returns:
Stack trace entry.
Throws:
java.lang.IndexOutOfBoundsException - Invalid level index.

getCallerEntry

public StackTrace.Entry (src)  getCallerEntry()
Returns the stack trace entry for the calling method.

Returns:
Stack trace entry for calling method.

getRootEntry

public StackTrace.Entry (src)  getRootEntry()
Return the root entry for this stack trace.

Returns:
Stack trace entry for the root calling method.

getSubTrace

public StackTrace (src)  getSubTrace(int level)
Returns a sub trace starting at the the given level.

Parameters:
level - Number of levels.
Returns:
Sub-trace.

getSubTrace

public StackTrace (src)  getSubTrace(int level,
                              int limit)
Returns a sub trace starting at the the given level.

Parameters:
level - Number of levels.
limit - Limit the sub-trace. If there are less entries than the limit, the limit has no effect.
Returns:
Sub-trace.

getCallerTrace

public StackTrace (src)  getCallerTrace()
Returns the stack trace starting at the calling method.

Returns:
Stack trace for calling method.

print

public void print(java.io.PrintWriter writer,
                  java.lang.String prefix)
Print this stack trace.

Specified by:
print in interface Printable (src)
Parameters:
writer - The writer to print to.
prefix - Stack trace entry prefix.

print

public void print(java.io.PrintWriter writer)
Print this stack trace.

Specified by:
print in interface Printable (src)
Parameters:
writer - The writer to print to.

print

public void print(java.io.PrintStream stream,
                  java.lang.String prefix)
Print this stack trace.

Specified by:
print in interface Printable (src)
Parameters:
stream - The stream to print to.
prefix - Stack trace entry prefix.

print

public void print(java.io.PrintStream stream)
Print this stack trace.

Specified by:
print in interface Printable (src)
Parameters:
stream - The stream to print to.

print

public void print(java.lang.String prefix)
Print this stack trace to System.err.

Parameters:
prefix - Stack trace entry prefix.

print

public void print()
Print this stack trace to System.err.


iterator

public java.util.Iterator iterator()
Returns an iterator over all of the entries in the stack trace.

Returns:
An iterator over all of the entries in the stack trace.

size

public int size()
Returns the number of entries (or size) of the stack trace.

Returns:
The number of entries (or size) of the stack trace.

currentEntry

public static final StackTrace.Entry (src)  currentEntry()
Returns a stack trace entry for the current position in the stack.

The current entry refers to the method that has invoked currentEntry().

Returns:
Current position in the stack.

callerEntry

public static final StackTrace.Entry (src)  callerEntry()
Returns a stack trace entry for the calling methods current position in the stack.

Calling method in this case refers to the method that has called the method which invoked callerEntry().

Returns:
Calling methods current position in the stack.
Throws:
java.lang.IndexOutOfBoundsException - The current entry is at bottom of the stack.

rootEntry

public static final StackTrace.Entry (src)  rootEntry()
Returns a stack trace entry for the root calling method of the current execution thread.

Returns:
Stack trace entry for the root calling method.