i3.dragos.core.services.datasources
Class DataSourceFactory

java.lang.Object
  extended by i3.dragos.core.AbstractService
      extended by i3.dragos.core.services.datasources.DataSourceFactory
All Implemented Interfaces:
Service

public class DataSourceFactory
extends AbstractService

The DataSourceFactory creates data sources. A data source must be opened after it is obtained from the factory to make it usable.

Data source are identified by two so called datasource URLs, the physical and the logical URL.
The identifier of the physical URL is used to associate a database with a data source implementation. Since some implementations for a data source can be used for different databases like the implementation for JDBC compliant databases wildcards can be used for a database identifier in the configuration file. Hence a "*" is not allowed in database identifiers which are used to obtain a data source from the factory.

Author:
Boris Boehlen <boehlen@cs.rwth-aachen.de>, Thorsten Hermes <thermes@i3.informatik.rwth-aachen.de>
See Also:
DataSourceURL, DataSource

Nested Class Summary
 
Nested classes/interfaces inherited from interface i3.dragos.core.Service
Service.Result, Service.State
 
Constructor Summary
DataSourceFactory()
          Constructs the factory.
 
Method Summary
 DataSource create(DataSourceURL physicalDSURL, DataSourceURL logicalDSURL)
          Creates a new data source.
 DataSource get(DataSourceURL datasourceURL)
          Retrieves a previously created DataSource by its logical DataSourceURL.
 DataSource get(java.lang.String datasourceURL)
          Retrieves a previously created DataSource by the String representation of its logical DataSourceURL.
static DataSourceFactory getInstance()
          Returns the data source factroy registered by the service manager.
 java.lang.String getName()
          Returns the name of the service.
 java.util.Set<java.lang.String> getSupportedDataSources()
          Returns the data source identifiers supported by the factory.
 Service.Result initialize()
          Initializes the services.
 void registerDataSourceImplementation(java.lang.String id, java.lang.String impl)
          Registers an implementation for a specific data source.
 Service.Result uninitialize()
          Uninitializes the services and releases all resources used by the service.
 
Methods inherited from class i3.dragos.core.AbstractService
getState, resume, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceFactory

public DataSourceFactory()
Constructs the factory.

Method Detail

getInstance

public static DataSourceFactory getInstance()
Returns the data source factroy registered by the service manager.

Returns:
the data source factroy registered by the service manager.

getName

public java.lang.String getName()
Returns the name of the service.

Returns:
the name of the service.

initialize

public Service.Result initialize()
Initializes the services.

Specified by:
initialize in interface Service
Overrides:
initialize in class AbstractService
Returns:
OK if the initialization was successful, FAILED if it was not and INVALID if the configuration was incorrect.

uninitialize

public Service.Result uninitialize()
Uninitializes the services and releases all resources used by the service.

Specified by:
uninitialize in interface Service
Overrides:
uninitialize in class AbstractService
Returns:
OK if the uninitialization was successful, FAILED if it was not and INVALID if the configuration was incorrect.

getSupportedDataSources

public java.util.Set<java.lang.String> getSupportedDataSources()
Returns the data source identifiers supported by the factory.

Returns:
A set of identifiers of type String.

registerDataSourceImplementation

public void registerDataSourceImplementation(java.lang.String id,
                                             java.lang.String impl)
Registers an implementation for a specific data source.

Parameters:
id - The data source ID.
impl - The full-qualified name of the realization class.

get

public DataSource get(java.lang.String datasourceURL)
               throws DataSourceFactoryException,
                      java.net.MalformedURLException
Retrieves a previously created DataSource by the String representation of its logical DataSourceURL.

Parameters:
datasourceURL - The URL that identifies the data source.
Returns:
the requested data source
Throws:
DataSourceFactoryException - if the requested data source does not exist.
java.net.MalformedURLException - if the data source URL does not match the syntax specified in DataSourceURL.

get

public DataSource get(DataSourceURL datasourceURL)
               throws DataSourceFactoryException
Retrieves a previously created DataSource by its logical DataSourceURL.

Parameters:
datasourceURL - The URL that identifies the data source.
Returns:
the requested data source
Throws:
DataSourceFactoryException - if the requested data source does not exist.

create

public DataSource create(DataSourceURL physicalDSURL,
                         DataSourceURL logicalDSURL)
                  throws DataSourceFactoryException
Creates a new data source. You can not create more than one data source object for the same physical DataSourceURL (as that would require additional precautions for the DataSource implementations, and is not really useful). You also can obviously not use the same logical DataSourceURL for two different DataSources. Thus, this method behaves as follows:

Parameters:
physicalDSURL - The physical DataSourceURL that is needed to create the data source (must not be null).
logicalDSURL - The logical DataSourceURL that will identify the data source from now on (must not be null).
Returns:
a data source which can be used to access the requested database
Throws:
DataSourceFactoryException - if something went wrong during the creation of a proper data source.


Copyright © 2002-2008 RWTH Aachen, Department of Computer Science 3 (Software Engineering). All Rights Reserved.