| java.lang.Object java.lang.ClassLoader com.lutris.classloader.MultiClassLoader
MultiClassLoader | public class MultiClassLoader extends ClassLoader (Code) | | Summary:
A class loader that can load classes from
class files and zip files residing in a specified class path.
This class loader can also load resources that reside on the
class path and return them as is, as input streams, or as byte arrays.
Features:
Class Path
If classes are to be loaded from a class path, it must be set by the
setClassPath or addClassPath methods or by
the constructor prior to calling loadClass . If the class
path is not set, the class will be loaded with the system class loader.
The class path can consist of directories, files, and/or URLs.
Example valid class path entries are:
Files and directories on the local file system
../../java/classes
/users/kristen/java/classes
/users/kristen/java/classes/
/users/kristen/java/zipfiles/MyClasses.zip
/users/kristen/java/jarfiles/MyClasses.jar
file:///users/kristen/java/classes
file://localhost/users/kristen/java/classes
Files and directories on a remote file system
(must be in URL format)
ftp://www.foo.com/pub/java/classes
file://www.foo.com/pub/java/classes/
http://www.foo.com/web/java/classes/
file://www.foo.com:8080/pub/java/zipfiles/MyClasses.zip
http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar
Note that the location of the entry includes the protocol, the host name,
and the port while the file name is everything else. For example,
http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar
has the form [location][name] or
[http://www.foo.com:8080/][/web/java/jarfiles/MyClasses.jar]
so the location is "http://www.foo.com:8080/" and the name is
"/web/java/jarfiles/MyClasses.jar".
Note that the two references
/users/kristen/java/classes/
file:///users/kristen/java/classes/
represent the same directory on a Unix machine, and
C|/windows/java/classes/
file:///C|/windows/java/classes/
are equivalent directories on a Windows box.
But the two references
/users/kristen/java/classes/
file://monet.lutris.com/users/kristen/java/classes/
are not equivalent even if the directory
/users/kristen/java/classes/ lives
on the machine named monet.lutris.com and all development
is on this machine. Why? Because the web (browser?) protocol is different
for URLs with host information and those without. If no host is
specified, the file is assumed to be on the local machine and the
path is determined from the ROOT of the machine. If the
host is specified, then the ftp protocol is used and the path
is determined from the ftp ROOT (e.g. /users/ftp/) rather
than the machine's ROOT. Thus, on a machine that support's anonymous
ftp, the following two directories are the same:
/users/ftp/pub/classes/
file://picasso.lutris.com/pub/classes/
assuming the development is being done on picasso.lutris.com.
System Class Path
The system class path is the system-dependent path of directories
and files (e.g. CLASSPATH on Unix and Windows) used by the system
class loader to load classes. This class path is usually configured
prior to executing a Java program but can be dynamically configured
during runtime if desired. If you want to use the system class path
for this class loader, the convenience method getSystemClassPath
has been provided.
Valid system class path entries are
directories and zip files, specified by absolute path or relative path
on the system. Any valid system class path entry is also valid
for this class loader.
Example
Here is an example of how to use this class loader:
MultiClassLoader loader = new MultiClassLoader();
loader.setClassPath("/web/java/lutris.jar");
loader.addClassPath("/users/kristen/java/");
loader.addClassPath("/usr/local/lib/graphics.zip");
try {
Class c = loader.loadClass("com.lutris.util.MyClass");
System.out.println("My loader is " + c.getClassLoader());
Object o = (Object) c.newInstance();
System.out.println("My class is " + o.getClass());
} catch (ClassNotFoundException e) {
Throwable t = new Throwable();
t.printStackTrace();
}
Warning: This class loader is not yet fully compliant with Java 1.2. It
maybe used on 1.2, but not all features are available. The parent loader,
secondary loader, and filter may change in a future release without
maintaining compatibility.
author: Kristen Pol, Lutris Technologies version: $Revision : 1.0 $ See Also: java.lang.ClassLoader See Also: com.lutris.classloader.Resource See Also: java.net.URL |
Inner Class :public interface ClassFilter | |
Inner Class :public static class ClassResource | |
Method Summary | |
public synchronized void | addClassFilter(ClassFilter filter) Add a filter to the list of filters that check if a class maybe
loaded by this class loader. | public void | addClassPath(String path) Adds specified class path to beginning of existing path. | public synchronized void | addClassPath(String[] path) Adds specified class path to beginning of existing path. | public void | addClassPath(File path) Adds specified class path to beginning of existing path. | public synchronized void | addClassPath(File[] path) Adds specified class path to beginning of existing path. | public void | addClassPath(URL path) Adds specified class path to beginning of existing path. | public synchronized void | addClassPath(URL[] path) Adds specified class path to beginning of existing path. | public synchronized void | clearClassPath() Clears class path entries. | public void | enableAutoReloadForSecLoader(boolean enable) Sets flag to enable Auto Reloading possibility when Secondary ClassLoader
usage is forced (refer to forceSecondaryLoader() method for more help). | public void | forceSecondaryLoader(boolean force) Sets flag to indicate forsing of Secondary ClassLoader usage or not.
Parameters: force - true when the MultiClassLoader is used as utility wrapperclass for passed secondary ClassLoader. | public URL[] | getClassPath() Gets class path for class loader defined previously by constructor and
setClassPath /addClassPath methods. | public Resource | getClassResource(String className) Get the resource for a class loaded by this class loader. | public LogChannel | getLogChannel() Get the log channel associated this class loader. | public URL | getResource(String name) Gets specified resource as URL. | public byte[] | getResourceAsByteArray(String name) Gets specified resource as array of bytes.
Parameters: name - The name of the resource. | public Resource | getResourceAsIs(String name) Gets specified resource object. | public InputStream | getResourceAsStream(String name) Gets specified resource as input stream.
Parameters: name - The name of the resource. | public Resource | getResourceObject(String name) Gets specified resource object.
Parameters: name - The name of the resource. | public ClassLoader | getSecondary() Get the secondary class loader. | public static URL[] | getSystemClassPath() Gets class path from system. | public Class | loadClass(String className, boolean resolve) Loads and, optionally, resolves the specified class. | public Class | loadClass(String className) | public static String[] | parseClassPath(String path) Parse a class-path string using the system path separator. | public void | removeLoadedClass() | public void | setClassPath(String path) Sets class loader with specified class path. | public synchronized void | setClassPath(String[] path) Sets class loader with specified class path. | public void | setClassPath(File path) Sets class loader with specified class path. | public synchronized void | setClassPath(File[] path) Sets class loader with specified class path. | public void | setClassPath(URL path) Sets class loader with specified class path. | public synchronized void | setClassPath(URL[] path) Sets class loader with specified class path. | public void | setParent(ClassLoader parent) Set the parent class loader for delegation. | public void | setSecondary(ClassLoader secondary) Set the secondary class loader. | public boolean | shouldReload() Determine if the classes loaded by this class loader have been modified.
If any file associated with loaded in the class loader's class path has
changed, the classes should be reloaded. |
LOG_LEVEL | final public static String LOG_LEVEL(Code) | | Log level symbolic name
|
MultiClassLoader | public MultiClassLoader(ClassLoader parent, ClassLoader secondary, LogChannel loadLogChannel)(Code) | | Constructs class loader with no initial class path and a
specified parent class loader.
Parameters: parent - The parent class loader for delegation,or null if no parent is defined. Parameters: secondary - The secondary class loader.Use getSysClassLoader to get the system class loaderto specify as the secondary. Parameters: loadLogChannel - The log channel, maybe null. See Also: getSysClassLoader |
MultiClassLoader | public MultiClassLoader(LogChannel loadLogChannel)(Code) | | Constructs class loader with no initial class path and the
system class loader as the secondary.
Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(String path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
assumed to be either a directory, URL, or zip file.
Parameters: path - The class path represented by a String. Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(String[] path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
assumed to be an array of directories, URLs, and/or zip files.
Parameters: path - The class path represented by a String array. Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(File path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
assumed to be either a zip file or directory.
Parameters: path - The class path represented by a File. Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(File[] path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
assumed to be an array of zip files and/or directories.
Parameters: path - The class path represented by a File array. Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(URL path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
represent a directory or zip file on the local machine or a
remote machine.
Parameters: path - The class path represented by a URL. Parameters: loadLogChannel - The log channel, maybe null. |
MultiClassLoader | public MultiClassLoader(URL[] path, LogChannel loadLogChannel)(Code) | | Constructs class loader with specified class path. The parameter is
represent directories and/or zip files on the local machine and/or
on remote machines.
Parameters: path - The class path represented by a URL array. Parameters: loadLogChannel - The log channel, maybe null. |
addClassFilter | public synchronized void addClassFilter(ClassFilter filter)(Code) | | Add a filter to the list of filters that check if a class maybe
loaded by this class loader.
|
addClassPath | public void addClassPath(String path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is
assumed to be either a directory, URL, or zip file.
Parameters: path - The class path to be added to current class path. |
addClassPath | public synchronized void addClassPath(String[] path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is
assumed to be an array of directories, URLs, and/or zip files.
Parameters: path - The class path to be added to current class path. |
addClassPath | public void addClassPath(File path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is assumed to be either a zip file or directory.
Parameters: path - The class path to be added to current class path. |
addClassPath | public synchronized void addClassPath(File[] path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is
assumed to be an array of zip files and/or directories.
Parameters: path - The class path to be added to current class path. |
addClassPath | public void addClassPath(URL path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is
represent a directory or zip file on the local machine or a
remote machine.
Parameters: path - The class path to be added to current class path. |
addClassPath | public synchronized void addClassPath(URL[] path)(Code) | | Adds specified class path to beginning of existing path.
The parameter is
represent directories and/or zip files on the local machine and/or
on remote machines.
Parameters: path - The class path to be added to current class path. |
enableAutoReloadForSecLoader | public void enableAutoReloadForSecLoader(boolean enable)(Code) | | Sets flag to enable Auto Reloading possibility when Secondary ClassLoader
usage is forced (refer to forceSecondaryLoader() method for more help).
This flag has no efect when MultiClassLoader is used in standard maner (as
realy ClassLoader, not only as wrapper class for external ClassLoader)
Parameters: enable - true when the AutoReloading should be used. |
forceSecondaryLoader | public void forceSecondaryLoader(boolean force)(Code) | | Sets flag to indicate forsing of Secondary ClassLoader usage or not.
Parameters: force - true when the MultiClassLoader is used as utility wrapperclass for passed secondary ClassLoader. All resource loads will be forcedvia passed Secondary ClassLoader. If parameter is set to false, then theMultyClassLoader will work in standard maner. |
getLogChannel | public LogChannel getLogChannel()(Code) | | Get the log channel associated this class loader.
|
getResource | public URL getResource(String name)(Code) | | Gets specified resource as URL. Doing a getContent() on the URL may
return an Image, an AudioClip, or an InputStream.
Parameters: name - The name of the resource. the resource represented by a URL, or null if not found. |
getResourceAsByteArray | public byte[] getResourceAsByteArray(String name)(Code) | | Gets specified resource as array of bytes.
Parameters: name - The name of the resource. an array of bytes representing the specified resource ornull if the resource is not found. |
getResourceAsIs | public Resource getResourceAsIs(String name)(Code) | | Gets specified resource object.
See Also: deprecated See Also: Use getResourceObject() See Also: getResourceObject |
getResourceAsStream | public InputStream getResourceAsStream(String name)(Code) | | Gets specified resource as input stream.
Parameters: name - The name of the resource. an input stream representing the specified resource ornull if the resource is not found. |
getResourceObject | public Resource getResourceObject(String name)(Code) | | Gets specified resource object.
Parameters: name - The name of the resource. the resource if found, null if not. See Also: Resource |
getSystemClassPath | public static URL[] getSystemClassPath()(Code) | | Gets class path from system.
the system class path represented by anarray of URL objects. |
loadClass | public Class loadClass(String className, boolean resolve) throws ClassNotFoundException(Code) | | Loads and, optionally, resolves the specified class. If the class
needs to be instantiated, the class must be resolved. If only the
existence of the class needs verification, class resolution is
unnecessary.
Calling loadClass(String className) is equivalent to calling
this method with resolve set to true .
Purposely not synchronized. If class is not found in loadedClasses table, then
doLoadClass will do the operation in a synchronized manner.
Parameters: className - The name of the class to be loaded, e.g."com.lutris.util.Table". Parameters: resolve - Set to true for class resolution,false for no resolution. the loaded Class. exception: ClassNotFoundException - if the class could not be load. See Also: MultiClassLoader.setClassPath See Also: MultiClassLoader.addClassPath |
parseClassPath | public static String[] parseClassPath(String path)(Code) | | Parse a class-path string using the system path separator.
|
removeLoadedClass | public void removeLoadedClass()(Code) | | Removes stored data about already loaded classes
|
setClassPath | public void setClassPath(String path)(Code) | | Sets class loader with specified class path. The parameter is
assumed to be either a directory, URL, or zip file.
Parameters: path - The class path to be used when loading classes. |
setClassPath | public synchronized void setClassPath(String[] path)(Code) | | Sets class loader with specified class path. The parameter is
assumed to be an array of directories, URLs, and/or zip files.
Parameters: path - The class path to be used when loading classes. |
setClassPath | public void setClassPath(File path)(Code) | | Sets class loader with specified class path. The parameter is
assumed to be either a zip file or directory.
Parameters: path - The class path to be used when loading classes. |
setClassPath | public synchronized void setClassPath(File[] path)(Code) | | Sets class loader with specified class path. The parameter is
assumed to be an array of zip files and/or directories.
Parameters: path - The class path to be used when loading classes. |
setClassPath | public void setClassPath(URL path)(Code) | | Sets class loader with specified class path. The parameter is
represent a directory or zip file on the local machine or a
remote machine.
Parameters: path - The class path to be used when loading classes. |
setClassPath | public synchronized void setClassPath(URL[] path)(Code) | | Sets class loader with specified class path. The parameter is
represent directories and/or zip files on the local machine and/or
on remote machines.
Parameters: path - The class path to be used when loading classes. |
setParent | public void setParent(ClassLoader parent)(Code) | | Set the parent class loader for delegation.
|
setSecondary | public void setSecondary(ClassLoader secondary)(Code) | | Set the secondary class loader.
|
shouldReload | public boolean shouldReload()(Code) | | Determine if the classes loaded by this class loader have been modified.
If any file associated with loaded in the class loader's class path has
changed, the classes should be reloaded. If the classes need to be
reloaded, a new instance of this class loader must be created
because a particular class loader instance can only load classes
once.
true if the classes should be reloaded,false if not. |
Methods inherited from java.lang.ClassLoader | public synchronized void clearAssertionStatus()(Code)(Java Doc) final protected Class> defineClass(byte[] b, int off, int len) throws ClassFormatError(Code)(Java Doc) final protected Class> defineClass(String name, byte[] b, int off, int len) throws ClassFormatError(Code)(Java Doc) final protected Class> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) throws ClassFormatError(Code)(Java Doc) final protected Class> defineClass(String name, java.nio.ByteBuffer b, ProtectionDomain protectionDomain) throws ClassFormatError(Code)(Java Doc) protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException(Code)(Java Doc) protected Class> findClass(String name) throws ClassNotFoundException(Code)(Java Doc) protected String findLibrary(String libname)(Code)(Java Doc) final protected Class> findLoadedClass(String name)(Code)(Java Doc) protected URL findResource(String name)(Code)(Java Doc) protected Enumeration<URL> findResources(String name) throws IOException(Code)(Java Doc) final protected Class> findSystemClass(String name) throws ClassNotFoundException(Code)(Java Doc) protected Package getPackage(String name)(Code)(Java Doc) protected Package[] getPackages()(Code)(Java Doc) final public ClassLoader getParent()(Code)(Java Doc) public URL getResource(String name)(Code)(Java Doc) public InputStream getResourceAsStream(String name)(Code)(Java Doc) public Enumeration<URL> getResources(String name) throws IOException(Code)(Java Doc) public static ClassLoader getSystemClassLoader()(Code)(Java Doc) public static URL getSystemResource(String name)(Code)(Java Doc) public static InputStream getSystemResourceAsStream(String name)(Code)(Java Doc) public static Enumeration<URL> getSystemResources(String name) throws IOException(Code)(Java Doc) public Class> loadClass(String name) throws ClassNotFoundException(Code)(Java Doc) protected synchronized Class> loadClass(String name, boolean resolve) throws ClassNotFoundException(Code)(Java Doc) final protected void resolveClass(Class> c)(Code)(Java Doc) public synchronized void setClassAssertionStatus(String className, boolean enabled)(Code)(Java Doc) public synchronized void setDefaultAssertionStatus(boolean enabled)(Code)(Java Doc) public synchronized void setPackageAssertionStatus(String packageName, boolean enabled)(Code)(Java Doc) final protected void setSigners(Class> c, Object[] signers)(Code)(Java Doc)
|
|
|