com.bluemarsh.jswat
Class ContextManager

java.lang.Object
  |
  +--com.bluemarsh.jswat.DefaultManager
        |
        +--com.bluemarsh.jswat.ContextManager
All Implemented Interfaces:
Manager, SessionListener

public class ContextManager
extends DefaultManager

Class ContextManager is responsible for holding the current context of the debugger. It holds a reference to the current thread, the current source line (if stepping), the current frame in the thread stack, etc.

Author:
Nathan Fiedler

Field Summary
protected  int currentFrame
          Zero-based index of the current stack frame.
protected  com.sun.jdi.Location currentLocation
          Location that we're currently stepping through.
protected  com.sun.jdi.ThreadReference currentThread
          Reference to the current thread.
protected  int latestFrameCount
          Count of the stack frames from the current thread.
protected  com.bluemarsh.util.EventListenerList listeners
          List of context listeners.
 
Fields inherited from class com.bluemarsh.jswat.DefaultManager
swat
 
Constructor Summary
ContextManager()
          Constructs a new ContextManager object.
 
Method Summary
 void addContextListener(ContextListener listener)
          Add a context listener to this manager object.
 void deactivate(Session session)
          Called when the Session is about to end an active debugging session.
protected  void fireChange(com.sun.jdi.ThreadReference oldThrd, com.sun.jdi.Location oldLoc, int oldFrame)
          Let all the change listeners know of a recent change in the context.
 int getCurrentFrame()
          Returns the current thread's frame index.
 com.sun.jdi.Location getCurrentLocation()
          Get the location that the debugger is presently stepping through.
 com.sun.jdi.StackFrame getCurrentStackFrame()
          Returns the current thread's stack frame.
 com.sun.jdi.ThreadReference getCurrentThread()
          Returns the ThreadReference to the current thread object.
protected  com.sun.jdi.Location getLocationFromFrame(int frame)
          Uses the current thread and the given stack frame index to get the Location.
 void removeContextListener(ContextListener listener)
          Remove a context listener from the listener list.
 void setCurrentFrame(int frame)
          Sets the current thread's stack frame.
 void setCurrentLocation(com.sun.jdi.event.LocatableEvent le)
          Set the location and thread that the debugger is presently examining.
 void setCurrentThread(com.sun.jdi.ThreadReference thread)
          Sets the current thread to the one given.
 
Methods inherited from class com.bluemarsh.jswat.DefaultManager
activate, close, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentThread

protected com.sun.jdi.ThreadReference currentThread
Reference to the current thread.

currentFrame

protected int currentFrame
Zero-based index of the current stack frame.

currentLocation

protected com.sun.jdi.Location currentLocation
Location that we're currently stepping through.

listeners

protected com.bluemarsh.util.EventListenerList listeners
List of context listeners.

latestFrameCount

protected int latestFrameCount
Count of the stack frames from the current thread.
Constructor Detail

ContextManager

public ContextManager()
Constructs a new ContextManager object.
Method Detail

addContextListener

public void addContextListener(ContextListener listener)
Add a context listener to this manager object.
Parameters:
listener - new listener to add notification list

deactivate

public void deactivate(Session session)
Called when the Session is about to end an active debugging session. That is, JSwat is about to terminate the connection with the debuggee VM.
Overrides:
deactivate in class DefaultManager
Parameters:
session - Session being deactivated.

fireChange

protected void fireChange(com.sun.jdi.ThreadReference oldThrd,
                          com.sun.jdi.Location oldLoc,
                          int oldFrame)
Let all the change listeners know of a recent change in the context. This creates a ContextChangeEvent object and sends it out to the listeners.
Parameters:
oldThrd - previous value for current thread
oldLoc - previous value for current location
oldFrame - previous value for current frame

getCurrentFrame

public int getCurrentFrame()
Returns the current thread's frame index. The returned value is guaranteed to be a valid stack frame index.
Returns:
Current thread's frame index.

getCurrentLocation

public com.sun.jdi.Location getCurrentLocation()
Get the location that the debugger is presently stepping through.
Returns:
Current location of debugger.

getCurrentStackFrame

public com.sun.jdi.StackFrame getCurrentStackFrame()
                                            throws com.sun.jdi.IncompatibleThreadStateException,
                                                   java.lang.IndexOutOfBoundsException,
                                                   com.sun.jdi.ObjectCollectedException
Returns the current thread's stack frame.
Returns:
Current thread's stack frame, or null if no current thread.
Throws:
com.sun.jdi.IncompatibleThreadStateException - Thrown if current thread is not suspended.
java.lang.IndexOutOfBoundsException - Thrown if current frame is < 0 or >= frame count.
com.sun.jdi.ObjectCollectedException - Thrown if this object has been collected.

getCurrentThread

public com.sun.jdi.ThreadReference getCurrentThread()
Returns the ThreadReference to the current thread object.
Returns:
Current thread reference.

getLocationFromFrame

protected com.sun.jdi.Location getLocationFromFrame(int frame)
Uses the current thread and the given stack frame index to get the Location.
Parameters:
frame - Frame index into current thread's stack.
Returns:
Location at that stack frame, or null if error.

removeContextListener

public void removeContextListener(ContextListener listener)
Remove a context listener from the listener list.
Parameters:
listener - listener to remove from notification list

setCurrentFrame

public void setCurrentFrame(int frame)
                     throws com.sun.jdi.IncompatibleThreadStateException,
                            java.lang.IndexOutOfBoundsException
Sets the current thread's stack frame. The thread must be suspended before calling this method.
Parameters:
frame - New current stack frame. Must be between zero and the number of stack frames minus one, inclusive.
Throws:
com.sun.jdi.IncompatibleThreadStateException - Thrown if current thread is not suspended.
java.lang.IndexOutOfBoundsException - Thrown if frame is < 0 or >= frame count.
java.lang.IllegalStateException - Thrown if current thread is not set.

setCurrentLocation

public void setCurrentLocation(com.sun.jdi.event.LocatableEvent le)
Set the location and thread that the debugger is presently examining. If null is passed, the location and thread are reset to null. The current frame is always reset to zero.
Parameters:
loc - Current location of debugger, or null to reset.

setCurrentThread

public void setCurrentThread(com.sun.jdi.ThreadReference thread)
Sets the current thread to the one given. Resets the current frame to zero (top stack frame).
Parameters:
thread - New current thread.