jbet
Class ClassInfoLoader

java.lang.Object
  extended by jbet.ClassInfoLoader
All Implemented Interfaces:
ClassFinder

public class ClassInfoLoader
extends java.lang.Object
implements ClassFinder

Finds classes and loads them into ClassInfo objects, using the CLASSPATH variable. Main program Jbet constructs an instance of this class and then calls parseClassPath(pathEnvironment). Lexer then calls getClass() to load all classes. Jbet then calls getClasses() to find the classes to write out. This class translates from Java class names ('.'-separated components not ending in '.class') to file names, and maintains a table of loaded classes.

Since:
JDK 1.1.8

Nested Class Summary
static class ClassInfoLoader.DirectoryCPE
          directory returns a reader for a directory.
static class ClassInfoLoader.ZipFileCPE
          zipfile returns a reader for a ZIP file.
 
Field Summary
static char colon
           
 ClassFinder getCopyFinder
           
static java.lang.String JbetLogFacility
           
static char slash
           
 
Constructor Summary
ClassInfoLoader()
          Constructor.
 
Method Summary
 void clearPath()
          clear the classPath.
static ClassPathElement directory(java.lang.String name)
           
 boolean exists(java.lang.String name)
          Test if a class exists on the classpath.
 ClassInfo findClass(java.lang.String name)
           
 void findPackageClasses(java.lang.String packname, java.util.Collection out, boolean sense)
           
 ClassInfo getClass(java.lang.String name)
           
 java.util.Enumeration getClasses()
          Return an enumeration of all classes
 java.lang.String getClassPath()
           
 ClassInfo getCopy(java.lang.String name)
           
 FieldInfo getField(java.lang.String cname, java.lang.String name)
          Get info on a field.
 MethodInfo getMethod(java.lang.String cname, java.lang.String name, Descriptor type)
          Get info on a method.
 java.lang.Object getThing(java.lang.String cname, java.lang.String name, Descriptor d)
          Get info on a classs, method or field.
 ClassInfo lookupClass(java.lang.String name)
          Returns a ClassInfo for the class name specified.
 void parseClassPath(java.lang.String cpString)
          Access the program's CLASSPATH environment variable, split the string in CLASSPATH into separate paths, and saves the separate paths in a Vector.
 void parseClassPath(java.lang.String cpString, boolean insertAtFront)
          Variant that allows control of where to insert.
 void putClass(ClassInfo cr)
          Put a class.
 void putClass(java.lang.String name, ClassInfo cr)
           
 void removeClass(ClassInfo cr)
          remove a class from the loader.
static ClassPathElement zipfile(java.lang.String zfname)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colon

public static char colon

slash

public static char slash

JbetLogFacility

public static java.lang.String JbetLogFacility

getCopyFinder

public ClassFinder getCopyFinder
Constructor Detail

ClassInfoLoader

public ClassInfoLoader()
Constructor.

Method Detail

directory

public static ClassPathElement directory(java.lang.String name)

zipfile

public static ClassPathElement zipfile(java.lang.String zfname)
                                throws java.io.IOException
Throws:
java.io.IOException

parseClassPath

public void parseClassPath(java.lang.String cpString)
Access the program's CLASSPATH environment variable, split the string in CLASSPATH into separate paths, and saves the separate paths in a Vector.

Parameters:
cpString - input class path, colon separated elements.

parseClassPath

public void parseClassPath(java.lang.String cpString,
                           boolean insertAtFront)
Variant that allows control of where to insert.

Parameters:
cpString - input class path
insertAtFront - if true, makes vector in reverse order

clearPath

public void clearPath()
clear the classPath.


getClasses

public java.util.Enumeration getClasses()
Return an enumeration of all classes


findClass

public ClassInfo findClass(java.lang.String name)
                    throws ClassFileException
Specified by:
findClass in interface ClassFinder
Throws:
ClassFileException

lookupClass

public ClassInfo lookupClass(java.lang.String name)
Returns a ClassInfo for the class name specified. The ClassInfoLoader caches ClassInfo objects and returns the ClassInfo from the cache if possible, and reads it from disk (caching it) otherwise.


getClass

public ClassInfo getClass(java.lang.String name)
                   throws ClassFileException
Throws:
ClassFileException

getCopy

public ClassInfo getCopy(java.lang.String name)
                  throws ClassFileException
Throws:
ClassFileException

getMethod

public MethodInfo getMethod(java.lang.String cname,
                            java.lang.String name,
                            Descriptor type)
                     throws ClassFileException,
                            ElementNotFoundException
Get info on a method. Throw an exception if it's not there.

Parameters:
cname - class name
name - method name
type - method descriptor
Returns:
a MethodInfo object for the method.
Throws:
ClassFileException
ElementNotFoundException

getField

public FieldInfo getField(java.lang.String cname,
                          java.lang.String name)
                   throws ClassFileException,
                          ElementNotFoundException
Get info on a field. Throw an exception if it's not there.

Parameters:
cname - class name
name - field name
Returns:
a FieldInfo object for the field.
Throws:
ClassFileException
ElementNotFoundException

getThing

public java.lang.Object getThing(java.lang.String cname,
                                 java.lang.String name,
                                 Descriptor d)
                          throws ClassFileException,
                                 ElementNotFoundException
Get info on a classs, method or field. Return appropriate info. Throw an exception if it's not there.

Parameters:
cname - class name.
name - field or method name.
d - optional method descriptor
Returns:
either a ClassInfo, MethodInfo or a FieldInfo
Throws:
ClassFileException
ElementNotFoundException

removeClass

public void removeClass(ClassInfo cr)
remove a class from the loader. This is so it can be renamed.


putClass

public void putClass(ClassInfo cr)
Put a class.

Parameters:
cr - ClassInfo of the class.

putClass

public void putClass(java.lang.String name,
                     ClassInfo cr)

exists

public boolean exists(java.lang.String name)
               throws ClassFileException
Test if a class exists on the classpath.

Parameters:
name - name of the class.
Returns:
true if class can be found.
Throws:
ClassFileException

findPackageClasses

public void findPackageClasses(java.lang.String packname,
                               java.util.Collection out,
                               boolean sense)
                        throws ClassFileException
Throws:
ClassFileException

getClassPath

public java.lang.String getClassPath()