Class DynamicClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class DynamicClassLoader extends URLClassLoader
  • Constructor Details

    • DynamicClassLoader

      public DynamicClassLoader(Key name, URL url, ClassLoader parent)
      Construct the class loader
      Parameters:
      name - The unique name of the class loader
      url - A single URL to load from
      parent - The parent class loader to delegate to
    • DynamicClassLoader

      public DynamicClassLoader(Key name, URL[] urls, ClassLoader parent)
      Construct the class loader
      Parameters:
      name - The unique name of the class loader
      urls - The URLs to load from
      parent - The parent class loader to delegate to
    • DynamicClassLoader

      public DynamicClassLoader(Key name, ClassLoader parent)
      Construct the class loader
      Parameters:
      name - The unique name of the class loader
      parent - The parent class loader to delegate to
  • Method Details

    • getNameAsKey

      public Key getNameAsKey()
      Get the name of the class loader as a
      Returns:
      The name of the class loader
    • findClass

      public Class<?> findClass(String className) throws ClassNotFoundException
      Find a class in the class loader or delegate to the parent. If not found, then throw an exception
      Overrides:
      findClass in class URLClassLoader
      Parameters:
      className - The name of the class to find
      Throws:
      ClassNotFoundException
    • findClass

      public Class<?> findClass(String className, Boolean safe) throws ClassNotFoundException
      Find a class in the class loader or delegate to the parent
      Parameters:
      className - The name of the class to find
      safe - Whether to throw an exception if the class is not found
      Throws:
      ClassNotFoundException
    • getDynamicParent

      public ClassLoader getDynamicParent()
      Get the parent class loader
      Returns:
      The parent class loader
    • addURL

      public void addURL(URL url)
      Add a URL to the class loader
      Overrides:
      addURL in class URLClassLoader
      Parameters:
      url - The URL to add
      See Also:
    • addURLs

      public void addURLs(URL[] urls)
      Add an array of URLs to the class loader
      Parameters:
      urls - The URLs to add
      See Also:
    • clearCache

      public void clearCache()
      Clear The cache of loaded classes
    • isCacheEmpty

      public boolean isCacheEmpty()
      Is the cache empty or not
    • isClassInCache

      public boolean isClassInCache(String className)
      Verifies if the passed class name is in the cache
      Parameters:
      className - The name of the class to check
      Returns:
      True if the class is in the cache, false otherwise
    • getCacheKeys

      public Set<String> getCacheKeys()
      Get all the class paths keys in the resolver cache
      Returns:
      The keys in the resolver cache
    • getCacheSize

      public int getCacheSize()
      Size of the cache
      Returns:
      The size of the cache
    • getUnfoundClasses

      public Map<String,Class<?>> getUnfoundClasses()
      Get the cache of unfound classes
      Returns:
      The cache of unfound classes
    • getUnfoundClassesKeys

      public Set<String> getUnfoundClassesKeys()
      Get the set of keys in the unfound class cache
      Returns:
      The keys in the unfound class cache
    • getUnfoundClassesSize

      public int getUnfoundClassesSize()
      How many unfound classes we have found
      Returns:
      The size of the unfound classes
    • clearUnfoundClasses

      public void clearUnfoundClasses()
      Clear the unfound class cache
    • close

      public void close() throws IOException
      Close the class loader
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class URLClassLoader
      Throws:
      IOException
    • getJarURLs

      public static URL[] getJarURLs(String targetPath) throws IOException
      Static method that takes in a String path and returns an array of URLs of all the JARs/clases in the path
      Parameters:
      targetPath - The path to search for JARs
      Returns:
      An array of URLs of all the JARs in the path
      Throws:
      IOException
    • getJarURLs

      public static URL[] getJarURLs(Path targetPath) throws IOException
      Static method that takes in a path and returns an array of URLs of all the JARs in the path
      Parameters:
      targetPath - The path to search for JARs
      Returns:
      An array of URLs of all the JARs in the path
      Throws:
      IOException
    • inflateClassPaths

      public static URL[] inflateClassPaths(Array paths)
      Goes through an array of path locations and inflates them into an array of URLs of all the JARs and classes in the paths
      Parameters:
      paths - An array of paths' to inflate
      Returns:
      The URLs of jars and classes