Class PluginClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class PluginClassLoader extends URLClassLoader
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 Details

    • PluginClassLoader

      public PluginClassLoader(String pluginId, URL[] urls, ClassLoader classLoader)
      Constructs a new PluginClassLoader for the specified URLs using the specified parent class loader.
      Parameters:
      pluginId - ID of the plugin being loaded, according to data from Metadata.
      urls - The URLs from which to load classes and resources.
      classLoader - parent ClassLoader.
  • Method Details

    • findLoaded

      public Class<?> findLoaded(String name)
      Finds a loaded class by name. This method is used to check if a class has already been loaded by this class loader.
      Parameters:
      name - The fully qualified name of the desired Class.
      Returns:
      The Class object, or null if the class has not been loaded.
    • getClassByName

      public static Class<?> getClassByName(String name)
      Retrieves the Class 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, or null if the class could not be found.
    • getClasses

      public Set<String> getClasses()
      Retrieves the set of loaded class names.
      Returns:
      A set containing the names of the loaded classes.