com.sun.tdk.signaturetest.classpath
Class ClasspathImpl

java.lang.Object
  extended by com.sun.tdk.signaturetest.classpath.ClasspathImpl
All Implemented Interfaces:
Classpath

public class ClasspathImpl
extends java.lang.Object
implements Classpath

ClasspathImpl provides access to all classes placed inside directories and/or jar-files listed in the classpath, which is given to the constructor for new ClasspathImpl instance.

The constructor searches every directory or jar-file listed and keeps corresponding ClasspathEntry element, which can provide access to a bytecode for each class found inside the directory or jar-file. All classes found inside the listed directories and jar-files are virtually enumerated in the same order as they are found. The methods nextClassName() and setListToBegin() provide access to this classes enumeration.

Also, the method findClass(name) provides access to class directly by its qualified name. Note however, that the names class must belong to some directory or zip-file pointed to the ClasspathImpl instance.

See Also:
ClasspathEntry

Constructor Summary
ClasspathImpl(java.lang.String classPath)
          This constructor finds all classes within the given classpath, and creates a list of ClasspathEntry iterator - one element per each directory or zip-file found.
 
Method Summary
 void close()
          Free resources used (if any) or do nothing.
protected  ClasspathEntry createPathEntry(ClasspathEntry previosEntry, java.lang.String name)
          Check if the given name is directory or zip-file name, and create either new DirectoryEntry or new JarFileEntry instance correspondingly.
 java.io.InputStream findClass(java.lang.String name)
          Returns FileInputStream instance providing bytecode for the required class.
 int getNumErrors()
          Return number of significand errors occurred when ClasspathImpl constructor was being working.
 boolean hasNext()
           
 void init(java.lang.String classPath)
          Initialize the module with given parameter: classPath.
 boolean isEmpty()
           
 java.lang.String nextClassName()
          Search next class in the enumeration of classes found inside directories and jar-files pointed to this ClasspathImpl instance.
 void printErrors(java.io.PrintWriter out)
          Report about all errors occurred while construction of ClasspathImpl.
 void setListToBegin()
          Reset list of directories and/or zip-files found by ClasspathImpl.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathImpl

public ClasspathImpl(java.lang.String classPath)
This constructor finds all classes within the given classpath, and creates a list of ClasspathEntry iterator - one element per each directory or zip-file found. Classes found inside the listed directories and zip files become available through the created ClasspathImpl instance.

Parameters:
classPath - Path string listing directories and/or zip files.
Throws:
java.lang.SecurityException - The classPath string has invalid format.
See Also:
findClass(String), nextClassName(), setListToBegin(), createPathEntry(ClasspathEntry, String)
Method Detail

init

public void init(java.lang.String classPath)
Description copied from interface: Classpath
Initialize the module with given parameter: classPath.

Specified by:
init in interface Classpath
Parameters:
classPath - parameter provided to initialize module (usually a directory or file classPath).

close

public void close()
Description copied from interface: Classpath
Free resources used (if any) or do nothing.

Specified by:
close in interface Classpath

isEmpty

public boolean isEmpty()

printErrors

public void printErrors(java.io.PrintWriter out)
Report about all errors occurred while construction of ClasspathImpl.

Parameters:
out - Where to println error messages.

getNumErrors

public int getNumErrors()
Return number of significand errors occurred when ClasspathImpl constructor was being working. Ignorable path entries are not taken into account here.

See Also:
createPathEntry(ClasspathEntry, String)

setListToBegin

public void setListToBegin()
Reset list of directories and/or zip-files found by ClasspathImpl. This also resets transparent enumeration of classes found inside those directories and zip-files, which are available with the methods nextClassName(), getCurrentClass(), or findClass(name).

Specified by:
setListToBegin in interface Classpath
See Also:
nextClassName(), findClass(String)

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Classpath
Returns:
true if more classes available

nextClassName

public java.lang.String nextClassName()
Search next class in the enumeration of classes found inside directories and jar-files pointed to this ClasspathImpl instance. You may invoke setListToBegin() method to restore classes enumeration to its starting point.

Specified by:
nextClassName in interface Classpath
Returns:
Class qualified name
See Also:
setListToBegin(), findClass(String)

findClass

public java.io.InputStream findClass(java.lang.String name)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
Returns FileInputStream instance providing bytecode for the required class. The class must be found by the given qualified name inside some of ClasspathEntry iterator listed by this ClasspathImpl instance.

Specified by:
findClass in interface Classpath
Parameters:
name - Qualified name of the class requested.
Throws:
java.lang.ClassNotFoundException - Not found in any ClasspathEntry in this ClasspathImpl instance.
java.io.IOException
See Also:
FileInputStream

createPathEntry

protected ClasspathEntry createPathEntry(ClasspathEntry previosEntry,
                                         java.lang.String name)
Check if the given name is directory or zip-file name, and create either new DirectoryEntry or new JarFileEntry instance correspondingly.

Parameters:
name - Qualified name of some directory or zip file.
Returns:
New ClasspathEntry instance corresponding to the given name.