Package jcckit.util
Class Factory
- java.lang.Object
-
- jcckit.util.Factory
-
public class Factory extends java.lang.ObjectGeneral purpose factory method based onConfigParametersand Java's Reflection API.- Author:
- Franz-Josef Elmer
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_NAME_KEYThe constant defining the key className.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectcreate(java.lang.String className)Creates an instance of the specified class.static java.lang.Objectcreate(ConfigParameters configParameters)Creates an object based on the specified configuration parameters.static java.lang.Objectcreate(ConfigParameters configParameters, java.lang.String defaultClassName)Creates an object based on the specified configuration parameters and default class name.static java.lang.ObjectcreateOrGet(ConfigParameters configParameters, java.lang.Object defaultObject)Creates an object based on the specified configuration parameters or returns the default object.
-
-
-
Field Detail
-
CLASS_NAME_KEY
public static final java.lang.String CLASS_NAME_KEY
The constant defining the key className.- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static java.lang.Object create(java.lang.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:
java.lang.IllegalArgumentException- if the instance could be created.
-
create
public static java.lang.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 keyCLASS_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 aFactoryExceptionis thrown.- Parameters:
configParameters- Configuration parameters.- Returns:
- the newly created object.
- Throws:
java.lang.IllegalArgumentException- if key className is missing.FactoryException- wrapping any kind of exception or error occured.
-
create
public static java.lang.Object create(ConfigParameters configParameters, java.lang.String defaultClassName)
Creates an object based on the specified configuration parameters and default class name. If the parameter with the keyCLASS_NAME_KEYis missed in configParameters defaultClassName is used. Otherwise it works ascreate(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 java.lang.Object createOrGet(ConfigParameters configParameters, java.lang.Object defaultObject)
Creates an object based on the specified configuration parameters or returns the default object. This method behaves ascreate(jcckit.util.ConfigParameters), except that is does not throw an IllegalArgumentException if key className is missing. Instead defaultObject is returned.
-
-