Package jcckit.util

Class Factory


  • public class Factory
    extends Object
    General purpose factory method based on ConfigParameters and Java's Reflection API.
    Author:
    Franz-Josef Elmer
    • Field Detail

    • Method Detail

      • create

        public static Object create​(String className)
        Creates an instance of the specified class.
        Parameters:
        className - Fully-qualified name of a class with a default constructor.
        Returns:
        a new instance.
        Throws:
        IllegalArgumentException - if the instance could be created.
      • create

        public static Object create​(ConfigParameters configParameters)
        Creates an object based on the specified configuration parameters. The class of the object is determined by the parameter with the key CLASS_NAME_KEY. The constructor with a single argument of the type ConfigParameter is invoked with the argument configParameters. If such a constructor does not exists the default constructor is invoked. If neither of these constructors exist a FactoryException is thrown.
        Parameters:
        configParameters - Configuration parameters.
        Returns:
        the newly created object.
        Throws:
        IllegalArgumentException - if key className is missing.
        FactoryException - wrapping any kind of exception or error occured.
      • create

        public static Object create​(ConfigParameters configParameters,
                                    String defaultClassName)
        Creates an object based on the specified configuration parameters and default class name. If the parameter with the key CLASS_NAME_KEY is missed in configParameters defaultClassName is used. Otherwise it works as create(jcckit.util.ConfigParameters).
        Parameters:
        configParameters - Configuration parameters.
        defaultClassName - Default class name.
        Returns:
        the newly created object.
        Throws:
        FactoryException - wrapping any kind of exception or error occured.
      • createOrGet

        public static Object createOrGet​(ConfigParameters configParameters,
                                         Object defaultObject)
        Creates an object based on the specified configuration parameters or returns the default object. This method behaves as create(jcckit.util.ConfigParameters), except that is does not throw an IllegalArgumentException if key className is missing. Instead defaultObject is returned.