bsh.classpath
Class ClassManagerImpl
public class ClassManagerImpl
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
used unless/until 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.
addClassPath , addListener , cacheClassInfo , cacheResolvedMethod , classExists , classForName , classLoaderChanged , clearCaches , cmUnavailable , createClassManager , doSuperImport , dump , getClassNameByUnqName , getResolvedMethod , getResource , getResourceAsStream , hasSuperImport , noClassDefFound , plainClassForName , reloadAllClasses , reloadClasses , reloadPackage , removeListener , reset , setClassLoader , setClassPath |
ClassManagerImpl
public ClassManagerImpl()
Used by BshClassManager singleton constructor
addClassPath
public void addClassPath(URL path)
throws IOException
- addClassPath in interface BshClassManager
classForName
public Class classForName(String name)
- classForName in interface BshClassManager
- the class or null
classLoaderChanged
protected void 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.
- classLoaderChanged in interface BshClassManager
doSuperImport
public void doSuperImport()
throws UtilEvalError
Support for "import *;"
Hide details in here as opposed to NameSpace.
- doSuperImport in interface BshClassManager
getBaseLoader
public ClassLoader getBaseLoader()
getClassNameByUnqName
public String getClassNameByUnqName(String name)
throws ClassPathException
Return the name or null if none is found,
Throw an ClassPathException containing detail if name is ambigous.
- getClassNameByUnqName in interface BshClassManager
getResource
public URL getResource(String path)
Get a resource URL using the BeanShell classpath
- getResource in interface BshClassManager
path
- should be an absolute path
getResourceAsStream
public InputStream getResourceAsStream(String path)
Get a resource stream using the BeanShell classpath
- getResourceAsStream in interface BshClassManager
path
- should be an absolute path
hasSuperImport
protected boolean hasSuperImport()
A "super import" ("import *") operation has been performed.
- hasSuperImport in interface BshClassManager
plainClassForName
public Class plainClassForName(String name)
throws ClassNotFoundException
Delegate for bottom level implementation of Class.forName().
This is here solely to provide for Java version specific features.
In this case - the Thread getContextClassLoader() which is required
to get bsh to see user classpath when it's installed in a web
application or in the jre/lib/ext directory.
- plainClassForName in interface BshClassManager
BshClassManager.plainClassForName()
reloadAllClasses
public 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).
- reloadAllClasses in interface BshClassManager
reloadClasses
public void reloadClasses(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
- reloadClasses in interface BshClassManager
reloadPackage
public void reloadPackage(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.
- reloadPackage in interface BshClassManager
reset
public void reset()
Clear all classloading behavior and class caches and reset to
initial state.
- reset in interface BshClassManager
setClassPath
public void setClassPath(URL[] cp)
Set a new base classpath and create a new base classloader.
This means all types change.
- setClassPath in interface BshClassManager
B) 2000 pat@pat.net :-)