bsh
Class BshClassManager

java.lang.Object
  |
  +--bsh.BshClassManager
Direct Known Subclasses:
ClassManagerImpl

public abstract class BshClassManager
extends java.lang.Object

BshClassManager manages all classloading in BeanShell. It also supports a dynamically loaded extension (bsh.classpath package) which allows classpath extension and class file reloading. Currently the extension relies on 1.2 for BshClassLoader and weak references. See http://www.beanshell.org/manual/classloading.html for details on the bsh classloader architecture.

Bsh has a multi-tiered class loading architecture. No class loader is used unless/until the classpath is modified or a class is reloaded.

Note: currently class loading features affect all instances of the Interpreter. However the basic design of this class will allow for per instance class management in the future if it is desired.


Nested Class Summary
static interface BshClassManager.Listener
           
 
Field Summary
protected static java.util.Hashtable absoluteClassCache
          Global cache for things we know are classes.
protected static java.util.Hashtable absoluteNonClasses
          Global cache for things we know are *not* classes.
private static boolean checkedForManager
           
private static java.lang.ClassLoader externalClassLoader
          An external classloader supplied by the setClassLoader() command.
private static BshClassManager manager
          Singleton class manager
private static java.lang.Object NOVALUE
           
 
Constructor Summary
BshClassManager()
           
 
Method Summary
abstract  void addClassPath(java.net.URL path)
           
static void addCMListener(BshClassManager.Listener l)
          Add a BshClassManager.Listener to the class manager.
abstract  void addListener(BshClassManager.Listener l)
           
static void cacheClassInfo(java.lang.String name, java.lang.Class value)
          Cache info about whether name is a class or not.
static boolean classExists(java.lang.String name)
           
static java.lang.Class classForName(java.lang.String name)
          Load the specified class by name, taking into account added classpath and reloaded classes, etc.
protected abstract  void classLoaderChanged()
           
protected  void clearCaches()
          Clear the static caches in BshClassManager
abstract  void doSuperImport()
          Support for "import *;" Hide details in here as opposed to NameSpace.
abstract  void dump(java.io.PrintWriter pw)
           
abstract  java.lang.ClassLoader getBaseLoader()
           
abstract  java.lang.Class getClassForName(java.lang.String name)
           
static BshClassManager getClassManager()
           
abstract  java.lang.String getClassNameByUnqName(java.lang.String name)
          Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous.
abstract  java.lang.ClassLoader getLoaderForClass(java.lang.String name)
           
abstract  java.lang.Class getPlainClassForName(java.lang.String name)
          Delegate for plainClassForName.
static java.lang.Class plainClassForName(java.lang.String name)
          Perform a plain Class.forName() or call the externally provided class loader.
abstract  void reloadAllClasses()
          Overlay the entire path with a new class loader.
abstract  void reloadClasses(java.lang.String[] classNames)
          Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space.
abstract  void reloadPackage(java.lang.String pack)
          Reload all classes in the specified package: e.g.
abstract  void removeListener(BshClassManager.Listener l)
           
abstract  void reset()
          Clear all loaders and start over.
static void setClassLoader(java.lang.ClassLoader externalCL)
          Set an external class loader.
abstract  void setClassPath(java.net.URL[] cp)
          Set a new base classpath and create a new base classloader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

manager

private static BshClassManager manager
Singleton class manager


checkedForManager

private static boolean checkedForManager

NOVALUE

private static java.lang.Object NOVALUE

externalClassLoader

private static java.lang.ClassLoader externalClassLoader
An external classloader supplied by the setClassLoader() command.


absoluteClassCache

protected static transient java.util.Hashtable absoluteClassCache
Global cache for things we know are classes. Note: these should probably be re-implemented with Soft references. (as opposed to strong or Weak)


absoluteNonClasses

protected static transient java.util.Hashtable absoluteNonClasses
Global cache for things we know are *not* classes. Note: these should probably be re-implemented with Soft references. (as opposed to strong or Weak)

Constructor Detail

BshClassManager

public BshClassManager()
Method Detail

getClassManager

public static BshClassManager getClassManager()
Returns:
the BshClassManager singleton or null, indicating no class manager is available.

classExists

public static boolean classExists(java.lang.String name)

classForName

public static java.lang.Class classForName(java.lang.String name)
Load the specified class by name, taking into account added classpath and reloaded classes, etc.

Returns:
the class or null

plainClassForName

public static java.lang.Class plainClassForName(java.lang.String name)
                                         throws java.lang.ClassNotFoundException
Perform a plain Class.forName() or call the externally provided class loader. If a BshClassManager implementation is loaded the call will be delegated to it, to allow for additional hooks. This simply wraps that bottom level class lookup call and provides a central point for monitoring and handling certain Java version dependent bugs, etc.

Returns:
the class
java.lang.ClassNotFoundException
See Also:
getPlainClassForName( String )

cacheClassInfo

public static void cacheClassInfo(java.lang.String name,
                                  java.lang.Class value)
Cache info about whether name is a class or not.

Parameters:
value - if value is non-null, cache the class if value is null, set the flag that it is *not* a class to speed later resolution

clearCaches

protected void clearCaches()
Clear the static caches in BshClassManager


addCMListener

public static void addCMListener(BshClassManager.Listener l)
Add a BshClassManager.Listener to the class manager. The listener is informed upon changes to the classpath. This is a static convenience form of BshClassManager addListener(). If there is no class manager the listener will be ignored.


setClassLoader

public static void setClassLoader(java.lang.ClassLoader externalCL)
Set an external class loader. BeanShell will use this at the same point it would otherwise use the plain Class.forName(). i.e. if no explicit classpath management is done from the script (addClassPath(), setClassPath(), reloadClasses()) then BeanShell will only use the supplied classloader. If additional classpath management is done then BeanShell will perform that in addition to the supplied external classloader. However BeanShell is not currently able to reload classes supplied through the external classloader.


getClassForName

public abstract java.lang.Class getClassForName(java.lang.String name)
See Also:
classForName( String )

getPlainClassForName

public abstract java.lang.Class getPlainClassForName(java.lang.String name)
                                              throws java.lang.ClassNotFoundException
Delegate for plainClassForName.

java.lang.ClassNotFoundException
See Also:
plainClassForName( String )

getBaseLoader

public abstract java.lang.ClassLoader getBaseLoader()

getLoaderForClass

public abstract java.lang.ClassLoader getLoaderForClass(java.lang.String name)

addClassPath

public abstract void addClassPath(java.net.URL path)
                           throws java.io.IOException
java.io.IOException

reset

public abstract void reset()
Clear all loaders and start over. No class loading.


setClassPath

public abstract void setClassPath(java.net.URL[] cp)
Set a new base classpath and create a new base classloader. This means all types change.


reloadAllClasses

public abstract void reloadAllClasses()
                               throws ClassPathException
Overlay the entire path with a new class loader. Set the base path to the user path + base path. No point in including the boot class path (can't reload thos).

ClassPathException

reloadClasses

public abstract void reloadClasses(java.lang.String[] classNames)
                            throws ClassPathException
Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space. For this we use a DiscreteFilesClassLoader

ClassPathException

reloadPackage

public abstract void reloadPackage(java.lang.String pack)
                            throws ClassPathException
Reload all classes in the specified package: e.g. "com.sun.tools" The special package name "" can be used to refer to unpackaged classes.

ClassPathException

doSuperImport

public abstract void doSuperImport()
                            throws EvalError
Support for "import *;" Hide details in here as opposed to NameSpace. Note: this used to be package private...

EvalError

getClassNameByUnqName

public abstract java.lang.String getClassNameByUnqName(java.lang.String name)
                                                throws ClassPathException
Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous. Note: this used to be package private...

ClassPathException

addListener

public abstract void addListener(BshClassManager.Listener l)

removeListener

public abstract void removeListener(BshClassManager.Listener l)

dump

public abstract void dump(java.io.PrintWriter pw)

classLoaderChanged

protected abstract void classLoaderChanged()