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, Marko van Dooren

Field Summary
protected  java.util.Hashtable classnameSources
          Table of SourceSource objects, keyed by the classname.
protected  Session owningSession
          Session that owns us.
 
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 mapClass(com.sun.jdi.ReferenceType clazz)
          Searches for the .class file of the given class and returns a SourceSource representing that .class file.
 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)
          Look for the file in the given class or sourcepath entry.
protected  SourceSource mapSourceLow(java.lang.String filename, java.lang.String classname)
          Looks for a matching entry in either the classpath or sourcepath.
 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.

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; may be empty.

getClassPathAsString

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

getSourcePath

public java.lang.String[] getSourcePath()
Returns the array of sourcepath directories, if any.
Returns:
Array of Strings containing sourcepath directories; may be empty.

getSourcePathAsString

public java.lang.String getSourcePathAsString()
Returns the sourcepath as a String.
Returns:
String of sourcepath, or empty string 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.

mapClass

public SourceSource mapClass(com.sun.jdi.ReferenceType clazz)
Searches for the .class file of the given class and returns a SourceSource representing that .class file.
Parameters:
clazz - class for which to find class file.
Returns:
object representing the desired class file, or null if class file not found.

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 classpath or sourcepath.
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)
Look for the file in the given class or sourcepath entry. This method deals with zip and jar archives, as well as the usual directory paths.
Parameters:
path - source or classpath entry.
filename - name of file to look for.

setClassPath

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

setClassPath

public void setClassPath(java.util.List list)
Sets the classpath this source manager uses. The previous classpath is discarded in favor of the new one. The class path is used together with the sourcepath, 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 sourcepath is discarded in favor of the new one. The source path is used together with the classpath, if any.
Parameters:
sourcepath - Sourcepath for VM.