Package migratedb.core.internal.util
Enum ClassUtils
- java.lang.Object
-
- java.lang.Enum<ClassUtils>
-
- migratedb.core.internal.util.ClassUtils
-
- All Implemented Interfaces:
Serializable,Comparable<ClassUtils>
public enum ClassUtils extends Enum<ClassUtils>
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ClassLoaderdefaultClassLoader()static StringgetClassName(@Nullable Object obj)static StringgetStaticFieldValue(Class<?> clazz, String fieldName)Gets the String value of a static field.static StringgetStaticFieldValue(String className, String fieldName, ClassLoader classLoader)Gets the String value of a static field.static PathguessLocationOnDisk(Class<?> aClass)Tries to get the physical location on disk ofaClass.static <T> Tinstantiate(Class<T> clazz)Creates a new instance ofclazz.static <T> Tinstantiate(String className, ClassLoader classLoader)Creates a new instance of this class.static <T> List<T>instantiateAll(String[] classes, ClassLoader classLoader)Instantiate all these classes.static <E extends Exception>
Objectinvoke(Class<?> clazz, String methodName, Object receiver, Class<?>[] paramTypes, Object[] params, Function<? super Throwable,@Nullable E> exceptionMapper)static booleanisImplementationPresent(String serviceName, ClassLoader classLoader)Determine whether a class implementing the service identified by the supplied name is present and can be loaded.static booleanisPresent(String className, ClassLoader classLoader)Determine whether theClassidentified by the supplied name is present and can be loaded.static Class<?>loadClass(String className, ClassLoader classLoader)LoadsclassNameusing the class loader.static ClassUtilsvalueOf(String name)Returns the enum constant of this type with the specified name.static ClassUtils[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Method Detail
-
values
public static ClassUtils[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ClassUtils c : ClassUtils.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ClassUtils valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
instantiate
public static <T> T instantiate(String className, ClassLoader classLoader)
Creates a new instance of this class.- Type Parameters:
T- The type of the new instance.- Parameters:
className- The fully qualified name of the class to instantiate.classLoader- The ClassLoader to use.- Returns:
- The new instance.
- Throws:
MigrateDbException- Thrown when the instantiation failed.
-
instantiate
public static <T> T instantiate(Class<T> clazz)
Creates a new instance ofclazz.- Type Parameters:
T- The type of the new instance.- Returns:
- The new instance.
- Throws:
MigrateDbException- Thrown when the instantiation failed.
-
instantiateAll
public static <T> List<T> instantiateAll(String[] classes, ClassLoader classLoader)
Instantiate all these classes.- Type Parameters:
T- The common type for all classes.- Parameters:
classes- Fully qualified class names to instantiate.classLoader- The ClassLoader to use.- Returns:
- The list of instances.
-
isPresent
public static boolean isPresent(String className, ClassLoader classLoader)
Determine whether theClassidentified by the supplied name is present and can be loaded. Will returnfalseif either the class or one of its dependencies is not present or cannot be loaded.- Parameters:
className- The name of the class to check.classLoader- The ClassLoader to use.- Returns:
- whether the specified class is present
-
isImplementationPresent
public static boolean isImplementationPresent(String serviceName, ClassLoader classLoader)
Determine whether a class implementing the service identified by the supplied name is present and can be loaded. Will returnfalseif either no class is found, or the class or one of its dependencies is not present or cannot be loaded.- Parameters:
serviceName- The name of the service to check.classLoader- The ClassLoader to use.- Returns:
- whether an implementation of the specified service is present
-
loadClass
public static Class<?> loadClass(String className, ClassLoader classLoader)
LoadsclassNameusing the class loader.- Parameters:
className- The name of the class to load.classLoader- The ClassLoader to use.- Returns:
- the newly loaded class
-
guessLocationOnDisk
public static Path guessLocationOnDisk(Class<?> aClass)
Tries to get the physical location on disk ofaClass.- Parameters:
aClass- The class to get the location for.- Returns:
- The absolute path of the .class file (or null).
-
getStaticFieldValue
public static String getStaticFieldValue(String className, String fieldName, ClassLoader classLoader)
Gets the String value of a static field.- Parameters:
className- The fully qualified name of the class to instantiate.classLoader- The ClassLoader to use.fieldName- The field name- Returns:
- The value of the field.
- Throws:
MigrateDbException- If the field value cannot be read.
-
getStaticFieldValue
public static String getStaticFieldValue(Class<?> clazz, String fieldName)
Gets the String value of a static field.- Throws:
MigrateDbException- If the field value cannot be read.
-
defaultClassLoader
public static ClassLoader defaultClassLoader()
- Returns:
- The first class loader that is non-null:
- Thread context class loader
- Class loader of this class
- System class loader
-
invoke
public static <E extends Exception> Object invoke(Class<?> clazz, String methodName, Object receiver, Class<?>[] paramTypes, Object[] params, Function<? super Throwable,@Nullable E> exceptionMapper) throws E extends Exception
- Throws:
E extends Exception
-
-