public class ClassManagerImpl extends BshClassManager
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)
BshClassManager.ListenerabsoluteClassCache, absoluteNonClasses, definingClasses, definingClassesBaseNames, externalClassLoader, resolvedObjectMethods, resolvedStaticMethods| Constructor and Description |
|---|
ClassManagerImpl()
Used by BshClassManager singleton constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClassPath(java.net.URL path) |
void |
addListener(BshClassManager.Listener l) |
java.lang.Class |
classForName(java.lang.String name)
Load the specified class by name, taking into account added classpath
and reloaded classes, etc.
|
protected void |
classLoaderChanged()
Clear global class cache and notify namespaces to clear their
class caches.
|
java.lang.Class |
defineClass(java.lang.String name,
byte[] code)
Get the BeanShell classloader.
|
void |
doSuperImport()
Support for "import *;"
Hide details in here as opposed to NameSpace.
|
void |
dump(java.io.PrintWriter i) |
java.lang.ClassLoader |
getBaseLoader() |
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.
|
BshClassPath |
getClassPath()
Get the full blown classpath.
|
java.net.URL |
getResource(java.lang.String path)
Get a resource URL using the BeanShell classpath
|
java.io.InputStream |
getResourceAsStream(java.lang.String path)
Get a resource stream using the BeanShell classpath
|
protected boolean |
hasSuperImport()
A "super import" ("import *") operation has been performed.
|
void |
reloadAllClasses()
Overlay the entire path with a new class loader.
|
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.
|
void |
reloadPackage(java.lang.String pack)
Reload all classes in the specified package: e.g.
|
void |
removeListener(BshClassManager.Listener l) |
void |
reset()
Clear all classloading behavior and class caches and reset to
initial state.
|
void |
setClassPath(java.net.URL[] cp)
Set a new base classpath and create a new base classloader.
|
cacheClassInfo, cacheResolvedMethod, classExists, clearCaches, cmUnavailable, createClassManager, definingClass, doneDefiningClass, getClassBeingDefined, getResolvedMethod, isClassBeingDefined, loadSourceClass, noClassDefFound, plainClassForName, setClassLoaderpublic ClassManagerImpl()
public java.lang.Class classForName(java.lang.String name)
BshClassManagerclassForName in class BshClassManagerpublic java.net.URL getResource(java.lang.String path)
getResource in class BshClassManagerpath - should be an absolute pathpublic java.io.InputStream getResourceAsStream(java.lang.String path)
getResourceAsStream in class BshClassManagerpath - should be an absolute pathpublic void addClassPath(java.net.URL path)
throws java.io.IOException
addClassPath in class BshClassManagerjava.io.IOExceptionpublic void reset()
reset in class BshClassManagerpublic void setClassPath(java.net.URL[] cp)
setClassPath in class BshClassManagerpublic void reloadAllClasses()
throws ClassPathException
reloadAllClasses in class BshClassManagerClassPathExceptionpublic void reloadClasses(java.lang.String[] classNames)
throws ClassPathException
reloadClasses in class BshClassManagerClassPathExceptionpublic void reloadPackage(java.lang.String pack)
throws ClassPathException
reloadPackage in class BshClassManagerClassPathExceptionpublic BshClassPath getClassPath() throws ClassPathException
ClassPathExceptionpublic void doSuperImport()
throws UtilEvalError
doSuperImport in class BshClassManagerUtilEvalErrorprotected boolean hasSuperImport()
BshClassManagerhasSuperImport in class BshClassManagerpublic java.lang.String getClassNameByUnqName(java.lang.String name)
throws ClassPathException
getClassNameByUnqName in class BshClassManagerClassPathExceptionpublic void addListener(BshClassManager.Listener l)
addListener in class BshClassManagerpublic void removeListener(BshClassManager.Listener l)
removeListener in class BshClassManagerpublic java.lang.ClassLoader getBaseLoader()
public java.lang.Class defineClass(java.lang.String name,
byte[] code)
defineClass in class BshClassManagerprotected void classLoaderChanged()
classLoaderChanged in class BshClassManagerpublic void dump(java.io.PrintWriter i)
dump in class BshClassManager