All Packages Class Hierarchy This Package Previous Next Index
Class openstar.generic.Factory
java.lang.Object
|
+----openstar.generic.ParamSet
|
+----openstar.generic.Factory
- public class Factory
- extends ParamSet
Generic factory base class.
This class provides a common framework for the creation of user-defined
objects. It is intended to be used by tools that are also "generic",
in the sense that they provide services or functions to allow users to
create objects by specifying a class name and giving a set of parameters
in a predefined format. One example of such a tool could be a parser for
a specific picture generation method. To support such tools in their
generic behaviour,
it is recommended that the names of concrete factory classes are composed
of the class name of the objects they create, followed by the string
"Factory", for example "FooFactory".
Factory
is a meta-meta factory class, and can also
be called the "mother of all factory base classes". meta factory
classes are derived from Factory
and may
add additional features that are specific to the family of objects being
created. Finally, concrete Factory classes are the ones that
create specific objects within a given family.
- Version:
- 04 Jun 1997
- Author:
- Nils Schwabe
-
ERR_CLASS_NOT_FOUND
- The specified factory class was not found.
-
ERR_INSTANCE_ERROR
- An internal error occurred while instantiating a factory.
-
ERR_NOT_A_FACTORY
- The specified class is not derived from
Factory
.
-
ERR_UNKNOWN_PARAMETER
- The parameter name is not recocgized by this factory.
-
ERR_WRONG_TYPE
- The parameter value is not an instance of a class that
is expected for this parameter.
-
OK
- Everything's just fine.
-
WARN_PARAM_EXISTED
- A parameter with the same name already existed and it has
been replaced by the new parameter.
-
Factory()
-
-
create()
- Creates a new instance.
-
getFactory(String, int[])
-
Creates and returns an instance of a factory.
-
missingParams()
- Returns an array of strings that contain the names
of missing parameters, or
null
if no parameters
are missing.
-
newParam(String, Object)
- Adds a new parameter.
OK
public final static int OK
- Everything's just fine.
ERR_UNKNOWN_PARAMETER
public final static int ERR_UNKNOWN_PARAMETER
- The parameter name is not recocgized by this factory.
ERR_WRONG_TYPE
public final static int ERR_WRONG_TYPE
- The parameter value is not an instance of a class that
is expected for this parameter.
ERR_CLASS_NOT_FOUND
public final static int ERR_CLASS_NOT_FOUND
- The specified factory class was not found.
ERR_INSTANCE_ERROR
public final static int ERR_INSTANCE_ERROR
- An internal error occurred while instantiating a factory.
ERR_NOT_A_FACTORY
public final static int ERR_NOT_A_FACTORY
- The specified class is not derived from
Factory
.
WARN_PARAM_EXISTED
public final static int WARN_PARAM_EXISTED
- A parameter with the same name already existed and it has
been replaced by the new parameter.
Factory
public Factory()
getFactory
public static Factory getFactory(String name,
int error[])
- Creates and returns an instance of a factory.
The factory class is loaded dynamically (if not already loaded
by the system) by using the method Class.forName()
.
The name of the class is composed of the given string, and the
string "Factory". Thus, classes whose names do not end with
"Factory" cannot be loaded with this method.
- Parameters:
- name - Name of the factory class (not including the trailing
"Factory")
- error - If the method returns
null
then the first
element of this array contains one of the defined error codes.
- Returns:
- New factory instance or
null
if an error occured.
newParam
public int newParam(String name,
Object value)
- Adds a new parameter.
missingParams
public String[] missingParams()
- Returns an array of strings that contain the names
of missing parameters, or
null
if no parameters
are missing.
A generic tool should check this
array before trying to create() an instance. If the returned array
is not null
, the user should be asked to provide values
for the missing parameters.
The default implementation of this method returns null
.
create
public abstract Object create()
- Creates a new instance.
This method must be implemented by all meta factory classes.
All Packages Class Hierarchy This Package Previous Next Index