Package net.minestom.server.extras.selfmodification

# Class HierarchyClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
net.minestom.server.extras.selfmodification.HierarchyClassLoader

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `MinestomExtensionClassLoader`, `MinestomRootClassLoader`

public abstract class HierarchyClassLoader extends URLClassLoader
Classloader part of a hierarchy of classloader.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final List<MinestomExtensionClassLoader>`
  `children`
  `protected final List<HierarchyClassLoader>`
  `parents`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HierarchyClassLoader(String name, URL[] urls, ClassLoader parent)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addChild(@NotNull MinestomExtensionClassLoader loader)`
  `String`
  `findLibrary(String libname)`
  `String`
  `getName()`
  `@Nullable InputStream`
  `getResourceAsStreamWithChildren(@NotNull String name)`
  Finds a resource under the given name within this classloader, or if that fails, in any of its children.
  `@Nullable URL`
  `getResourceAsURLWithChildren(@NotNull String name)`
  Finds a resource under the given name within this classloader, or if that fails, in any of its children.
  `void`
  `removeChildInHierarchy(MinestomExtensionClassLoader child)`

  ### Methods inherited from class java.net.URLClassLoader

  `addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance`

  ### Methods inherited from class java.security.SecureClassLoader

  `defineClass, defineClass`

  ### Methods inherited from class java.lang.ClassLoader

  `clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### children

    protected final List<MinestomExtensionClassLoader> children

  - ### parents

    protected final List<HierarchyClassLoader> parents

- ## Constructor Details

  - ### HierarchyClassLoader

    public HierarchyClassLoader(String name, URL[] urls, ClassLoader parent)

- ## Method Details

  - ### addChild

    public void addChild(@NotNull @NotNull MinestomExtensionClassLoader loader)

  - ### findLibrary

    public String findLibrary(String libname)
    Overrides:
      `findLibrary` in class `ClassLoader`

  - ### getResourceAsStreamWithChildren

    @Nullable public @Nullable InputStream getResourceAsStreamWithChildren(@NotNull @NotNull String name)
    Finds a resource under the given name within this classloader, or if that fails, in any of its children. If the resource is found, the resource is opened as an `InputStream`, otherwise `null` is returned.

    This method distinguishes itself from `URLClassLoader.getResourceAsStream(String)`, which will first query the parent classloader and only then this classloader. Further, `URLClassLoader.getResourceAsStream(String)` does not query children classloaders.

    When failing to open a resource using `URL.openStream()`, the resource is deemed to no exist in this classloader and will search in children classloaders.

    The `InputStream` returned by this method must be closed manually, it is unspecified whether the returned object will be closed whenever this classloader is closed. A warning will be logged in that circumstance.

    Parameters:
      `name` - The pathname of the resource. See `URLClassLoader.findResource(String)`.
    Returns:
      The `InputStream` of the corresponding found resource, or null if such a resource does not exist.
    Since:
      0.0.1
    Implementation Note:
      Search occurs depth-first, which means that registration order can matter quite a lot.

  - ### getResourceAsURLWithChildren

    @Nullable @AvailableSince("4.0.0-a20241006") public @Nullable URL getResourceAsURLWithChildren(@NotNull @NotNull String name)
    Finds a resource under the given name within this classloader, or if that fails, in any of its children. If the resource is found, the resource is returned as an URL, otherwise `null` is returned.

    This method distinguishes itself from `ClassLoader.getResource(String)`, which will first query the parent classloader and only then this classloader. Further, `ClassLoader.getResource(String)` does not query children classloaders.

    Parameters:
      `name` - The pathname of the resource.
    Returns:
      The `URL` of the corresponding found resource, or null if such a resource does not exist.
    Since:
      4.0.0-a20241006
    Implementation Note:
      Search occurs depth-first, which means that registration order can matter quite a lot.

  - ### removeChildInHierarchy

    public void removeChildInHierarchy(MinestomExtensionClassLoader child)

  - ### getName

    public String getName()
    Overrides:
      `getName` in class `ClassLoader`