org.openxava.util
Class Factory

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

public class Factory
extends java.lang.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 Summary
Factory(java.net.URL propertiesFile)
          Creates a objects factory from a properties files.
Factory(java.net.URL propertiesFile, java.lang.String defaultEntry)
          Creates a object factory from a properties file, sending the entry that indicate the default entry.
 
Method Summary
 java.lang.Object create()
          Create a default object.
 java.lang.Object create(java.lang.String name)
          Create the indicate object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Factory

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

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

Parameters:
propertiesFile - File URL withn pairs names/classes

Factory

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

Preconditions:

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 Detail

create

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

Postcondition:

does it as indicate in the entry default in properties file.

Throws:
InitException - Some problem on init

create

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

Postcondition:

Parameters:
name - Identifier name, which is registered in properties
Throws:
InitException - Si hay alg�n problema el iniciar.