org.opensubsystems.core.util
Class ClassFactory

java.lang.Object
  extended by org.opensubsystems.core.util.ClassFactory
Direct Known Subclasses:
ControllerClassFactory, DatabaseFactoryClassFactory, ThickClientDependentClassFactory

public class ClassFactory
extends java.lang.Object

Purpose of this class is to make creation of configurable factories easier. It allows caller to specify class or class name of the class for which some new instance is desired. It allows derived class to perform name transformation

Version:
$Id: ClassFactory.java,v 1.7 2007/01/07 06:14:00 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.5 2006/04/05 05:05:13 bastafidli

Constructor Summary
ClassFactory()
          Creates a new instance of DatabaseContextListener
 
Method Summary
protected  void createConfiguredClassNames(java.lang.String strClassIdentifier, java.lang.String strModifier, java.util.List lstClassNames)
          Create name for the class identified by given identifier based on configuration information.
protected  void createDefaultClassNames(java.lang.String strClassIdentifier, java.lang.String strModifier, java.util.List lstClassNames)
          Create new class name based on the specified identifier and modifier.
 java.lang.Object createInstance(java.lang.Class clsClassIdentifier)
          Create instance of the class by calling parameterless constructor.
 java.lang.Object createInstance(java.lang.Class clsClassIdentifier, java.lang.Class clsDefault)
          Create instance of the class by calling parameterless constructor.
 java.lang.Object createInstance(java.lang.String strClassIdentifier)
          Create instance of the class by calling parameterless constructor.
 java.lang.Object createInstance(java.lang.String strClassIdentifier, java.lang.Class clsDefault)
          Create instance of the class by calling parameterless constructor.
static ClassFactory getInstance()
          Get the default instance so that everybody doesn't have to instantiate it all the time.
protected  java.lang.String getModifier()
          Get modifier which should be used together with the class identifier to construct class names.
protected  java.lang.Object instantiateClass(java.util.List lstClassNames, java.lang.String strClassIdentifier)
          Instantiate new istance using ordered list of class names to consider.
static void setInstance(ClassFactory defaultInstance)
          Set default instance.
protected  void verifyInstance(java.lang.Object objInstance)
          This method allows derived class to implement verifications if desired that the instantiated class must satisfy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFactory

public ClassFactory()
Creates a new instance of DatabaseContextListener

Method Detail

getInstance

public static ClassFactory getInstance()
                                throws OSSException
Get the default instance so that everybody doesn't have to instantiate it all the time.

Returns:
DatabaseSchemaManager
Throws:
OSSException - - cannot get current database

setInstance

public static void setInstance(ClassFactory defaultInstance)
Set default instance. This instance will be returned by getInstance method until it is changed.

Parameters:
defaultInstance - - new default instance
See Also:
getInstance()

createInstance

public java.lang.Object createInstance(java.lang.Class clsClassIdentifier)
                                throws OSSException
Create instance of the class by calling parameterless constructor. The created instance doesn't have to be of the same type as the passed in class identifier. The identifier can be used to create name of different class by some transformation, e.g. in case an interface name is passed in and default implementation class is desired.

Parameters:
clsClassIdentifier - - identifier of the class for which new instance should be created
Returns:
Object - new instance of the object, never null since exception will be thrown if not found
Throws:
OSSException - - an error has occured

createInstance

public java.lang.Object createInstance(java.lang.Class clsClassIdentifier,
                                       java.lang.Class clsDefault)
                                throws OSSException
Create instance of the class by calling parameterless constructor. The created instance doesn't have to be of the same type as the passed in class identifier. The identifier can be used to create name of different class by some transformation, e.g. in case an interface name is passed in and default implementation class is desired.

Parameters:
clsClassIdentifier - - identifier of the class for which new instance should be created
clsDefault - - default class to instantiate if no other class based on clsClassIdentifier cannot be instantiated
Returns:
Object - new instance of the object, never null since exception will be thrown if not found
Throws:
OSSException - - an error has occured

createInstance

public java.lang.Object createInstance(java.lang.String strClassIdentifier,
                                       java.lang.Class clsDefault)
                                throws OSSException
Create instance of the class by calling parameterless constructor. The created instance doesn't have to be of the same type as the passed in class identifier. The identifier can be used to create name of different class by some transformation, e.g. in case an interface name is passed in and default implementation class is desired.

Parameters:
strClassIdentifier - - identifier of the class for which new instance should be created
clsDefault - - default class to instantiate if no other class based on clsClassIdentifier cannot be instantiated
Returns:
Object - new instance of the object, never null since exception will be thrown if not found
Throws:
OSSException - - an error has occured

createInstance

public java.lang.Object createInstance(java.lang.String strClassIdentifier)
                                throws OSSException
Create instance of the class by calling parameterless constructor. The created instance doesn't have to be of the same type as the passed in class identifier. The identifier can be used to create name of different class by some transformation, e.g. in case an interface name is passed in and default implementation class is desired.

Parameters:
strClassIdentifier - - identifier of the class for which new instance should be created
Returns:
Object - new instance of the object, never null since exception will be thrown if not found
Throws:
OSSException - - an error has occured

instantiateClass

protected java.lang.Object instantiateClass(java.util.List lstClassNames,
                                            java.lang.String strClassIdentifier)
                                     throws OSSException
Instantiate new istance using ordered list of class names to consider.

Parameters:
lstClassNames - - ordered list of classes to consider as a template for new instance
strClassIdentifier - - identifier of the class for which new instance should be created, used for reporting purposes
Returns:
Object - new instance or null if it cannot be instantiated
Throws:
OSSException - - an error has occured

verifyInstance

protected void verifyInstance(java.lang.Object objInstance)
                       throws OSSException
This method allows derived class to implement verifications if desired that the instantiated class must satisfy.

Parameters:
objInstance - - instance to verify, can be null
Throws:
OSSException - - an error has occured (e.g. verification error)

createDefaultClassNames

protected void createDefaultClassNames(java.lang.String strClassIdentifier,
                                       java.lang.String strModifier,
                                       java.util.List lstClassNames)
                                throws OSSException
Create new class name based on the specified identifier and modifier.

Parameters:
strClassIdentifier - - identifier of the class for which new instance should be created
strModifier - - modifier used together with identifier to query configured class name or null if none is available
lstClassNames - - container to add the possible class names to. The classes will be tried in order as they are added to this container.
Throws:
OSSException - - an error has occured

createConfiguredClassNames

protected void createConfiguredClassNames(java.lang.String strClassIdentifier,
                                          java.lang.String strModifier,
                                          java.util.List lstClassNames)
                                   throws OSSException
Create name for the class identified by given identifier based on configuration information. This name is first queried using modifier appended to the identifier and then without modifier for default configuration.

Parameters:
strClassIdentifier - - identifier of the class for which new instance should be created
strModifier - - modifier used together with identifier to query configured class name or null if none is available
lstClassNames - - container to add the possible class names to. The classes will be tried in order as they are added to this container.
Throws:
OSSException - - an error has occured

getModifier

protected java.lang.String getModifier()
                                throws OSSException
Get modifier which should be used together with the class identifier to construct class names.

Returns:
String - modifier or null if no modifier should be used
Throws:
OSSException - - an error has occured


Copyright © 2003 - 2006 OpenSubsystems s.r.o.