com.deltax.util
Class JDK12ClassFileFinder

java.lang.Object
  |
  +--com.deltax.util.JDK12ClassFileFinder

public class JDK12ClassFileFinder
extends java.lang.Object
implements ClassFileFinder

This class emulates JDK 1.2 behaviour for finding class, providing direct access to the files / streams Of course, it work only when classes are actually loaded from a filesystem.


Field Summary
protected  java.lang.String classPath
          The application class path used by this classFileFinder
 
Constructor Summary
JDK12ClassFileFinder()
          Creates a classfinder which looks (besides system directories) in $java.class.path
JDK12ClassFileFinder(java.lang.String classPath)
          Creates a classfinder which looks (besides system directories) in the given class path
 
Method Summary
protected  java.lang.String classNameToEntry(java.lang.String className)
          Converts a fully qualified externalized java class name into a zip file entry.
protected  java.lang.String classNameToPath(java.lang.String className)
          Converts a fully qualified externalized java class name into a relative file path.
 java.io.File findClassFile(java.lang.String className)
          This method emulates 1.2 behaviour for class finding - which means: - it first searches into the $java.home/lib/ and $java.home/lib/*.jar; - then in $java.ext.dirs/*.jar; - eventually in $java.class.path
protected  java.io.File[] findJarsInPath(java.io.File path)
          Find the JAR files in the given path
 byte[] getBytes(java.lang.String className)
          Return the byte array for the class
protected  java.util.Enumeration getClassPathDirs()
           
 java.lang.String getSupportedLoadingScheme()
          Returns the supported loading scheme
 boolean isJar(java.io.File f)
          Just checks if the file ends with .jar
static void main(java.lang.String[] args)
           
 java.io.InputStream openClass(java.lang.String className)
          Open class data.
protected  java.io.InputStream openClassInJar(java.lang.String className, java.io.File jarFile)
          Open class data in a JAR file
protected  java.io.File searchJars(java.lang.String className, java.io.File[] jars)
          Searches jar files for a given class path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classPath

protected java.lang.String classPath
The application class path used by this classFileFinder
Constructor Detail

JDK12ClassFileFinder

public JDK12ClassFileFinder(java.lang.String classPath)
Creates a classfinder which looks (besides system directories) in the given class path
Parameters:
classPath - the search class path

JDK12ClassFileFinder

public JDK12ClassFileFinder()
Creates a classfinder which looks (besides system directories) in $java.class.path
Method Detail

getSupportedLoadingScheme

public java.lang.String getSupportedLoadingScheme()
Returns the supported loading scheme
Specified by:
getSupportedLoadingScheme in interface ClassFileFinder
Tags copied from interface: ClassFileFinder
Returns:
a description string

openClass

public java.io.InputStream openClass(java.lang.String className)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
Open class data. The input stream reads exactly and only the class byte data.
Specified by:
openClass in interface ClassFileFinder
Parameters:
className - the name of the class to find
Throws:
java.lang.ClassNotFoundException - if the class is not found
java.io.IOException - if an I/O Exception occurs

findClassFile

public java.io.File findClassFile(java.lang.String className)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
This method emulates 1.2 behaviour for class finding - which means: - it first searches into the $java.home/lib/ and $java.home/lib/*.jar; - then in $java.ext.dirs/*.jar; - eventually in $java.class.path
Specified by:
findClassFile in interface ClassFileFinder
Parameters:
className - the name of the class to find
Returns:
the File object for the class file; this can be a .class file, or a JAR file containing the class
Throws:
java.lang.ClassNotFoundException - if the class is not found
java.io.IOException - if an I/O Exception occurs

getBytes

public byte[] getBytes(java.lang.String className)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException
Return the byte array for the class
Throws:
java.lang.ClassNotFoundException - if the class is not found in the JAR file
java.io.IOException - if an I/O Exception occurs

isJar

public boolean isJar(java.io.File f)
Just checks if the file ends with .jar
Parameters:
f - the file to check
Returns:
true if the file name ends with .jar

openClassInJar

protected java.io.InputStream openClassInJar(java.lang.String className,
                                             java.io.File jarFile)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
Open class data in a JAR file
Returns:
an input stream to the class byte data in JAR
Throws:
java.lang.ClassNotFoundException - if the class is not found in the JAR file
java.io.IOException - if an I/O Exception occurs

searchJars

protected java.io.File searchJars(java.lang.String className,
                                  java.io.File[] jars)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Searches jar files for a given class path
Parameters:
className - the name of the class to find
jars - an array of JAR file objects
Returns:
the jar file containing the class
Throws:
java.lang.ClassNotFoundException - if the class is not found
java.io.IOException - if an I/O Exception occurs

findJarsInPath

protected java.io.File[] findJarsInPath(java.io.File path)
Find the JAR files in the given path
Parameters:
path - the path to search in
Returns:
an array (may be zero-length) with the JAR file names

classNameToPath

protected java.lang.String classNameToPath(java.lang.String className)
Converts a fully qualified externalized java class name into a relative file path.
Parameters:
className - the name of the class to find
Returns:
the system-dependent path name for the class

classNameToEntry

protected java.lang.String classNameToEntry(java.lang.String className)
Converts a fully qualified externalized java class name into a zip file entry. (ZIP format uses always UNIX slash)
Parameters:
className - the name of the class to find
Returns:
the JAR entry name for the class

getClassPathDirs

protected java.util.Enumeration getClassPathDirs()

main

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