|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
artofillusion.util.SearchlistClassLoader
public class SearchlistClassLoader
A class loader which loads classes using a searchlist of
other classloaders.
The classloaders in the searchlist are of two types: shared and
non-shared. A shared classloader may be in use by other code, and
so no duplicates should be made of the classes in the loaders.
A non-shared classloader is private to this SearchlistClassLoader, and
so there is no possibility that other code could be using them. To avoid
problems of isolation, all classes loaded through non-shared loaders are
defined as having been loaded by the SearchlistClassLoader itself. This
ensures the JVM can find the correct loader when loading associated
classes (including shared classes).
The SearchlistClassLoader API therefore makes a clear distinction
between shared and non-shared classloaders.
The add(ClassLoader)
method adds an existing classloader
which means the added classloader is treated as being shared.
The add(URL)
method adds a new internally created classloader
which loads the content associated with the specified URL, which means the
internally created classloader is non-shared.
SearchlistClassLoader therefore also allows control over the order in
which classloaders are searched, through the setSearchMode(byte)
method.
The possible searchmodes are:
loadLocalClass(String)
and getLocalResource(String)
).
Implementation notes:.
Because each class object is associated with the classloader which
defined it (see ClassLoader.defineClass(...)), SearchlistClassLoader
must associate itself with all class objects it loads
through non-shared loaders, and similarly must not associate
itself with class objects loaded through shared loaders.
(See findClass(String)
.)
The structure of the internal ClassLoader methods is as per the
instructions in ClassLoader
. While I don't think this is
necessary any longer, it was quite easy to comply with the instructions.
Field Summary | |
---|---|
static byte |
NONSHARED
|
static byte |
ORDERED
|
static byte |
SHARED
search mode enums |
Constructor Summary | |
---|---|
SearchlistClassLoader()
create a SearchlistClassLoader. |
|
SearchlistClassLoader(java.lang.ClassLoader parent)
create a SearchlistClassLoader. |
|
SearchlistClassLoader(java.net.URL[] url)
create a SearchlistClassLoader. |
|
SearchlistClassLoader(java.net.URL[] url,
java.lang.ClassLoader parent)
create a SearchlistClassLoader. |
Method Summary | |
---|---|
void |
add(java.lang.ClassLoader loader)
add a (shared) classloader to the searchlist. |
void |
add(java.net.URL url)
add a (non-shared) URL to the searchlist. |
java.lang.Class |
findClass(java.lang.String name)
Return a Class object for the specified class name. |
java.lang.String |
findLibrary(java.lang.String libname)
return the pathname to the specified native library. |
java.net.URL |
findResource(java.lang.String path)
find a resource using the searchlist. |
java.net.URL |
getLocalResource(java.lang.String name)
Return the URL for the local resource specified by name. |
java.net.URL[] |
getSearchPath()
return the list of URLs in the search list |
java.net.URL[] |
getURLs()
return the array of URLs used locally by this class loader |
java.lang.Class |
loadLocalClass(java.lang.String name)
Return the local class instance for name. |
void |
setSearchMode(byte mode)
set the search mode. |
static java.lang.String |
translate(java.lang.String str,
java.lang.String match,
java.lang.String replace)
translate matching chars in a string. |
Methods inherited from class java.lang.ClassLoader |
---|
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte SHARED
public static final byte NONSHARED
public static final byte ORDERED
Constructor Detail |
---|
public SearchlistClassLoader()
public SearchlistClassLoader(java.lang.ClassLoader parent)
public SearchlistClassLoader(java.net.URL[] url)
public SearchlistClassLoader(java.net.URL[] url, java.lang.ClassLoader parent)
Method Detail |
---|
public void setSearchMode(byte mode)
mode
- enum for the searchmode: SHARED, NONSHARED, ORDEREDpublic void add(java.lang.ClassLoader loader)
loader
- the ClassLoader to add to the searchlist.public void add(java.net.URL url)
url
- the URL to add to the searchlist.public java.net.URL[] getURLs()
public java.net.URL[] getSearchPath()
public java.lang.Class loadLocalClass(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the fully-qualified name of the class
java.lang.ClassNotFoundException
- if the class is not found.public java.net.URL getLocalResource(java.lang.String name)
name
- the fully-qualified name of the resource.
public java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.lang.ClassLoader
name
- the fully-qualified name of the class
java.lang.ClassNotFoundException
- if the class could not be loaded.public java.net.URL findResource(java.lang.String path)
findResource
in class java.lang.ClassLoader
path
- the fully-qualified name of the resource to retrieve
public java.lang.String findLibrary(java.lang.String libname)
findLibrary
in class java.lang.ClassLoader
libname
- - the String name of the library to find
public static java.lang.String translate(java.lang.String str, java.lang.String match, java.lang.String replace)
str
- the String to translatematch
- the list of chars to match, in a string.replace
- the list of corresponding chars to replace matched chars
with.
Eg: translate("the dog.", "o.", "i") returns "the dig", because 'o' is replaced with 'i', and '.' is replaced with nothing (ie deleted).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |