com.framework.jdto.finder
Class ServiceFinder

java.lang.Object
  extended bycom.framework.jdto.finder.ServiceFinder

public class ServiceFinder
extends Object

This class Follows the ServiceLocator Design Pattern. its a SingleTon Class. its basically used for Locating the DataSource provided its DataSourceJNDIName, InitialContextFactory and ProviderURL using setter Methods or in jdto.properties. If User set these in jdto.properties it should be available in the classpath. Once these values are set, all the DAO's and TransactionContextManager takes care of locating the DataSource. This also lets the user set an existing DataSource using setDataSource method. if the user Sets the DataSource using setDataSource Method, this class picks that DataSource for Transaction Handling. In this Case JDTO Properties is not Required.

This is provided to enable the WebServer users to use any opensource DataSources like Commons DBCP, as the lookup mechanism only works with Application Servers.

Author:
msatish

Method Summary
 DataSource getDataSource()
          Returns the DataSource object for the JNDI Name which is set in jdto.properties or set by using setDataSource method of this class.
 DataSource getDataSource(String jndiName)
          Returns the DataSource object of the corresponding JNDI Name or the datasourceKeyName that is passed during the call to setDataSource method.
static ServiceFinder getInstance()
          This method maintains the Singleton instance of the class.
static void setDatasource(String datasourceKeyName, DataSource ds)
          This method can be used to set the datasource to the framework if you already have one.
 void setDatasourceJNDIName(String datasourceJNDIName)
           
 void setInitialContextFactory(String initialContextFactory)
           
 void setProviderURL(String providerURL)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ServiceFinder getInstance()
This method maintains the Singleton instance of the class. User needs to call ServiceFinder.getInstance() method in order to access any other methods in this class.

Returns:
ServiceFinder

getDataSource

public DataSource getDataSource()
                         throws NamingException
Returns the DataSource object for the JNDI Name which is set in jdto.properties or set by using setDataSource method of this class. if jdto.properties is used, User needs to set the InitialContextFactory, ProviderURL and DataSourceJNDIName in jdto.properties. Also if more than one datasource is set using setDataSource method, this method will take the datasource which ever it finds first from the datasources map, as all the datasources are added to a Map.

Returns:
retObj - A javax.sql.DataSource Object.
Throws:
NamingException - if JNDI name that is set using setDatasourceJNDIName method is not found or can not be resolved.

getDataSource

public DataSource getDataSource(String jndiName)
                         throws NamingException
Returns the DataSource object of the corresponding JNDI Name or the datasourceKeyName that is passed during the call to setDataSource method. if the user passes a JNDI name without calling setDataSource method prior to this, User needs to ensure that the InitialContextFactory and ProviderURL are set in jdto.properties, so that the framework finds the datasource by doing a lookup.

Parameters:
jndiName -
Returns:
datasource
Throws:
NamingException - if JNDI name is not found or can not be resolved.

setDatasource

public static void setDatasource(String datasourceKeyName,
                                 DataSource ds)
This method can be used to set the datasource to the framework if you already have one.

Parameters:
datasourceKeyName -
ds -

setDatasourceJNDIName

public void setDatasourceJNDIName(String datasourceJNDIName)

setInitialContextFactory

public void setInitialContextFactory(String initialContextFactory)

setProviderURL

public void setProviderURL(String providerURL)