Package org.gvsig.andami.plugins
Class PluginClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.gvsig.andami.plugins.PluginClassLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
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.
- Author:
- Fernando Gonz�lez Cort�s
-
Constructor Summary
ConstructorsConstructorDescriptionPluginClassLoader(URL[] jars, String baseDir, ClassLoader cl, List<PluginClassLoader> pluginLoaders) PluginClassLoader(URL[] jars, String baseDir, ClassLoader cl, PluginClassLoader[] pluginLoaders) Creates a new PluginClassLoader object. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddLoaders(ArrayList classLoaders) Adds other classloader to use when all the normal methods fail.voidaddPluginClassLoader(PluginClassLoader pluginClassLoader) voidGets the plugin's base Iteratorinvalid input: '<'Map.Entryinvalid input: '<'Integer, Integer>>dir, the directory which will be used to search resources.protected PermissionCollectiongetPermissions(CodeSource codesource) Returns the name of the plugin (the name of the directory containing the plugin).getResource(String res) Gets the requested resource.getResources(String name) protected Enumeration<URL> getResources(String name, HashSet<PluginClassLoader> visitedPlugins) protected ClassCarga la claseprotected ClasssingleLoadClass(String name) toString()Methods inherited from class java.net.URLClassLoader
close, definePackage, findClass, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
PluginClassLoader
public PluginClassLoader(URL[] jars, String baseDir, ClassLoader cl, PluginClassLoader[] pluginLoaders) throws IOException Creates a new PluginClassLoader object.- Parameters:
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 thegetResourcesmethod.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.- Throws:
IOException
-
PluginClassLoader
public PluginClassLoader(URL[] jars, String baseDir, ClassLoader cl, List<PluginClassLoader> pluginLoaders) throws IOException - Throws:
IOException
-
-
Method Details
-
singleLoadClass
- Throws:
ClassNotFoundException
-
loadClass
Carga la clase- Overrides:
loadClassin classClassLoader- Parameters:
name- Nombre de la claseresolve- Si se ha de resolver la clase o no- Returns:
- Clase cargada
- Throws:
ClassNotFoundException- Si no se pudo encontrar la clase
-
getResource
Gets the requested resource. If the path is relative, its base directory will be the one provided in the PluginClassLoader's constructor. If the resource is not found, search in dependents plugins, otherwise the parent classloader will be invoked to try to get it. If it is not found, it will return null.- Overrides:
getResourcein classClassLoader- Parameters:
res- An absolute or relative path to the requested resource.- Returns:
- Resource's URL if it was found, nul otherwise.
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResources
protected Enumeration<URL> getResources(String name, HashSet<PluginClassLoader> visitedPlugins) throws IOException - Throws:
IOException
-
getPluginName
Returns the name of the plugin (the name of the directory containing the plugin).- Returns:
- An String containing the plugin's name.
-
getPermissions
- Overrides:
getPermissionsin classURLClassLoader
-
getBaseDir
Gets the plugin's base Iteratorinvalid input: '<'Map.Entryinvalid input: '<'Integer, Integer>>dir, the directory which will be used to search resources.- Returns:
- Returns the baseDir.
-
addLoaders
Adds other classloader to use when all the normal methods fail.- Parameters:
classLoaders- An ArrayList of ClassLoaders which will be used to load classes when all the normal methods fail.
-
toString
-
addPluginClassLoader
-
addURL
- Overrides:
addURLin classURLClassLoader
-