public class BshClassManager
extends java.lang.Object
Bsh has a multi-tiered class loading architecture. No class loader is used unless/until the classpath is modified or a class is reloaded.
| Modifier and Type | Class and Description |
|---|---|
static interface |
BshClassManager.Listener |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,java.lang.Class<?>> |
absoluteClassCache
Global cache for things we know are classes.
|
protected java.util.Set<java.lang.String> |
absoluteNonClasses
Global cache for things we know are *not* classes.
|
protected java.util.Map<java.lang.String,java.lang.Class<?>> |
associatedClasses |
protected java.lang.ClassLoader |
externalClassLoader
An external classloader supplied by the setClassLoader() command.
|
| Constructor and Description |
|---|
BshClassManager() |
| Modifier and Type | Method and Description |
|---|---|
void |
addClassPath(java.net.URL path) |
void |
addListener(BshClassManager.Listener l) |
void |
associateClass(java.lang.Class<?> clas)
Associate a persistent generated class implementation with this
interpreter.
|
void |
cacheClassInfo(java.lang.String name,
java.lang.Class<?> value)
Cache info about whether name is a class or not.
|
boolean |
classExists(java.lang.String name) |
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() |
protected void |
clearCaches()
Clear the caches in BshClassManager
|
protected static UtilEvalError |
cmUnavailable() |
static BshClassManager |
createClassManager(Interpreter interpreter)
Create a new instance of the class manager.
|
java.lang.Class<?> |
defineClass(java.lang.String name,
byte[] code) |
protected void |
doSuperImport()
Support for "import *;"
Hide details in here as opposed to NameSpace.
|
void |
dump(java.io.PrintWriter pw) |
java.lang.Class<?> |
getAssociatedClass(java.lang.String name) |
protected 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.
|
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
|
boolean |
getStrictJava() |
protected boolean |
hasSuperImport()
A "super import" ("import *") operation has been performed.
|
protected java.lang.Class<?> |
loadSourceClass(java.lang.String name) |
java.lang.Class<?> |
plainClassForName(java.lang.String name)
Perform a plain Class.forName() or call the externally provided
classloader.
|
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 loaders and start over.
|
void |
setClassLoader(java.lang.ClassLoader externalCL)
Set an external class loader.
|
void |
setClassPath(java.net.URL[] cp)
Set a new base classpath and create a new base classloader.
|
protected java.lang.ClassLoader externalClassLoader
protected final transient java.util.Map<java.lang.String,java.lang.Class<?>> absoluteClassCache
protected final transient java.util.Set<java.lang.String> absoluteNonClasses
protected final transient java.util.Map<java.lang.String,java.lang.Class<?>> associatedClasses
associateClass( Class )public boolean getStrictJava()
public static BshClassManager createClassManager(Interpreter interpreter)
bsh.Interpreter.getClassManager(),
bsh.Interpreter.setClassLoader( ClassLoader )public boolean classExists(java.lang.String name)
public java.lang.Class<?> classForName(java.lang.String name)
protected java.lang.Class<?> loadSourceClass(java.lang.String name)
public java.lang.Class<?> plainClassForName(java.lang.String name)
throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundExceptionclassForName( String )public java.net.URL getResource(java.lang.String path)
path - should be an absolute pathpublic java.io.InputStream getResourceAsStream(java.lang.String path)
path - should be an absolute pathpublic void cacheClassInfo(java.lang.String name,
java.lang.Class<?> value)
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 resolutionpublic void associateClass(java.lang.Class<?> clas)
public java.lang.Class<?> getAssociatedClass(java.lang.String name)
protected void clearCaches()
void #reset() for external usagepublic void setClassLoader(java.lang.ClassLoader externalCL)
public void addClassPath(java.net.URL path)
throws java.io.IOException
java.io.IOExceptionpublic void reset()
public void setClassPath(java.net.URL[] cp)
throws UtilEvalError
UtilEvalErrorpublic void reloadAllClasses()
throws UtilEvalError
UtilEvalErrorpublic void reloadClasses(java.lang.String[] classNames)
throws UtilEvalError
UtilEvalErrorpublic void reloadPackage(java.lang.String pack)
throws UtilEvalError
UtilEvalErrorprotected void doSuperImport()
throws UtilEvalError
UtilEvalErrorprotected boolean hasSuperImport()
protected java.lang.String getClassNameByUnqName(java.lang.String name)
throws UtilEvalError
UtilEvalErrorpublic void addListener(BshClassManager.Listener l)
public void removeListener(BshClassManager.Listener l)
public void dump(java.io.PrintWriter pw)
public java.lang.Class<?> defineClass(java.lang.String name,
byte[] code)
protected void classLoaderChanged()
protected static UtilEvalError cmUnavailable()