Class ClassUtils


  • public final class ClassUtils
    extends Object
    • Constructor Detail

      • ClassUtils

        public ClassUtils()
    • Method Detail

      • instantiate

        public static <T> T instantiate​(String className,
                                        @Nullable ClassLoader classLoader)
        Creates a new instance of a 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.
      • instantiateAll

        public static <T> List<T> instantiateAll​(Collection<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 the Class identified by the supplied name is present and can be loaded. Will return false if 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 return false if 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)
        Loads className using 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 of aClass.
        Parameters:
        aClass - The class to get the location for.
        Returns:
        The absolute path of the .class file (or null).
      • defaultClassLoader

        public static ClassLoader defaultClassLoader()
        Returns:
        The first class loader that is non-null:
        1. Thread context class loader
        2. Class loader of this class
        3. System class loader