Top Description Fields Constructors Methods
bsh.classpath

public Class ClassManagerImpl

extends BshClassManager
Class Inheritance
Imports
java.net.*, java.util.*, java.lang.ref.*, java.io.IOException, java.io.*, bsh.classpath.BshClassPath.ClassSource, .BshClassPath.JarClassSource, .BshClassPath.GeneratedClassSource, bsh.BshClassManager, .ClassPathException, .Interpreter, .UtilEvalError

Manage all classloading in BeanShell.
Allows classpath extension and class file reloading.

This class holds the implementation of the BshClassManager so that it
can be separated from the core package.

This class currently relies on 1.2 for BshClassLoader and weak references.
Is there a workaround for weak refs?  If so we could make this work
with 1.1 by supplying our own classloader code...

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
created unless/until a class is generated, the classpath is modified, 
or a class is reloaded.

Note

we may need some synchronization in here Note on jdk1.2 dependency: We are forced to use weak references here to accomodate all of the fleeting namespace listeners. (NameSpaces must be informed if the class space changes so that they can un-cache names). I had the interesting thought that a way around this would be to implement BeanShell's own garbage collector... Then I came to my senses and said - screw it, class re-loading will require 1.2. --------------------- Classloading precedence: in-script evaluated class (scripted class) in-script added / modified classpath optionally, external classloader optionally, thread context classloader plain Class.forName() source class (.java file in classpath)

Field Summary

Modifier and TypeField and Description
private BshClassPath
baseClassPath

The classpath of the base loader.

private BshClassLoader
baseLoader

This handles extension / modification of the base classpath The loader to use where no mapping of reloaded classes exists.

pack-priv static final String
private BshClassPath
fullClassPath

This is the full blown classpath including baseClassPath (extensions), user path, and java bootstrap path (rt.jar) This is lazily constructed and further (and more importantly) lazily intialized in components because mapping the full path could be expensive.

private Vector<E>
private Map<K, V>
loaderMap

Map by classname of loaders to use for reloaded classes

private ReferenceQueue<T>
private boolean
Inherited from bsh.BshClassManager:
absoluteClassCacheabsoluteNonClassesdefiningClassesdefiningClassesBaseNamesexternalClassLoaderresolvedObjectMethodsresolvedStaticMethods

Constructor Summary

AccessConstructor and Description
public
ClassManagerImpl()

Used by BshClassManager singleton constructor

Method Summary

Modifier and TypeMethod and Description
public void
public void
public Class<T>

Returns:

the class or null
classForName
(String name)

Overrides bsh.BshClassManager.classForName.

Load the specified class by name, taking into account added classpath and reloaded classes, etc.

Note

Again, this is just a trivial implementation.

protected void
classLoaderChanged()

Overrides bsh.BshClassManager.classLoaderChanged.

Clear global class cache and notify namespaces to clear their class caches.
public Class<T>
defineClass(String name, byte[] code)

Overrides bsh.BshClassManager.defineClass.

Get the BeanShell classloader.
public void
doSuperImport()

Overrides bsh.BshClassManager.doSuperImport.

Support for "import *;" Hide details in here as opposed to NameSpace.
public void
public ClassLoader
public String
getClassNameByUnqName(String name)

Overrides bsh.BshClassManager.getClassNameByUnqName.

Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous.
public BshClassPath
getClassPath()

Get the full blown classpath.

pack-priv ClassLoader
public URL
getResource(String
should be an absolute path
path
)

Overrides bsh.BshClassManager.getResource.

Get a resource URL using the BeanShell classpath
public InputStream
getResourceAsStream(String
should be an absolute path
path
)

Overrides bsh.BshClassManager.getResourceAsStream.

Get a resource stream using the BeanShell classpath
protected boolean
hasSuperImport()

Overrides bsh.BshClassManager.hasSuperImport.

A "super import" ("import *") operation has been performed.
private void
initBaseLoader()

init the baseLoader from the baseClassPath

public void
reloadAllClasses()

Overrides bsh.BshClassManager.reloadAllClasses.

Overlay the entire path with a new class loader.
public void
reloadClasses(String[] classNames)

Overrides bsh.BshClassManager.reloadClasses.

Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space.
public void
reloadPackage(String pack)

Overrides bsh.BshClassManager.reloadPackage.

Reload all classes in the specified package: e.g. "com.sun.tools" The special package name "<unpackaged>" can be used to refer to unpackaged classes.
public void
public void
reset()

Overrides bsh.BshClassManager.reset.

Clear all classloading behavior and class caches and reset to initial state.
public void
setClassPath(URL[] cp)

Overrides bsh.BshClassManager.setClassPath.

Set a new base classpath and create a new base classloader.
Inherited from bsh.BshClassManager:
cacheClassInfocacheResolvedMethodclassExistsclearCachescmUnavailablecreateClassManagerdefiningClassdoneDefiningClassgetClassBeingDefinedgetResolvedMethodisClassBeingDefinedloadSourceClassnoClassDefFoundplainClassForNamesetClassLoader

Field Detail

baseClassPathback to summary
private BshClassPath baseClassPath

The classpath of the base loader. Initially and upon reset() this is an empty instance of BshClassPath. It grows as paths are added or is reset when the classpath is explicitly set. This could also be called the "extension" class path, but is not strictly confined to added path (could be set arbitrarily by setClassPath())

baseLoaderback to summary
private BshClassLoader baseLoader

This handles extension / modification of the base classpath The loader to use where no mapping of reloaded classes exists. The baseLoader is initially null meaning no class loader is used.

BSH_PACKAGEback to summary
pack-priv static final String BSH_PACKAGE
fullClassPathback to summary
private BshClassPath fullClassPath

This is the full blown classpath including baseClassPath (extensions), user path, and java bootstrap path (rt.jar) This is lazily constructed and further (and more importantly) lazily intialized in components because mapping the full path could be expensive. The full class path is a composite of: baseClassPath (user extension) : userClassPath : bootClassPath in that order.

listenersback to summary
private Vector<E> listeners
loaderMapback to summary
private Map<K, V> loaderMap

Map by classname of loaders to use for reloaded classes

refQueueback to summary
private ReferenceQueue<T> refQueue
superImportback to summary
private boolean superImport

Constructor Detail

ClassManagerImplback to summary
public ClassManagerImpl()

Used by BshClassManager singleton constructor

Method Detail

addClassPathback to summary
public void addClassPath(URL path) throws IOException

Overrides bsh.BshClassManager.addClassPath.

addListenerback to summary
public void addListener(BshClassManager.Listener l)

Overrides bsh.BshClassManager.addListener.

classForNameback to summary
public Class<T> classForName(String name)

Overrides bsh.BshClassManager.classForName.

Doc from bsh.BshClassManager.classForName.

Load the specified class by name, taking into account added classpath and reloaded classes, etc.

Note

Again, this is just a trivial implementation. See bsh.classpath.ClassManagerImpl for the fully functional class management package.

Returns:Class<T>

the class or null

classLoaderChangedback to summary
protected void classLoaderChanged()

Overrides bsh.BshClassManager.classLoaderChanged.

Clear global class cache and notify namespaces to clear their class caches. The listener list is implemented with weak references so that we will not keep every namespace in existence forever.

defineClassback to summary
public Class<T> defineClass(String name, byte[] code)

Overrides bsh.BshClassManager.defineClass.

Get the BeanShell classloader. public ClassLoader getClassLoader() { }

doSuperImportback to summary
public void doSuperImport() throws UtilEvalError

Overrides bsh.BshClassManager.doSuperImport.

Support for "import *;" Hide details in here as opposed to NameSpace.

dumpback to summary
public void dump(PrintWriter i)

Overrides bsh.BshClassManager.dump.

getBaseLoaderback to summary
public ClassLoader getBaseLoader()
getClassNameByUnqNameback to summary
public String getClassNameByUnqName(String name) throws ClassPathException

Overrides bsh.BshClassManager.getClassNameByUnqName.

Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous.

getClassPathback to summary
public BshClassPath getClassPath() throws ClassPathException

Get the full blown classpath.

getLoaderForClassback to summary
pack-priv ClassLoader getLoaderForClass(String name)
getResourceback to summary
public URL getResource(String path)

Overrides bsh.BshClassManager.getResource.

Get a resource URL using the BeanShell classpath

Parameters
path:String

should be an absolute path

getResourceAsStreamback to summary
public InputStream getResourceAsStream(String path)

Overrides bsh.BshClassManager.getResourceAsStream.

Get a resource stream using the BeanShell classpath

Parameters
path:String

should be an absolute path

hasSuperImportback to summary
protected boolean hasSuperImport()

Overrides bsh.BshClassManager.hasSuperImport.

Doc from bsh.BshClassManager.hasSuperImport.

A "super import" ("import *") operation has been performed.

initBaseLoaderback to summary
private void initBaseLoader()

init the baseLoader from the baseClassPath

reloadAllClassesback to summary
public void reloadAllClasses() throws ClassPathException

Overrides bsh.BshClassManager.reloadAllClasses.

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).

reloadClassesback to summary
public void reloadClasses(String[] classNames) throws ClassPathException

Overrides bsh.BshClassManager.reloadClasses.

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

reloadPackageback to summary
public void reloadPackage(String pack) throws ClassPathException

Overrides bsh.BshClassManager.reloadPackage.

Reload all classes in the specified package: e.g. "com.sun.tools" The special package name "" can be used to refer to unpackaged classes.

removeListenerback to summary
public void removeListener(BshClassManager.Listener l)

Overrides bsh.BshClassManager.removeListener.

resetback to summary
public void reset()

Overrides bsh.BshClassManager.reset.

Clear all classloading behavior and class caches and reset to initial state.

setClassPathback to summary
public void setClassPath(URL[] cp)

Overrides bsh.BshClassManager.setClassPath.

Set a new base classpath and create a new base classloader. This means all types change.