Class FactoryFinder


  • final class FactoryFinder
    extends java.lang.Object
    Factory finder utility class.
    Since:
    2.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.logging.Logger LOGGER  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FactoryFinder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T> java.lang.Object find​(java.lang.String factoryId, java.lang.String fallbackClassName, java.lang.Class<T> service)
      Finds the implementation Class for the given factory name, or if that fails, finds the Class for the given fallback class name and create its instance.
      private static java.lang.ClassLoader getContextClassLoader()  
      private static java.lang.Object newInstance​(java.lang.String className, java.lang.ClassLoader classLoader)
      Creates an instance of the specified class using the specified ClassLoader object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
    • Constructor Detail

      • FactoryFinder

        private FactoryFinder()
    • Method Detail

      • getContextClassLoader

        private static java.lang.ClassLoader getContextClassLoader()
      • newInstance

        private static java.lang.Object newInstance​(java.lang.String className,
                                                    java.lang.ClassLoader classLoader)
                                             throws java.lang.ClassNotFoundException
        Creates an instance of the specified class using the specified ClassLoader object.
        Parameters:
        className - name of the class to be instantiated.
        classLoader - class loader to be used.
        Returns:
        instance of the specified class.
        Throws:
        java.lang.ClassNotFoundException - if the given class could not be found or could not be instantiated.
      • find

        static <T> java.lang.Object find​(java.lang.String factoryId,
                                         java.lang.String fallbackClassName,
                                         java.lang.Class<T> service)
                                  throws java.lang.ClassNotFoundException
        Finds the implementation Class for the given factory name, or if that fails, finds the Class for the given fallback class name and create its instance. The arguments supplied MUST be used in order. If using the first argument is successful, the second one will not be used.

        This method is package private so that this code can be shared.

        Type Parameters:
        T - type of the service to be found.
        Parameters:
        factoryId - the name of the factory to find, which is a system property.
        fallbackClassName - the implementation class name, which is to be used only if nothing else. is found; null to indicate that there is no fallback class name.
        service - service to be found.
        Returns:
        the instance of the specified service; may not be null.
        Throws:
        java.lang.ClassNotFoundException - if the given class could not be found or could not be instantiated.