com.bluemarsh.jswat
Class PathManager

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

public class PathManager
extends DefaultManager

Class PathManager is responsible for managing the classpath and sourcepath. It uses a given classpath and sourcepath, along with class names and package names to find source files for requested classes. If both a classpath and sourcepath are provided, the path manager will search both to find a source file, searching the sourcepath first.

Author:
Nathan Fiedler

Field Summary
protected  java.util.Hashtable classnameSources
          Table of SourceSource objects, keyed by the classname.
protected  java.lang.String[] classpathArray
          List of classpath directories where we might find source code.
protected  Session owningSession
          Session that owns us.
protected  java.lang.String[] sourcepathArray
          List of directories where we might find source code.
 
Fields inherited from class com.bluemarsh.jswat.DefaultManager
swat
 
Constructor Summary
PathManager()
          Constructs a PathManager object.
 
Method Summary
 void activate(Session session)
          Called when the Session is about to begin an active debugging session.
protected  java.lang.String classnameToFilename(java.lang.String classname)
          Turn the package name into a file path using simple character subsitution.
 java.lang.String[] getClassPath()
          Returns the array of classpath directories, if any.
 java.lang.String getClassPathAsString()
          Returns the classpath as a String.
 java.lang.String[] getSourcePath()
          Returns the array of sourcepath directories, if any.
 java.lang.String getSourcePathAsString()
          Returns the sourcepath as a String.
 void init(Session session)
          Called after the Session has instantiated this mananger.
 SourceSource mapSource(com.sun.jdi.ReferenceType clazz)
          Return a SourceSource corresponding to the given class.
 SourceSource mapSource(java.lang.String classname)
          Return a SourceSource corresponding to the fully-qualified class name.
protected  SourceSource mapSource0(java.lang.String path, java.lang.String filename, java.lang.String classname)
          Look for the file in the given class or source path entry.
protected  SourceSource mapSourceLow(java.lang.String filename, java.lang.String classname)
          Looks for a matching entry in either the class path or source path.
 void setClassPath(java.util.List list)
          Sets the classpath this source manager uses.
 void setClassPath(java.lang.String classpath)
          Sets the classpath this source manager uses.
 void setSourcePath(java.lang.String sourcepath)
          Sets the sourcepath this source manager uses.
 
Methods inherited from class com.bluemarsh.jswat.DefaultManager
close, deactivate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owningSession

protected Session owningSession
Session that owns us.

classpathArray

protected java.lang.String[] classpathArray
List of classpath directories where we might find source code.

sourcepathArray

protected java.lang.String[] sourcepathArray
List of directories where we might find source code.

classnameSources

protected java.util.Hashtable classnameSources
Table of SourceSource objects, keyed by the classname.
Constructor Detail

PathManager

public PathManager()
Constructs a PathManager object.
Method Detail

activate

public void activate(Session session)
Called when the Session is about to begin an active debugging session. That is, JSwat is about to debug a debuggee VM.
Overrides:
activate in class DefaultManager
Parameters:
session - Session being activated.

classnameToFilename

protected java.lang.String classnameToFilename(java.lang.String classname)
Turn the package name into a file path using simple character subsitution.
Parameters:
classname - fully-qualified name of the class, possibly including an inner-class specification.
Returns:
path and filename of source file.

getClassPath

public java.lang.String[] getClassPath()
Returns the array of classpath directories, if any.
Returns:
Array of Strings containing classpath directories, or null if none set.

getClassPathAsString

public java.lang.String getClassPathAsString()
Returns the classpath as a String.
Returns:
String of classpath, or null if not set.

getSourcePath

public java.lang.String[] getSourcePath()
Returns the array of sourcepath directories, if any.
Returns:
Array of Strings containing sourcepath directories, or null if none set.

getSourcePathAsString

public java.lang.String getSourcePathAsString()
Returns the sourcepath as a String.
Returns:
String of sourcepath, or null if not set.

init

public void init(Session session)
Called after the Session has instantiated this mananger. To avoid problems with circular dependencies between managers, iniitialize data members before calling Session.getManager().
Overrides:
init in class DefaultManager
Parameters:
session - Session initializing this manager.

mapSource

public SourceSource mapSource(java.lang.String classname)
                       throws java.io.IOException
Return a SourceSource corresponding to the fully-qualified class name. Return null if the source was not found.
Parameters:
classname - fully-qualified class name.
Returns:
source containing the desired location.
Throws:
java.io.IOException - Thrown if an I/O error occurred.

mapSource

public SourceSource mapSource(com.sun.jdi.ReferenceType clazz)
                       throws java.io.IOException
Return a SourceSource corresponding to the given class. Return null if the source was not found.
Parameters:
clazz - class for which to find source file.
Returns:
source containing the desired location.
Throws:
java.io.IOException - Thrown if an I/O error occurred.

mapSourceLow

protected SourceSource mapSourceLow(java.lang.String filename,
                                    java.lang.String classname)
Looks for a matching entry in either the class path or source path.
Parameters:
filename - name of file to look for.
classname - name of class for caching result.
Returns:
matching source, if found.

mapSource0

protected SourceSource mapSource0(java.lang.String path,
                                  java.lang.String filename,
                                  java.lang.String classname)
Look for the file in the given class or source path entry. This method deals with zip and jar archives, as well as the usual directory paths.
Parameters:
path - source or class path entry.
filename - name of file to look for.
classname - name of class for caching result.

setClassPath

public void setClassPath(java.lang.String classpath)
Sets the classpath this source manager uses. The previous class path is discarded in favor of the new one. The class path is used together with the source path, if any.
Parameters:
classpath - Classpath for VM.

setClassPath

public void setClassPath(java.util.List list)
Sets the classpath this source manager uses. The previous class path is discarded in favor of the new one. The class path is used together with the source path, if any.
Parameters:
list - List of String classpath entries.

setSourcePath

public void setSourcePath(java.lang.String sourcepath)
Sets the sourcepath this source manager uses. The previous source path is discarded in favor of the new one. The source path is used together with the class path, if any.
Parameters:
sourcepath - Sourcepath for VM.