adaptj.util
Class ClassPathExplorer

java.lang.Object
  |
  +--adaptj.util.ClassPathExplorer

public class ClassPathExplorer
extends java.lang.Object

Resolves class names from a CLASSPATH. The CLASSPATH is composed of a list of directories, jar/zip files and class files.

Author:
Bruno Dufour

Nested Class Summary
(package private)  class ClassPathExplorer.ClassFileLocation
           
(package private)  class ClassPathExplorer.ClassFoundException
           
 
Method Summary
 java.lang.String getClassFileName(java.lang.String className)
          Tries to resolve the class name specified by className based on the current class path.
 java.io.DataInputStream getInputStream(java.lang.String className)
          Tries resolve the class name specified by className based on the current class path.
 org.apache.bcel.classfile.JavaClass getJavaClass(java.lang.String className)
          Tries to create a new JavaClass corresponding to the name specified by className.
 boolean isArchive(java.io.File f)
          Determines whether the file designated by file appears to be a java archive (zip or jar).
 boolean isArchive(java.lang.String path)
          Determines whether the file designated by path appears to be a java archive (zip or jar).
 boolean isClassFile(java.io.File file)
          Determines whether the file designated by file appears to be a class file.
 boolean isClassFile(java.lang.String filename)
          Determines whether the file designated by filename appears to be a class file.
 void reset()
          Resets the instance of the ClassPathExplorer to its default values.
 void setClassPath(java.util.List classpath)
           
static ClassPathExplorer v()
          Returns the singleton instance of the ClassPathExplorer class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

v

public static ClassPathExplorer v()
Returns the singleton instance of the ClassPathExplorer class. This instance is only created when this method is called for the first time, so that no memory and/or time is wasted when not needed.

Returns:
the singleton instance of the ClassPathExplorer class.

reset

public void reset()
Resets the instance of the ClassPathExplorer to its default values.


setClassPath

public void setClassPath(java.util.List classpath)

getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass(java.lang.String className)
Tries to create a new JavaClass corresponding to the name specified by className.

Parameters:
className - the fully qualified name of the class to be resolved.
Returns:
a JavaClass object for the specified class, or null if it cannot be resolved.

getClassFileName

public java.lang.String getClassFileName(java.lang.String className)
Tries to resolve the class name specified by className based on the current class path. The return value consists of the name of the file which defines this class.

Parameters:
className - the fully qualified name of the class to be resolved. For example, java.lang.String.
Returns:
the name of the file which defines this class. If the file is a zip or jar file, then the entry name of the class is appended at the end of the result, within square brackets.

getInputStream

public java.io.DataInputStream getInputStream(java.lang.String className)
Tries resolve the class name specified by className based on the current class path. The return value consists of an open DataInputStream object opened for reading the contents of the class file, or null if the class cannot be found.

Parameters:
className - the fully qualified name of the class to be resolved. For example, java.lang.String.
Returns:
an open DataInputStream object or null if the class cannot be found.

isArchive

public boolean isArchive(java.lang.String path)
Determines whether the file designated by path appears to be a java archive (zip or jar).

Parameters:
path - the name of a file to test
Returns:
true if the file appears to be a valid archive, false otherwise.

isArchive

public boolean isArchive(java.io.File f)
Determines whether the file designated by file appears to be a java archive (zip or jar).

Returns:
true if the file appears to be a valid archive, false otherwise.

isClassFile

public boolean isClassFile(java.lang.String filename)
Determines whether the file designated by filename appears to be a class file.

Returns:
true if the file appears to be a valid class file, false otherwise.

isClassFile

public boolean isClassFile(java.io.File file)
Determines whether the file designated by file appears to be a class file.

Parameters:
file - a File object representing a file to test
Returns:
true if the file appears to be a valid class file, false otherwise.