classUtils.pack.util
Class SimpleClassPackageExplorer

java.lang.Object
  extended by classUtils.pack.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.0
Author:
Cristiano Sadun

Field Summary
 
Fields inherited from interface classUtils.pack.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
 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 setClassPath(java.lang.String classPath)
          Sets the classPath.
 
Methods inherited from class java.lang.Object
equals, 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.

Parameters:
classPath - string to iterate on

SimpleClassPackageExplorer

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

Parameters:
classPath - string to iterate on
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
status - bit mask (see status constant masks) indicating which files to list.
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()

main

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

Throws:
java.lang.Exception

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()