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

Variable Index

 o ERR_CLASS_NOT_FOUND
The specified factory class was not found.
 o ERR_INSTANCE_ERROR
An internal error occurred while instantiating a factory.
 o ERR_NOT_A_FACTORY
The specified class is not derived from Factory.
 o ERR_UNKNOWN_PARAMETER
The parameter name is not recocgized by this factory.
 o ERR_WRONG_TYPE
The parameter value is not an instance of a class that is expected for this parameter.
 o OK
Everything's just fine.
 o WARN_PARAM_EXISTED
A parameter with the same name already existed and it has been replaced by the new parameter.

Constructor Index

 o Factory()

Method Index

 o create()
Creates a new instance.
 o getFactory(String, int[])
Creates and returns an instance of a factory.
 o missingParams()
Returns an array of strings that contain the names of missing parameters, or null if no parameters are missing.
 o newParam(String, Object)
Adds a new parameter.

Variables

 o OK
  public final static int OK
Everything's just fine.

 o ERR_UNKNOWN_PARAMETER
  public final static int ERR_UNKNOWN_PARAMETER
The parameter name is not recocgized by this factory.

 o 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.

 o ERR_CLASS_NOT_FOUND
  public final static int ERR_CLASS_NOT_FOUND
The specified factory class was not found.

 o ERR_INSTANCE_ERROR
  public final static int ERR_INSTANCE_ERROR
An internal error occurred while instantiating a factory.

 o ERR_NOT_A_FACTORY
  public final static int ERR_NOT_A_FACTORY
The specified class is not derived from Factory.

 o 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.

Constructors

 o Factory
  public Factory()

Methods

 o 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.
 o newParam
  public int newParam(String name,
                      Object value)
Adds a new parameter.

 o 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.

 o 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