planet.generic.commonapi.factory
Class ApplicationFactoryImpl

java.lang.Object
  extended byplanet.generic.commonapi.factory.ApplicationFactoryImpl
All Implemented Interfaces:
ApplicationFactory

public class ApplicationFactoryImpl
extends java.lang.Object
implements ApplicationFactory

This factory abstracts the functionality of builds new instances of Application. It is based with only one parameter contained in a properties file:

This property can too be modified by invoking methods, of course.

The concrete implementation of Application must have two constructors to execute without any problem:
  1. Constructor(): A constructor without parameters. In this case, the name of its instances are named by implementation owner.
  2. Constructor(String): A constructor with only one parameter. It is the name of the new instance of Application.

Author:
Jordi Pujol

Field Summary
protected  java.lang.Class appClass
          Class for Applications to build.
protected  java.lang.reflect.Constructor appConstructor
          Constructor for applications with some parameter.
protected static java.lang.String DEFAULT_APPLICATION
          The default key specified in the properties file that identifies the class of some Application's implementation.
protected  java.lang.String propertiesFile
          Properties file to be read to capture the defaultApplication.
 
Constructor Summary
ApplicationFactoryImpl(java.lang.Class appClass)
          This constructor reads the properties' file and initializes the Class for new Applications.
ApplicationFactoryImpl(java.lang.String propertiesFile)
          This constructor reads the properties' file and initializes the Class for new Applications.
 
Method Summary
 Application build()
          Builds a new instance of the actual Application's class with the default name.
 Application build(java.lang.String app)
          Builds a new instance of the specified Application's class app with the default name.
 Application buildWithName(java.lang.String name)
          Generates a new instance of the actual class of Application.
 Application buildWithName(java.lang.String app, java.lang.String name)
          Generates a new instance of the specified Application class app.
 java.lang.String getApplicationClass()
          Gets the Application classname actually in use.
 void setApplicationClass(java.lang.String app)
          Sets the Application classname to use in the future.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_APPLICATION

protected static final java.lang.String DEFAULT_APPLICATION
The default key specified in the properties file that identifies the class of some Application's implementation.

See Also:
Constant Field Values

appClass

protected java.lang.Class appClass
Class for Applications to build.


appConstructor

protected java.lang.reflect.Constructor appConstructor
Constructor for applications with some parameter.


propertiesFile

protected java.lang.String propertiesFile
Properties file to be read to capture the defaultApplication.

Constructor Detail

ApplicationFactoryImpl

public ApplicationFactoryImpl(java.lang.String propertiesFile)
                       throws InitializationException
This constructor reads the properties' file and initializes the Class for new Applications. If occur any problem with this initialization, throws an InitializationException exception with short description for the problem.

Parameters:
propertiesFile - Properties' file that contains the data to be read for this ApplicationFactory.
Throws:
InitializationException - If occur any problem during initialization steps.

ApplicationFactoryImpl

public ApplicationFactoryImpl(java.lang.Class appClass)
                       throws InitializationException
This constructor reads the properties' file and initializes the Class for new Applications. If occur any problem with this initialization, throws an InitializationException exception with short description for the problem.

Throws:
InitializationException - If occur any problem during initialization steps.
Method Detail

build

public Application build()
                  throws InitializationException
Builds a new instance of the actual Application's class with the default name.

Specified by:
build in interface ApplicationFactory
Returns:
A new instance of the actual Application's class.
Throws:
InitializationException
See Also:
ApplicationFactory.build()

build

public Application build(java.lang.String app)
                  throws InitializationException
Builds a new instance of the specified Application's class app with the default name.

Specified by:
build in interface ApplicationFactory
Parameters:
app - Application's class to be generated.
Returns:
A new instance of the specified Application's class.
Throws:
InitializationException
See Also:
ApplicationFactory.build(java.lang.String)

buildWithName

public Application buildWithName(java.lang.String name)
                          throws InitializationException
Generates a new instance of the actual class of Application.

Specified by:
buildWithName in interface ApplicationFactory
Parameters:
name - Name for the application to generate.
Returns:
A new instance of the actually specified Application class.
Throws:
InitializationException
See Also:
ApplicationFactory.build(), Application

buildWithName

public Application buildWithName(java.lang.String app,
                                 java.lang.String name)
                          throws InitializationException
Generates a new instance of the specified Application class app.

Specified by:
buildWithName in interface ApplicationFactory
Parameters:
app - Application class to generate this new instance.
name - Name for the application to generate.
Returns:
A new instance of the Application class app
Throws:
InitializationException
See Also:
ApplicationFactory.build(java.lang.String)

getApplicationClass

public java.lang.String getApplicationClass()
Gets the Application classname actually in use.

Specified by:
getApplicationClass in interface ApplicationFactory
Returns:
Application classname actually in use.
See Also:
ApplicationFactory.getApplicationClass()

setApplicationClass

public void setApplicationClass(java.lang.String app)
                         throws InitializationException
Sets the Application classname to use in the future.

Specified by:
setApplicationClass in interface ApplicationFactory
Parameters:
app - Application classname for some implementation to use in the future.
Throws:
InitializationException - if exists some problem with the Application classname app.
See Also:
ApplicationFactory.setApplicationClass(java.lang.String)