Class Factory

java.lang.Object
org.openxava.util.Factory

public class Factory extends Object
Generic class to implement object factories.

The classes are in a properties file with name=class formate. Where nombre is a identifier and class the class of object to create, which must to have a default constructor.

If the class implements IInit then the method IInit.init(java.lang.String) is called after creation.
Exists a entry that is assumed as default entry. This entry is used when you call to create() without arguments.
The default entry can be defined on create the factory or if not the entry _default/_defecto is assumed.
A example of properties file is:

 _defecto=rapido
 rapido=miempresa.miapp.paquete1.MiClaseRapida
 lento=miempresa.miapp.paquete1.MiClaseLenta
 
Or in english _default=fast fast=mycorp.myapp.package1.MyFastClass slow=mycorp.myapp.package1.MySlowClass
Author:
Javier Paniza
  • Constructor Details

    • Factory

      public Factory(URL propertiesFile)
      Creates a objects factory from a properties files.

      The entry that indicate the default entry is _defecto or _default.
      Preconditions:

      • propertiesFile != null
      Parameters:
      propertiesFile - File URL withn pairs names/classes
    • Factory

      public Factory(URL propertiesFile, String defaultEntry)
      Creates a object factory from a properties file, sending the entry that indicate the default entry.

      Preconditions:

      • propertiesFile != null
      Parameters:
      propertiesFile - File URL with pairs names/classes
      defaultEntry - Indicante what entry will be used as default entry, si if is null _defecto/_default is used.
  • Method Details

    • create

      public Object create() throws InitException
      Create a default object.

      Postcondition:

      • return != null
      does it as indicate in the entry default in properties file.
      Throws:
      InitException - Some problem on init
    • create

      public Object create(String name) throws InitException
      Create the indicate object.

      Postcondition:

      • return != null
      Parameters:
      name - Identifier name, which is registered in properties
      Throws:
      InitException - Si hay algĂșn problema el iniciar.