Package com.comphenix.protocol.utility
Class ClassSource
java.lang.Object
com.comphenix.protocol.utility.ClassSource
Represents an abstract class loader that can only retrieve classes by their canonical name.
- Author:
- Kristian
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringAppend to canonical names together.static ClassSourceattemptLoadFrom(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.static ClassSourceempty()static ClassSourceConstruct a class source from the default class loader.static ClassSourcefromClassLoader(ClassLoader loader)Construct a class source from the given class loader.static ClassSourceConstruct a class source from a mapping of canonical names and the corresponding classes.static ClassSourcefromPackage(String packageName)Construct a class source from the default class loader and package.abstract Class<?>Retrieve a class by name.retry(ClassSource other)Retrieve a class source that will retry failed lookups in the given source.usingPackage(String packageName)Retrieve a class source that prepends a specific package name to every lookup.
-
Constructor Details
-
ClassSource
public ClassSource()
-
-
Method Details
-
fromClassLoader
Construct a class source from the default class loader.- Returns:
- A class source.
-
fromPackage
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
Construct a class source from the given class loader.- Parameters:
loader- - the class loader.- Returns:
- The corresponding class source.
-
fromMap
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, aClassNotFoundExceptionwill be thrown.- Parameters:
map- - map of class names and classes.- Returns:
- The class source.
-
empty
- Returns:
- A ClassLoader which will never successfully load a class.
-
attemptLoadFrom
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
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
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
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
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
ClassNotFoundExceptionexception should be thrown. - Throws:
ClassNotFoundException- If the class could not be found.
-