Class ClassLoaderUtils
java.lang.Object
com.ultikits.ultitools.utils.ClassLoaderUtils
Helpers for framework and module class loading and for loading with an explicit owner loader.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoaderGet the shared loader for framework and module classes, not for external plugin classes.static Class<?> Load a framework or module class with name-format validation.static Class<?> Load a framework or module class with initialization control and name-format validation.static Class<?> loadClass(String className, ClassLoader owner) Load a class by validating its name and delegating to the supplied owner loader.static Class<?> loadPluginClass(String className) Load and validate an UltiToolsPlugin subclass using the shared module loader.static booleanvalidateClassLoaderHierarchy(ClassLoader classLoader) Validate a class loader's parent hierarchy against the shared framework and module loader.private static voidvalidateClassName(String className) Validate class name format.
-
Field Details
-
VALID_CLASS_NAME_PATTERN
-
-
Constructor Details
-
ClassLoaderUtils
public ClassLoaderUtils()
-
-
Method Details
-
validateClassName
Validate class name format.This is input validation, not a security boundary. Null, blank and malformed names are rejected before the classloader is called.
- Parameters:
className- class name to validate- Throws:
SecurityException- if the class name is null or does not match the expected format
-
getPluginClassLoader
Get the shared loader for framework and module classes, not for external plugin classes.- Returns:
- framework and module class loader
-
loadClass
Load a framework or module class with name-format validation. This method does not use an external plugin's own loader: for an external plugin class, callloadClasson that plugin's class loader directly.- Parameters:
className- class name- Returns:
- loaded class
- Throws:
ClassNotFoundException- if class not foundSecurityException- if the class name format is invalid
-
loadClass
@Internal public static Class<?> loadClass(String className, ClassLoader owner) throws ClassNotFoundException, SecurityException Load a class by validating its name and delegating to the supplied owner loader. This method does not request class initialization.For framework use only. Modules should not call this method. It is not covered by the public API compatibility policy and may change or be removed in any release.
- Parameters:
className- class nameowner- non-null class loader to use for lookup; there is no fallback loader- Returns:
- loaded class
- Throws:
ClassNotFoundException- if the owner loader cannot find the class; the loader's exception is the causeNullPointerException- if the name is valid and the owner loader is nullSecurityException- if the class name is null or malformed, even if the owner loader is null
-
loadClass
public static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException, SecurityException Load a framework or module class with initialization control and name-format validation. This does not use an external plugin's own loader.- Parameters:
className- class nameinitialize- whether to initialize the class- Returns:
- loaded class
- Throws:
ClassNotFoundException- if class not foundSecurityException- if the class name format is invalid
-
loadPluginClass
public static Class<?> loadPluginClass(String className) throws ClassNotFoundException, SecurityException Load and validate an UltiToolsPlugin subclass using the shared module loader. This method is not for external Bukkit plugin classes.- Parameters:
className- class name- Returns:
- loaded plugin class
- Throws:
ClassNotFoundException- if class not foundSecurityException- if the class name or plugin hierarchy is invalid
-
validateClassLoaderHierarchy
Validate a class loader's parent hierarchy against the shared framework and module loader. External Bukkit plugin loaders are not required to use this hierarchy.- Parameters:
classLoader- class loader to validate- Returns:
- true if valid, false otherwise
-