com.taursys.tools.util
Class ClassPath

java.lang.Object
  extended bycom.taursys.tools.util.ClassPath

public class ClassPath
extends java.lang.Object

ClassPath represents a classpath for an application. It consists of a set of Strings that contain the path to classes and resources needed by the application. The classpath can contain directory references where classes can be found and jar(or zip) file names which contain classes.

This class provides a number of utility methods for classpath related activities.

Version:
1.0
Author:
Marty Phelan

Nested Class Summary
protected  class ClassPath.ClassFilter
          FileFilter for classes only (excluding inner classes)
protected  class ClassPath.PackageFilter
          FileFilter for packages only - no files
 
Constructor Summary
ClassPath()
          Constructs a new empty ClassPath
ClassPath(java.lang.String classPath)
          Constructs a new ClassPath based on the given String representation.
 
Method Summary
protected  void addMissingEntries()
          Add missing entries to entries TreeSet.
 void addPath(java.lang.String path)
          Add a path to this classpath.
 java.lang.String getClassPathString()
          Get the String representation of this classpath.
 javax.swing.tree.DefaultMutableTreeNode getClassTree()
          Get a Tree consisting of all classes based on this ClassPath.
 java.util.TreeSet getEntries()
          Get the internal set of entries -- for testing purposes only.
protected  void getEntriesInPath()
           
 javax.swing.tree.DefaultMutableTreeNode getPackageTree()
          Get a Tree consisting of all packages based on this ClassPath.
 java.util.ArrayList getPaths()
          Get a copy of the paths for this ClassPath.
 javax.swing.tree.DefaultMutableTreeNode getTree(java.io.FileFilter filter, boolean removeFileType)
          Get a Tree consisting of all files matching given filter.
protected  java.lang.String getTreePath(javax.swing.tree.DefaultMutableTreeNode node)
          Get the String representation of given path
 void removePath(java.lang.String path)
          Remove a path from this classpath.
protected  void resetEntries()
          Reset the cached entries and trees, forcing a rebuild from the current paths.
 void resetPaths()
          Reset the collection of paths to empty.
 void setClassPathString(java.lang.String classPath)
          Set this ClassPath from the given String representation.
protected  void setInternalEntries(java.util.TreeSet entries)
          Set the internal entries TreeSet for testing purposes only.
 void setPaths(java.util.ArrayList newPaths)
          Set the internal ArrayList of paths for this ClassPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassPath

public ClassPath()
Constructs a new empty ClassPath


ClassPath

public ClassPath(java.lang.String classPath)
Constructs a new ClassPath based on the given String representation.

Method Detail

setClassPathString

public void setClassPathString(java.lang.String classPath)
Set this ClassPath from the given String representation. The given String classPath will be broken into individual paths. They must be separated by a semicolon.

Parameters:
classPath - is a set of paths separated by semicolons.

getClassPathString

public java.lang.String getClassPathString()
Get the String representation of this classpath. The classpath will consist of all the individiual paths concatenated and separated by semicolons.

Returns:
the String representation of this classpath.

addPath

public void addPath(java.lang.String path)
Add a path to this classpath. If the given path already exists in this classpath, no action will be taken.

Parameters:
path - to add to this classpath.

removePath

public void removePath(java.lang.String path)
Remove a path from this classpath. If the given path is not found in this classpath, no action will be taken.

Parameters:
path - to remove from this classpath.

setPaths

public void setPaths(java.util.ArrayList newPaths)
Set the internal ArrayList of paths for this ClassPath.

Parameters:
newPaths - the internal ArrayList of paths for this ClassPath.

getPaths

public java.util.ArrayList getPaths()
Get a copy of the paths for this ClassPath.

Returns:
a copy of the paths for this ClassPath.

getClassTree

public javax.swing.tree.DefaultMutableTreeNode getClassTree()
Get a Tree consisting of all classes based on this ClassPath.


getPackageTree

public javax.swing.tree.DefaultMutableTreeNode getPackageTree()
Get a Tree consisting of all packages based on this ClassPath.


getEntries

public java.util.TreeSet getEntries()
Get the internal set of entries -- for testing purposes only. This is a sorted unique set of all entries obtained from resources in the paths.

Returns:
a TreeSet of internal entries

resetPaths

public void resetPaths()
Reset the collection of paths to empty. Also resets internal cached entries.


getTreePath

protected java.lang.String getTreePath(javax.swing.tree.DefaultMutableTreeNode node)
Get the String representation of given path


getTree

public javax.swing.tree.DefaultMutableTreeNode getTree(java.io.FileFilter filter,
                                                       boolean removeFileType)
Get a Tree consisting of all files matching given filter.

Returns:
DefaultMutableTreeNode root of tree containing directories and files.

resetEntries

protected void resetEntries()
Reset the cached entries and trees, forcing a rebuild from the current paths. The internal entries are purged. They will be rebuilt by the next operation that needs them.


addMissingEntries

protected void addMissingEntries()
Add missing entries to entries TreeSet. If a zip or jar file is not correct, initial paths may be missing from the entries table. An example would be: com/sun/tools/jdi/resources/jdi.properties followed by com/sun/xml/parser/. It is missing the entry com/sun/xml/.


setInternalEntries

protected void setInternalEntries(java.util.TreeSet entries)
Set the internal entries TreeSet for testing purposes only.

Parameters:
entries - the internal entries TreeSet for testing purposes only.

getEntriesInPath

protected void getEntriesInPath()


Copyright © 2007 Martin T Phelan. All Rights Reserved.