Class ClassSource

java.lang.Object
com.comphenix.protocol.utility.ClassSource

public abstract class ClassSource extends Object
Represents an abstract class loader that can only retrieve classes by their canonical name.
Author:
Kristian
  • Constructor Details

    • ClassSource

      public ClassSource()
  • Method Details

    • fromClassLoader

      public static ClassSource fromClassLoader()
      Construct a class source from the default class loader.
      Returns:
      A class source.
    • fromPackage

      public static ClassSource fromPackage(String packageName)
      Construct a class source from the default class loader and package.
      Parameters:
      packageName - - the package that is prepended to every lookup.
      Returns:
      A package source.
    • fromClassLoader

      public static ClassSource fromClassLoader(ClassLoader loader)
      Construct a class source from the given class loader.
      Parameters:
      loader - - the class loader.
      Returns:
      The corresponding class source.
    • fromMap

      public static ClassSource fromMap(Map<String,​Class<?>> map)
      Construct a class source from a mapping of canonical names and the corresponding classes. If the map is null, it will be interpreted as an empty map. If the map does not contain a Class with the specified name, or that string maps to NULL explicitly, a ClassNotFoundException will be thrown.
      Parameters:
      map - - map of class names and classes.
      Returns:
      The class source.
    • empty

      public static ClassSource empty()
      Returns:
      A ClassLoader which will never successfully load a class.
    • attemptLoadFrom

      public static ClassSource attemptLoadFrom(ClassSource... sources)
      Retrieve a class source that will attempt lookups in each of the given sources in the order they are in the array, and return the first value that is found. If the sources array is null or composed of any null elements, an exception will be thrown.
      Parameters:
      sources - - the class sources.
      Returns:
      A new class source.
    • retry

      public ClassSource retry(ClassSource other)
      Retrieve a class source that will retry failed lookups in the given source.
      Parameters:
      other - - the other class source.
      Returns:
      A new class source.
    • usingPackage

      public ClassSource usingPackage(String packageName)
      Retrieve a class source that prepends a specific package name to every lookup.
      Parameters:
      packageName - - the package name to prepend.
      Returns:
      The class source.
    • append

      protected static String append(String a, String b)
      Append to canonical names together.
      Parameters:
      a - - the name to the left.
      b - - the name to the right.
      Returns:
      The full canonical name, with a dot seperator.
    • loadClass

      public abstract Class<?> loadClass(String canonicalName) throws ClassNotFoundException
      Retrieve a class by name.
      Parameters:
      canonicalName - - the full canonical name of the class.
      Returns:
      The corresponding class. If the class is not found, NULL should not be returned, instead a ClassNotFoundException exception should be thrown.
      Throws:
      ClassNotFoundException - If the class could not be found.