Package com.avrix.plugin
Class PluginClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
com.avrix.plugin.PluginClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
A custom class loader for loading plugin classes.
Extends
URLClassLoader
to provide functionality for loading classes from a URL
, such as a JAR file.
This class loader is specifically designed to work with plugins, allowing classes to be dynamically loaded and accessed during runtime. It also includes a method to check if a class has already been loaded, which helps prevent duplicate loading of the same class.
-
Constructor Summary
ConstructorDescriptionPluginClassLoader
(String pluginId, URL[] urls, ClassLoader classLoader) Constructs a newPluginClassLoader
for the specifiedURL
s using the specified parent class loader. -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
findLoaded
(String name) Finds a loaded class by name.static Class<?>
getClassByName
(String name) Retrieves theClass
object for a given class name from the cache or loaders.Retrieves the set of loaded class names.Methods inherited from class java.net.URLClassLoader
close, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus
-
Constructor Details
-
PluginClassLoader
Constructs a newPluginClassLoader
for the specifiedURL
s using the specified parent class loader.- Parameters:
pluginId
- ID of the plugin being loaded, according to data fromMetadata
.urls
- TheURL
s from which to load classes and resources.classLoader
- parentClassLoader
.
-
-
Method Details
-
findLoaded
Finds a loaded class by name. This method is used to check if a class has already been loaded by this class loader. -
getClassByName
Retrieves theClass
object for a given class name from the cache or loaders. If the class is not found in the cache, searches through all loaders to find the class.- Parameters:
name
- The fully qualified name of the desired class.- Returns:
- The
Class
object corresponding to the specified name, ornull
if the class could not be found.
-
getClasses
Retrieves the set of loaded class names.- Returns:
- A set containing the names of the loaded classes.
-