public class PluginClassLoader
extends java.net.URLClassLoader
Class loader which loads the classes requested by the plugins. It first tries
to search in the classpath, then it requests the class to the parent
classloader, then it searches in the owns plugins' library dir, and if all
these methods fail, it tries to load the class from any of the depended
plugins. Finally, if this also fails, the other classloaders provided in the
addLoaders
method are requested to load the class.
The class loader can also be used to load resources from the plugin's
directory by using the getResource()
method.
Constructor and Description |
---|
PluginClassLoader(java.net.URL[] jars,
java.lang.String baseDir,
java.lang.ClassLoader cl,
java.util.List<PluginClassLoader> pluginLoaders) |
PluginClassLoader(java.net.URL[] jars,
java.lang.String baseDir,
java.lang.ClassLoader cl,
PluginClassLoader[] pluginLoaders)
Creates a new PluginClassLoader object.
|
Modifier and Type | Method and Description |
---|---|
static void |
addLoaders(java.util.ArrayList classLoaders)
Adds other classloader to use when all the normal methods fail.
|
void |
addPluginClassLoader(PluginClassLoader pluginClassLoader) |
void |
addURL(java.net.URL url) |
java.lang.String |
getBaseDir()
Gets the plugin's base Iterator
|
protected java.security.PermissionCollection |
getPermissions(java.security.CodeSource codesource) |
java.lang.String |
getPluginName()
Returns the name of the plugin (the name of the directory containing the
plugin).
|
java.net.URL |
getResource(java.lang.String res)
Gets the requested resource.
|
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name) |
protected java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name,
java.util.HashSet<PluginClassLoader> visitedPlugins) |
protected java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Carga la clase
|
protected java.lang.Class |
singleLoadClass(java.lang.String name) |
java.lang.String |
toString() |
close, definePackage, findClass, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public PluginClassLoader(java.net.URL[] jars, java.lang.String baseDir, java.lang.ClassLoader cl, PluginClassLoader[] pluginLoaders) throws java.io.IOException
jars
- Array with the search paths where classes will be searchedbaseDir
- Base directory for this plugin. This is the directory
which will be used as basedir in the getResources
method.cl
- The parent classloader of this classloader. It will be used to
search classes before trying to search in the plugin's directorypluginLoaders
- The classloaders of the depended plugins.java.io.IOException
public PluginClassLoader(java.net.URL[] jars, java.lang.String baseDir, java.lang.ClassLoader cl, java.util.List<PluginClassLoader> pluginLoaders) throws java.io.IOException
java.io.IOException
protected java.lang.Class singleLoadClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
name
- Nombre de la claseresolve
- Si se ha de resolver la clase o nojava.lang.ClassNotFoundException
- Si no se pudo encontrar la clasepublic java.net.URL getResource(java.lang.String res)
getResource
in class java.lang.ClassLoader
res
- An absolute or relative path to the requested resource.public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException
getResources
in class java.lang.ClassLoader
java.io.IOException
protected java.util.Enumeration<java.net.URL> getResources(java.lang.String name, java.util.HashSet<PluginClassLoader> visitedPlugins) throws java.io.IOException
java.io.IOException
public java.lang.String getPluginName()
protected java.security.PermissionCollection getPermissions(java.security.CodeSource codesource)
getPermissions
in class java.net.URLClassLoader
public java.lang.String getBaseDir()
public static void addLoaders(java.util.ArrayList classLoaders)
classLoaders
- An ArrayList of ClassLoaders which will be used to
load classes when all the normal methods fail.public java.lang.String toString()
toString
in class java.lang.Object
public void addPluginClassLoader(PluginClassLoader pluginClassLoader)
public void addURL(java.net.URL url)
addURL
in class java.net.URLClassLoader