org.sadun.util
Class SimpleClassPackageExplorer

java.lang.Object
  extended byorg.sadun.util.SimpleClassPackageExplorer
All Implemented Interfaces:
ClassPackageExplorer

public class SimpleClassPackageExplorer
extends java.lang.Object
implements ClassPackageExplorer

A package explorer implementation.

WARNING: Sealed Jars aren't supported yet.

Version:
1.1
Author:
Cristiano Sadun

Nested Class Summary
static class SimpleClassPackageExplorer.PackageExplorationAdapter
          An empty implementation of PackageExplorationListener.
static interface SimpleClassPackageExplorer.PackageExplorationListener
          Classes implementing this interface receive notifications of the explorer's activity.
 
Field Summary
 
Fields inherited from interface org.sadun.util.ClassPackageExplorer
IN_DIRECTORY, IN_JAR, IN_JAR_SEALED
 
Constructor Summary
SimpleClassPackageExplorer()
          Create a SimpleClassPackageExplorer on the system class path.
SimpleClassPackageExplorer(java.lang.String classPath)
          Create a SimpleClassPackageExplorer on the given class path.
SimpleClassPackageExplorer(java.lang.String classPath, java.lang.String[] classDirs)
          Create a SimpleClassPackageExplorer on the given class path.
 
Method Summary
 void addExplorationListener(SimpleClassPackageExplorer.PackageExplorationListener l)
          Add a SimpleClassPackageExplorer.PackageExplorationListener to this object.
 java.lang.String getClassPath()
          Returns the classPath.
 java.lang.String getErrorLog()
          Return an error status for the explorer.
 java.io.File[] getPackageFiles(java.lang.String packageName)
          Return the one or more files or directories where a package lives.
 int getStatus(java.lang.String packageName)
          Return information on whether the package lives in a directory, a jar file, a sealed jar file or a combination.
 boolean hasErrorOccurred()
          Return an error status for the explorer.
 java.lang.String[] listPackage(java.lang.String packageName)
          Return the names of all the classes in the package.
 java.lang.String[] listPackage(java.lang.String packageName, int status)
          Return the names of the classes in the package.
 java.lang.String[] listPackageNames()
          List the available packages.
 java.lang.String[] listPackageNames(boolean rescan)
          List the available packages.
static void main(java.lang.String[] args)
          A test method
 void removeExplorationListener(SimpleClassPackageExplorer.PackageExplorationListener l)
          Remove a SimpleClassPackageExplorer.PackageExplorationListener from this object.
 void setClassPath(java.lang.String classPath)
          Sets the classPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleClassPackageExplorer

public SimpleClassPackageExplorer()
Create a SimpleClassPackageExplorer on the system class path.


SimpleClassPackageExplorer

public SimpleClassPackageExplorer(java.lang.String classPath)
Create a SimpleClassPackageExplorer on the given class path.


SimpleClassPackageExplorer

public SimpleClassPackageExplorer(java.lang.String classPath,
                                  java.lang.String[] classDirs)
Create a SimpleClassPackageExplorer on the given class path.

Parameters:
classDirs - an array of regular expression for the names of subdirectories to search for; these patterns are not considered for JARs.
Method Detail

listPackage

public java.lang.String[] listPackage(java.lang.String packageName)
Description copied from interface: ClassPackageExplorer
Return the names of all the classes in the package. This can take a long time on first invocation.

Specified by:
listPackage in interface ClassPackageExplorer
Parameters:
packageName - the name of the package
Returns:
the names of all the classes in the package.
See Also:
ClassPackageExplorer.listPackage(String)

listPackageNames

public java.lang.String[] listPackageNames()
Description copied from interface: ClassPackageExplorer
List the available packages. The classpath is scanned for classes, and each package is reported. This can take a long time on first invocation.

Specified by:
listPackageNames in interface ClassPackageExplorer
Returns:
a list of package names
See Also:
ClassPackageExplorer.listPackageNames()

getClassPath

public java.lang.String getClassPath()
Returns the classPath.

Returns:
String

getPackageFiles

public java.io.File[] getPackageFiles(java.lang.String packageName)
Description copied from interface: ClassPackageExplorer
Return the one or more files or directories where a package lives.

This can take a long time on first invocation.

Specified by:
getPackageFiles in interface ClassPackageExplorer
Parameters:
packageName - the name of the package
Returns:
the files containing classes belonging to the given package.
See Also:
ClassPackageExplorer.getPackageFiles(String)

getStatus

public int getStatus(java.lang.String packageName)
Description copied from interface: ClassPackageExplorer
Return information on whether the package lives in a directory, a jar file, a sealed jar file or a combination.

This can take a long time on first invocation.

Specified by:
getStatus in interface ClassPackageExplorer
Parameters:
packageName - the name of the package
Returns:
the distribution status for the given package, or -1 if the given package does not exist.
See Also:
ClassPackageExplorer.getStatus(String)

listPackage

public java.lang.String[] listPackage(java.lang.String packageName,
                                      int status)
Description copied from interface: ClassPackageExplorer
Return the names of the classes in the package.

Specified by:
listPackage in interface ClassPackageExplorer
Parameters:
packageName - the name of the package
Returns:
the names of the classes in the package.
See Also:
ClassPackageExplorer.listPackage(String, int)

listPackageNames

public java.lang.String[] listPackageNames(boolean rescan)
Description copied from interface: ClassPackageExplorer
List the available packages. The classpath is scanned for classes, and each package is reported.

This can take a long time on first invocation or if rescan is true.

Specified by:
listPackageNames in interface ClassPackageExplorer
Parameters:
rescan - forces a re-scanning
Returns:
a list of package names
See Also:
ClassPackageExplorer.listPackageNames(boolean)

setClassPath

public void setClassPath(java.lang.String classPath)
Sets the classPath.

Parameters:
classPath - The classPath to set

getErrorLog

public java.lang.String getErrorLog()
Description copied from interface: ClassPackageExplorer
Return an error status for the explorer.

Specified by:
getErrorLog in interface ClassPackageExplorer
See Also:
ClassPackageExplorer.getErrorLog()

hasErrorOccurred

public boolean hasErrorOccurred()
Description copied from interface: ClassPackageExplorer
Return an error status for the explorer.

Specified by:
hasErrorOccurred in interface ClassPackageExplorer
Returns:
true if an error has occurred while exploring the class path.
See Also:
ClassPackageExplorer.hasErrorOccurred()

addExplorationListener

public void addExplorationListener(SimpleClassPackageExplorer.PackageExplorationListener l)
Add a SimpleClassPackageExplorer.PackageExplorationListener to this object.

Parameters:
l - the SimpleClassPackageExplorer.PackageExplorationListener to add

removeExplorationListener

public void removeExplorationListener(SimpleClassPackageExplorer.PackageExplorationListener l)
Remove a SimpleClassPackageExplorer.PackageExplorationListener from this object.

Parameters:
l - the SimpleClassPackageExplorer.PackageExplorationListener to remove

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A test method

Throws:
java.lang.Exception