Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

bsh
Class CallStack  view CallStack download CallStack.java

java.lang.Object
  extended bybsh.CallStack

public class CallStack
extends java.lang.Object

A stack of NameSpaces representing the call path. Each method invocation, for example, pushes a new NameSpace onto the stack. The top of the stack is always the current namespace of evaluation.

This is used to support the this.caller magic reference and to print script "stack traces" when evaluation errors occur.

Note: it would be awefully nice to use the java.util.Stack here. Sigh... have to stay 1.1 compatible.

Note: How can this be thread safe, you might ask? Wouldn't a thread executing various beanshell methods be mutating the callstack? Don't we need one CallStack per Thread in the interpreter? The answer is that we do. Any java.lang.Thread enters our script via an external (hard) Java reference via a This type interface, e.g. the Runnable interface implemented by This or an arbitrary interface implemented by XThis. In that case the This invokeMethod() method (called by any interface that it exposes) creates a new CallStack for each external call.


Field Summary
private  java.util.Vector stack
           
 
Constructor Summary
CallStack()
           
CallStack(NameSpace namespace)
           
 
Method Summary
 void clear()
           
 CallStack copy()
          Occasionally we need to freeze the callstack for error reporting purposes, etc.
 int depth()
           
 NameSpace get(int depth)
          zero based.
 NameSpace pop()
           
 void push(NameSpace ns)
           
 void set(int depth, NameSpace ns)
          This is kind of crazy, but used by the setNameSpace command.
 NameSpace swap(NameSpace newTop)
          Swap in the value as the new top of the stack and return the old value.
 NameSpace[] toArray()
           
 NameSpace top()
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stack

private java.util.Vector stack
Constructor Detail

CallStack

public CallStack()

CallStack

public CallStack(NameSpace namespace)
Method Detail

clear

public void clear()

push

public void push(NameSpace ns)

top

public NameSpace top()

get

public NameSpace get(int depth)
zero based.


set

public void set(int depth,
                NameSpace ns)
This is kind of crazy, but used by the setNameSpace command. zero based.


pop

public NameSpace pop()

swap

public NameSpace swap(NameSpace newTop)
Swap in the value as the new top of the stack and return the old value.


depth

public int depth()

toArray

public NameSpace[] toArray()

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


copy

public CallStack copy()
Occasionally we need to freeze the callstack for error reporting purposes, etc.