org.geotools.referencing.factory.epsg
Class ThreadedEpsgFactory

Object
  extended by AbstractFactory
      extended by ReferencingFactory
          extended by AbstractAuthorityFactory
              extended by BufferedAuthorityFactory
                  extended by DeferredAuthorityFactory
                      extended by ThreadedEpsgFactory
All Implemented Interfaces:
RegisterableService, BufferedFactory, Factory, OptionalFactory, AuthorityFactory, CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory
Direct Known Subclasses:
DefaultFactory, ThreadedHsqlEpsgFactory, ThreadedPostgreSQLEpsgFactory

public class ThreadedEpsgFactory
extends DeferredAuthorityFactory
implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory

Base class for EPSG factories to be registered in ReferencingFactoryFinder. Various subclasses are defined for different database backends: Access, PostgreSQL, HSQL, etc..

This class has the following responsibilities:

Please note we are working with the same tables as defined by EPSG. The only thing that changes is the database used to host these tables.

Subclasses should override the following methods:

Users should not creates instance of this class directly. They should invoke one of ReferencingFactoryFinder.getFooAuthorityFactory("EPSG") methods instead.

Since:
2.4
Author:
Martin Desruisseaux (IRD)

Field Summary
protected  DataSource datasource
          The data source, or null if the connection has not yet been etablished.
static String DATASOURCE_NAME
          The default JDBC data source name in JNDI.
protected  boolean dynamicDataSource
          Whether the DataSource is created along with the backing store, or it's a stable, long lived one
 
Fields inherited from class ReferencingFactory
LOGGER
 
Fields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
 
Constructor Summary
ThreadedEpsgFactory()
          Constructs an authority factory using the default set of factories.
ThreadedEpsgFactory(Hints userHints)
          Constructs an authority factory with the default priority.
ThreadedEpsgFactory(Hints userHints, int priority)
          Constructs an authority factory using a set of factories created from the specified hints.
 
Method Summary
protected  boolean canDisposeBackingStore(AbstractAuthorityFactory backingStore)
          Returns true if the backing store can be disposed now.
protected  AbstractAuthorityFactory createBackingStore()
          Creates the backing store authority factory.
protected  AbstractAuthorityFactory createBackingStore(Hints hints)
          Creates the backing store for the specified data source.
protected  DataSource createDataSource()
          Setup a data source for a connection to the EPSG database.
 void dispose()
          Releases resources immediately instead of waiting for the garbage collector.
protected  void disposeBackingStore()
          Disposes of the backing store
 Citation getAuthority()
          Returns the authority for this EPSG database.
 DataSource getDataSource()
          Returns the data source for the EPSG database.
 void setDataSource(DataSource datasource)
          Set the data source for the EPSG database.
 
Methods inherited from class DeferredAuthorityFactory
exit, getBackingStore, isAvailable, isConnected, setTimeout
 
Methods inherited from class BufferedAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createObject, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getAuthorityCodes, getBackingStoreDescription, getDescriptionText, getIdentifiedObjectFinder, getVendor
 
Methods inherited from class AbstractAuthorityFactory
noSuchAuthorityCode, trimAuthority
 
Methods inherited from class ReferencingFactory
ensureNonNull
 
Methods inherited from class AbstractFactory
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRS
 
Methods inherited from interface CSAuthorityFactory
createCartesianCS, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createUnit, createVerticalCS
 
Methods inherited from interface DatumAuthorityFactory
createDatum, createEllipsoid, createEngineeringDatum, createGeodeticDatum, createImageDatum, createPrimeMeridian, createTemporalDatum, createVerticalDatum
 
Methods inherited from interface CoordinateOperationAuthorityFactory
createCoordinateOperation, createFromCoordinateReferenceSystemCodes
 
Methods inherited from interface AuthorityFactory
createObject, getAuthorityCodes, getDescriptionText
 
Methods inherited from interface Factory
getVendor
 
Methods inherited from interface Factory
getImplementationHints
 

Field Detail

DATASOURCE_NAME

public static final String DATASOURCE_NAME
The default JDBC data source name in JNDI. This is the name used if no other name were specified through the EPSG_DATA_SOURCE hint.

See Also:
createDataSource(), Constant Field Values

datasource

protected DataSource datasource
The data source, or null if the connection has not yet been etablished.


dynamicDataSource

protected boolean dynamicDataSource
Whether the DataSource is created along with the backing store, or it's a stable, long lived one

Constructor Detail

ThreadedEpsgFactory

public ThreadedEpsgFactory()
Constructs an authority factory using the default set of factories.


ThreadedEpsgFactory

public ThreadedEpsgFactory(Hints userHints)
Constructs an authority factory with the default priority.


ThreadedEpsgFactory

public ThreadedEpsgFactory(Hints userHints,
                           int priority)
Constructs an authority factory using a set of factories created from the specified hints. This constructor recognizes the CRS, CS, DATUM and MATH_TRANSFORM FACTORY hints, in addition of EPSG_DATA_SOURCE.

Parameters:
userHints - An optional set of hints, or null if none.
priority - The priority for this factory, as a number between MINIMUM_PRIORITY and MAXIMUM_PRIORITY inclusive.
Method Detail

getAuthority

public Citation getAuthority()
Returns the authority for this EPSG database. This authority will contains the database version in the edition attribute, together with the edition date.

Specified by:
getAuthority in interface AuthorityFactory
Overrides:
getAuthority in class BufferedAuthorityFactory
Returns:
The organization reponsible for definition of the database.

getDataSource

public final DataSource getDataSource()
                               throws SQLException
Returns the data source for the EPSG database. If no data source has been previously set, then this method invokes createDataSource(). Note: invoking this method may force immediate connection to the EPSG database.

Returns:
The data source.
Throws:
SQLException - if the connection to the EPSG database failed.
See Also:
setDataSource(javax.sql.DataSource), createDataSource()

setDataSource

public void setDataSource(DataSource datasource)
                   throws SQLException
Set the data source for the EPSG database. If an other EPSG database was already in use, it will be disconnected. Users should not invoke this method on the factory returned by ReferencingFactoryFinder, since it could have a system-wide effect.

Parameters:
datasource - The new datasource.
Throws:
SQLException - if an error occured.

createDataSource

protected DataSource createDataSource()
                               throws SQLException
Setup a data source for a connection to the EPSG database. This method is invoked by getDataSource() when no data source has been explicitly set. The default implementation searchs for a DataSource instance binded to the Hints.EPSG_DATA_SOURCE name ("java:comp/env/jdbc/EPSG" by default) using Java Naming and Directory Interfaces (JNDI). If no data source were found, then this method returns null.

Subclasses override this method in order to initialize a default data source when none were found with JNDI. For example plugin/epsg-access defines a default data source using the JDBC-ODBC bridge, which expects an "EPSG" database registered as an ODBC data source (see the package javadoc for installation instructions). Example for a PostgreSQL data source:

 protected DataSource createDataSource() throws SQLException {
     DataSource candidate = super.createDataSource();
     if (candidate instanceof Jdbc3SimpleDataSource) {
         return candidate;
     }
     Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource();
     ds.setServerName("localhost");
     ds.setDatabaseName("EPSG");
     ds.setUser("postgre");
     return ds;
 }
 

Returns:
The EPSG data source, or null if none where found.
Throws:
SQLException - if an error occured while creating the data source.

createBackingStore

protected AbstractAuthorityFactory createBackingStore(Hints hints)
                                               throws SQLException
Creates the backing store for the specified data source. This method usually returns a new instance of AccessDialectEpsgFactory or AnsiDialectEpsgFactory. Subclasses may override this method in order to returns an instance tuned for the SQL syntax of the underlying database. Example for a PostgreSQL data source:
 protected AbstractAuthorityFactory createBackingStore(Hints hints) throws SQLException {
     return new AnsiDialectEpsgFactory(hints, getDataSource().getConnection());
 }
 

Parameters:
hints - A map of hints, including the low-level factories to use for CRS creation. This argument should be given unchanged to DirectEpsgFactory constructor.
Returns:
The EPSG factory using SQL queries appropriate for this data source.
Throws:
SQLException - if connection to the database failed.

createBackingStore

protected AbstractAuthorityFactory createBackingStore()
                                               throws FactoryException
Creates the backing store authority factory.

Specified by:
createBackingStore in class DeferredAuthorityFactory
Returns:
The backing store to uses in createXXX(...) methods.
Throws:
FactoryException - if the constructor failed to connect to the EPSG database. This exception usually has a SQLException as its cause.

canDisposeBackingStore

protected boolean canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returns true if the backing store can be disposed now. This method is invoked automatically after the amount of time specified by DeferredAuthorityFactory.setTimeout(long) if the factory were not used during that time.

Overrides:
canDisposeBackingStore in class DeferredAuthorityFactory
Parameters:
backingStore - The backing store in process of being disposed.

disposeBackingStore

protected void disposeBackingStore()
Description copied from class: DeferredAuthorityFactory
Disposes of the backing store

Overrides:
disposeBackingStore in class DeferredAuthorityFactory

dispose

public void dispose()
             throws FactoryException
Description copied from class: DeferredAuthorityFactory
Releases resources immediately instead of waiting for the garbage collector. This method disposes the backing store regardeless of DeferredAuthorityFactory.canDisposeBackingStore(org.geotools.referencing.factory.AbstractAuthorityFactory) value.

Overrides:
dispose in class DeferredAuthorityFactory
Throws:
FactoryException - if an error occured while disposing the factory.


Copyright © 1996-2014 Geotools. All Rights Reserved.