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.Hashtable |
absoluteClassCache
Global cache for things we know are classes.
|
protected java.util.Hashtable |
absoluteNonClasses
Global cache for things we know are *not* classes.
|
protected java.util.Hashtable |
resolvedObjectMethods
Caches for resolved object and static methods.
|
protected java.util.Hashtable |
resolvedStaticMethods |
Constructor and Description |
---|
BshClassManager() |
Modifier and Type | Method and Description |
---|---|
void |
addClassPath(java.net.URL path) |
void |
addListener(BshClassManager.Listener l) |
void |
cacheClassInfo(java.lang.String name,
java.lang.Class value)
Cache info about whether name is a class or not.
|
void |
cacheResolvedMethod(java.lang.Class clas,
java.lang.Object[] args,
java.lang.reflect.Method method)
Cache a resolved (possibly overloaded) method based on the
argument types used to invoke it, subject to classloader change.
|
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()
Create a new instance of the class manager.
|
protected void |
doSuperImport()
Support for "import *;"
Hide details in here as opposed to NameSpace.
|
void |
dump(java.io.PrintWriter pw) |
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.lang.reflect.Method |
getResolvedMethod(java.lang.Class clas,
java.lang.String methodName,
java.lang.Object[] args,
boolean onlyStatic)
Return a previously cached resolved method.
|
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.
|
protected static java.lang.Error |
noClassDefFound(java.lang.String className,
java.lang.Error e)
Annotate the NoClassDefFoundError with some info about the class
we were trying to load.
|
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 transient java.util.Hashtable absoluteClassCache
protected transient java.util.Hashtable absoluteNonClasses
protected transient java.util.Hashtable resolvedObjectMethods
protected transient java.util.Hashtable resolvedStaticMethods
public static BshClassManager createClassManager()
bsh.Interpreter.getClassManager()
,
bsh.Interpreter.setClassLoader( ClassLoader )
public boolean classExists(java.lang.String name)
public java.lang.Class classForName(java.lang.String name)
public java.lang.Class plainClassForName(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
classForName( 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 cacheResolvedMethod(java.lang.Class clas, java.lang.Object[] args, java.lang.reflect.Method method)
public java.lang.reflect.Method getResolvedMethod(java.lang.Class clas, java.lang.String methodName, java.lang.Object[] args, boolean onlyStatic)
onlyStatic
- specifies that only a static method may be returned.protected void clearCaches()
void #reset() for external usage
public void setClassLoader(java.lang.ClassLoader externalCL)
public void addClassPath(java.net.URL path) throws java.io.IOException
java.io.IOException
public void reset()
public void setClassPath(java.net.URL[] cp) throws UtilEvalError
UtilEvalError
public void reloadAllClasses() throws UtilEvalError
UtilEvalError
public void reloadClasses(java.lang.String[] classNames) throws UtilEvalError
UtilEvalError
public void reloadPackage(java.lang.String pack) throws UtilEvalError
UtilEvalError
protected void doSuperImport() throws UtilEvalError
UtilEvalError
protected boolean hasSuperImport()
protected java.lang.String getClassNameByUnqName(java.lang.String name) throws UtilEvalError
UtilEvalError
public void addListener(BshClassManager.Listener l)
public void removeListener(BshClassManager.Listener l)
public void dump(java.io.PrintWriter pw)
protected void classLoaderChanged()
protected static java.lang.Error noClassDefFound(java.lang.String className, java.lang.Error e)
protected static UtilEvalError cmUnavailable()
? 2000 pat@pat.net :-)