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)
| Modifier and Type | Field 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 | |
| private Map | loaderMap
Map by classname of loaders to use for reloaded classes |
| private ReferenceQueue | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public Class | Returns: the class or nullOverrides bsh. Note Again, this is just a trivial implementation. |
| protected void | classLoaderChanged()
Overrides bsh. |
| public Class | defineClass(String name, byte[] code)
Overrides bsh. |
| public void | doSuperImport()
Overrides bsh. |
| public void | |
| public ClassLoader | |
| public String | getClassNameByUnqName(String name)
Overrides bsh. |
| public BshClassPath | |
| pack-priv ClassLoader | |
| public URL | getResource(String
should be an absolute path path)Overrides bsh. |
| public InputStream | getResourceAsStream(String
should be an absolute path path)Overrides bsh. |
| protected boolean | hasSuperImport()
Overrides bsh. |
| private void | |
| public void | reloadAllClasses()
Overrides bsh. |
| public void | reloadClasses(String[] classNames)
Overrides bsh. |
| public void | reloadPackage(String pack)
Overrides bsh. |
| public void | |
| public void | reset()
Overrides bsh. |
| public void | setClassPath(URL[] cp)
Overrides bsh. |
| baseClassPath | back 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()) | |
| baseLoader | back 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_PACKAGE | back to summary |
|---|---|
| pack-priv static final String BSH_PACKAGE | |
| fullClassPath | back 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. | |
| listeners | back to summary |
|---|---|
| private Vector<E> listeners | |
| loaderMap | back to summary |
|---|---|
| private Map<K, V> loaderMap Map by classname of loaders to use for reloaded classes | |
| refQueue | back to summary |
|---|---|
| private ReferenceQueue<T> refQueue | |
| superImport | back to summary |
|---|---|
| private boolean superImport | |
| ClassManagerImpl | back to summary |
|---|---|
| public ClassManagerImpl() Used by BshClassManager singleton constructor | |
| addClassPath | back to summary |
|---|---|
| public void addClassPath(URL path) throws IOException Overrides bsh. | |
| addListener | back to summary |
|---|---|
| public void addListener(BshClassManager. Overrides bsh. | |
| classForName | back to summary |
|---|---|
| public Class Overrides bsh. Doc from bsh. 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.
| |
| classLoaderChanged | back to summary |
|---|---|
| protected void classLoaderChanged() Overrides bsh. 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. | |
| defineClass | back to summary |
|---|---|
| public Class Overrides bsh. Get the BeanShell classloader. public ClassLoader getClassLoader() { } | |
| doSuperImport | back to summary |
|---|---|
| public void doSuperImport() throws UtilEvalError Overrides bsh. Support for "import *;" Hide details in here as opposed to NameSpace. | |
| dump | back to summary |
|---|---|
| public void dump(PrintWriter i) Overrides bsh. | |
| getBaseLoader | back to summary |
|---|---|
| public ClassLoader getBaseLoader() | |
| getClassNameByUnqName | back to summary |
|---|---|
| public String getClassNameByUnqName(String name) throws ClassPathException Overrides bsh. Return the name or null if none is found, Throw an ClassPathException containing detail if name is ambigous. | |
| getClassPath | back to summary |
|---|---|
| public BshClassPath getClassPath() throws ClassPathException Get the full blown classpath. | |
| getLoaderForClass | back to summary |
|---|---|
| pack-priv ClassLoader getLoaderForClass(String name) | |
| getResource | back to summary |
|---|---|
| public URL getResource(String path) Overrides bsh. Get a resource URL using the BeanShell classpath
| |
| getResourceAsStream | back to summary |
|---|---|
| public InputStream getResourceAsStream(String path) Overrides bsh. Get a resource stream using the BeanShell classpath
| |
| hasSuperImport | back to summary |
|---|---|
| protected boolean hasSuperImport() Overrides bsh. Doc from bsh. A "super import" ("import *") operation has been performed. | |
| initBaseLoader | back to summary |
|---|---|
| private void initBaseLoader() init the baseLoader from the baseClassPath | |
| reloadAllClasses | back to summary |
|---|---|
| public void reloadAllClasses() throws ClassPathException Overrides bsh. 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). | |
| reloadClasses | back to summary |
|---|---|
| public void reloadClasses(String[] classNames) throws ClassPathException Overrides bsh. 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 | |
| reloadPackage | back to summary |
|---|---|
| public void reloadPackage(String pack) throws ClassPathException Overrides bsh. Reload all classes in the specified package: e.g. "com.sun.tools"
The special package name " | |
| removeListener | back to summary |
|---|---|
| public void removeListener(BshClassManager. Overrides bsh. | |
| reset | back to summary |
|---|---|
| public void reset() Overrides bsh. Clear all classloading behavior and class caches and reset to initial state. | |
| setClassPath | back to summary |
|---|---|
| public void setClassPath(URL[] cp) Overrides bsh. Set a new base classpath and create a new base classloader. This means all types change. | |