Package org.openxava.util
Class Factory
- java.lang.Object
-
- 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 methodIInit.init(java.lang.String)
is called after creation.
Exists a entry that is assumed as default entry. This entry is used when you call tocreate()
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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
create()
Create a default object.java.lang.Object
create(java.lang.String name)
Create the indicate object.
-
-
-
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:- propertiesFile != null
- 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:
- propertiesFile != null
- Parameters:
propertiesFile
- File URL with pairs names/classesdefaultEntry
- Indicante what entry will be used as default entry, si if isnull
_defecto/_default is used.
-
-
Method Detail
-
create
public java.lang.Object create() throws InitException
Create a default object.Postcondition:
- return != null
- Throws:
InitException
- Some problem on init
-
create
public java.lang.Object create(java.lang.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.
-
-