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 classnameFiles
          Table of File 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.
 java.lang.String[] getClassPath()
          Returns the array of classpath directories, if any.
 java.lang.String getClassPathAsString()
          Returns the classpath as a String.
protected  java.util.List getClassPathFromVM()
          Gets the classpath from the running VM.
 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.
 java.lang.String mapClassName(java.io.File source)
          Return the fully-qualified classname corresponding to the given source file.
protected  java.lang.String mapClassNameLow(java.lang.String[] pathlist, java.lang.String fpath)
          Looks through the given path list, comparing each entry with the given fpath.
 java.io.File mapSourceFile(com.sun.jdi.ReferenceType clazz)
          Return a File corresponding to the given class.
 java.io.File mapSourceFile(java.lang.String classname)
          Return a File corresponding to the fully-qualified class name.
protected  java.io.File mapSourceFileLow(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.

classnameFiles

protected java.util.Hashtable classnameFiles
Table of File 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.

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.

getClassPathFromVM

protected java.util.List getClassPathFromVM()
Gets the classpath from the running VM. This will return the classpath of the debuggee VM if it is of type PathSearchingVirtualMachine. Otherwise, it returns the classpath of the VM running JSwat.
Returns:
List of classpath entries of type String.

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.

mapClassName

public java.lang.String mapClassName(java.io.File source)
Return the fully-qualified classname corresponding to the given source file. Returns null if file has an error.
Parameters:
source - source file containing class.
Returns:
Classname, or null if error.

mapClassNameLow

protected java.lang.String mapClassNameLow(java.lang.String[] pathlist,
                                           java.lang.String fpath)
                                    throws java.io.IOException
Looks through the given path list, comparing each entry with the given fpath. For the best matching entry, this method returns the fpath without that matching prefix.
Parameters:
pathlist - List of paths.
fpath - File path to look for.
Returns:
Name of class without the extra prefix, or null if no match. (using File.fileSeparatorChar to separate elements)
Throws:
java.io.IOException - Thrown if File.getCanonicalPath() has a problem.

mapSourceFile

public java.io.File mapSourceFile(java.lang.String classname)
                           throws java.io.IOException
Return a File corresponding to the fully-qualified class name. Return null if source file not found.
Parameters:
classname - fully-qualified class name.
Returns:
source file containing the desired location.
Throws:
java.io.IOException - Thrown if File.getCanonicalPath() has a problem.

mapSourceFile

public java.io.File mapSourceFile(com.sun.jdi.ReferenceType clazz)
                           throws java.io.IOException
Return a File corresponding to the given class. Return null if source file not found.
Parameters:
clazz - class for which to find source file.
Returns:
source file containing the desired location.
Throws:
java.io.IOException - Thrown if File.getCanonicalPath() has a problem.

mapSourceFileLow

protected java.io.File mapSourceFileLow(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 file, if found.

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.