Class AbstractEpsgFactory
- All Implemented Interfaces:
AuthorityFactory
,CRSAuthorityFactory
,CSAuthorityFactory
,DatumAuthorityFactory
,Factory
,CoordinateOperationAuthorityFactory
,BufferedFactory
,Factory
,RegistrableFactory
- Direct Known Subclasses:
AccessDialectEpsgFactory
,AnsiDialectEpsgFactory
The EPSG database is freely available at http://www.epsg.org. Current version of this class requires EPSG database version 6.6 or above.
This factory makes use of a provided ObjectCache
, and may be deployed in stand aline fashion; or as a
worker for a MultiEpsgFactory
.
This class is abstract - please see the subclasses for dialect specific implementations:
AccessDialectEpsgFactory
AnsiDialectEpsgFactory
OracleDialectEpsgFactory
"27581"
both fetchs the same object. However, names may be ambiguous since the same name may be used for more
than one object. This is the case of "WGS 84" for example. If such an ambiguity is found, an exception will be
thrown. If names are not wanted as a legal EPSG code, subclasses can override the isPrimaryKey(java.lang.String)
method.- Since:
- 2.4
- Author:
- Yann Cézard, Martin Desruisseaux (IRD), Rueben Schulz, Matthias Basler, Andrea Aime
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataSource
A DataSource to the EPSG database being used.Fields inherited from class AbstractCachedAuthorityFactory
cache, factories
Fields inherited from class ReferencingFactory
LOGGER
Fields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractEpsgFactory
(Hints userHints) AbstractEpsgFactory
(Hints userHints, Connection connection) Constructs an authority factory using the specified connection.AbstractEpsgFactory
(Hints userHints, DataSource dataSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract String
Invoked when a newPreparedStatement
is about to be created from a SQL string.void
connect()
Connect to the database in anticipation of of use.void
Disconnect from the database, and remain idle.void
dispose()
Disposes any resources hold by this object.protected final void
finalize()
Invokesdispose()
when this factory is garbage collected.generateAuthorityCodes
(Class type) Returns the set of authority codes of the given type.Returns a coordinate operation from a code.Returns a coordinate reference system from a code.Returns a coordinate system from a code.Returns a coordinate system axis from a code.generateDatum
(String code) Returns a datum from a code.generateEllipsoid
(String code) Returns an ellipsoid from a code.generateExtent
(String code) Returns an area of use.generateFromCoordinateReferenceSystemCodes
(String sourceCode, String targetCode) Creates operations from coordinate reference system codes.generateObject
(String code) Returns an arbitrary object from a code.Returns an operation method from a code.Returns a parameter descriptor from a code.generatePrimeMeridian
(String code) Returns a prime meridian, relative to Greenwich.Unit<?>
generateUnit
(String code) Returns an unit from a code.Returns the authority for this EPSG database.Returns a description of the database engine.protected Connection
Access to the connection used by this EpsgFactory.getDescriptionText
(String code) Gets a description of the object corresponding to a code.Returns the implementation hints for this factory.protected boolean
isPrimaryKey
(String code) Returnstrue
if the specified code may be a primary key in some table.protected void
shutdown
(boolean active) Shutdown the database engine.Methods inherited from class AbstractCachedAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createObject, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getAuthorityCodes, getIdentifiedObjectFinder, noSuchAuthorityCode, toKey, trimAuthority
Methods inherited from class AbstractAuthorityFactory
createExtent, createOperationMethod, createParameterDescriptor, noSuchAuthorityCode
Methods inherited from class ReferencingFactory
ensureNonNull, getVendor
Methods inherited from class AbstractFactory
addImplementationHints, equals, getPriority, hashCode, onDeregistration, onRegistration, toString
-
Field Details
-
dataSource
A DataSource to the EPSG database being used.
-
-
Constructor Details
-
AbstractEpsgFactory
- Throws:
FactoryException
-
AbstractEpsgFactory
-
AbstractEpsgFactory
Constructs an authority factory using the specified connection.- Parameters:
userHints
- The underlying factories used for objects creation.connection
- The connection to the underlying EPSG database.
-
-
Method Details
-
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 interfaceAuthorityFactory
- Specified by:
getAuthority
in classAbstractCachedAuthorityFactory
- Returns:
- The organization reponsible for definition of the database.
-
getBackingStoreDescription
Returns a description of the database engine.- Overrides:
getBackingStoreDescription
in classAbstractAuthorityFactory
- Returns:
- The description of the underlying backing store, or
null
. - Throws:
FactoryException
- if the database's metadata can't be fetched.
-
getImplementationHints
Returns the implementation hints for this factory. The returned map contains all the values specified in subclass, with the addition ofVERSION
.- Specified by:
getImplementationHints
in interfaceFactory
- Overrides:
getImplementationHints
in classAbstractFactory
- Returns:
- The map of hints, or an empty map if none.
-
generateAuthorityCodes
Returns the set of authority codes of the given type.- Specified by:
generateAuthorityCodes
in classAbstractCachedAuthorityFactory
- Parameters:
type
- The spatial reference objects type (may beObject.class
).- Returns:
- The set of authority codes for spatial reference objects of the given type. If this factory doesn't contains any object of the given type, then this method returns an empty set.
- Throws:
FactoryException
- if access to the underlying database failed.
-
getDescriptionText
Gets a description of the object corresponding to a code.- Specified by:
getDescriptionText
in interfaceAuthorityFactory
- Specified by:
getDescriptionText
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- A description of the object, or
null
if the object corresponding to the specifiedcode
has no description. - Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the query failed for some other reason.
-
generateObject
Returns an arbitrary object from a code. The default implementation invokes one ofAbstractCachedAuthorityFactory.createCoordinateReferenceSystem(java.lang.String)
,AbstractCachedAuthorityFactory.createCoordinateSystem(java.lang.String)
,AbstractCachedAuthorityFactory.createDatum(java.lang.String)
,AbstractCachedAuthorityFactory.createEllipsoid(java.lang.String)
, orAbstractCachedAuthorityFactory.createUnit(java.lang.String)
methods according the object type.- Specified by:
generateObject
in classAbstractCachedAuthorityFactory
- Parameters:
code
- The EPSG value.- Returns:
- The object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateUnit
Returns an unit from a code.- Specified by:
generateUnit
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The unit object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateEllipsoid
Returns an ellipsoid from a code.- Specified by:
generateEllipsoid
in classAbstractCachedAuthorityFactory
- Parameters:
code
- The EPSG value.- Returns:
- The ellipsoid object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generatePrimeMeridian
Returns a prime meridian, relative to Greenwich.- Specified by:
generatePrimeMeridian
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The prime meridian object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateExtent
Returns an area of use.- Parameters:
code
- Value allocated by authority.- Returns:
- The area of use.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateDatum
Returns a datum from a code.- Specified by:
generateDatum
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The datum object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateCoordinateSystemAxis
Returns a coordinate system axis from a code.- Specified by:
generateCoordinateSystemAxis
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.
-
generateCoordinateSystem
Returns a coordinate system from a code.- Specified by:
generateCoordinateSystem
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate system object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateCoordinateReferenceSystem
public CoordinateReferenceSystem generateCoordinateReferenceSystem(String code) throws FactoryException Returns a coordinate reference system from a code.- Specified by:
generateCoordinateReferenceSystem
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateParameterDescriptor
Returns a parameter descriptor from a code.- Parameters:
code
- The parameter descriptor code allocated by EPSG authority.- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateOperationMethod
Returns an operation method from a code.- Parameters:
code
- The operation method code allocated by EPSG authority.- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateCoordinateOperation
Returns a coordinate operation from a code. The returned object will either be a conversion or a transformation, depending on the code.- Specified by:
generateCoordinateOperation
in classAbstractCachedAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate operation object.
- Throws:
NoSuchAuthorityCodeException
- if this method can't find the requested code.FactoryException
- if some other kind of failure occured in the backing store. This exception usually haveSQLException
as its cause.
-
generateFromCoordinateReferenceSystemCodes
public Set generateFromCoordinateReferenceSystemCodes(String sourceCode, String targetCode) throws FactoryException Creates operations from coordinate reference system codes. The returned set is ordered with the most accurate operations first.- Specified by:
generateFromCoordinateReferenceSystemCodes
in classAbstractCachedAuthorityFactory
- Parameters:
sourceCode
- Coded value of source coordinate reference system.targetCode
- Coded value of target coordinate reference system.- Throws:
FactoryException
- if the object creation failed.
-
adaptSQL
Invoked when a newPreparedStatement
is about to be created from a SQL string. Since the EPSG database is available mainly in MS-Access format, SQL statements are formatted using some syntax specific to this particular database software (for example "SELECT * FROM [Coordinate Reference System]
"). When prociding subclass targeting another database vendor, then this method should be overridden in order to adapt the local SQL syntax.For example a subclass connecting to a PostgreSQL database could replace all spaces (" ") between watching braces ("[" and "]") by underscore ("_").
- Parameters:
statement
- The statement in MS-Access syntax.- Returns:
- The SQL statement to use. The default implementation returns the string unchanged.
-
isPrimaryKey
Returnstrue
if the specified code may be a primary key in some table. This method do not needs to checks any entry in the database. It should just checks from the syntax if the code looks like a valid EPSG identifier. The default implementation returnstrue
if all non-space characters are digits.When this method returns
false
, somecreateFoo(...)
methods look for the code in the name column instead of the primary key column. This allows to accept the "NTF (Paris) / France I" string (for example) in addition to the"27581"
primary key. Both should fetch the same object.If this method returns
true
in all cases, then this factory never search for matching names. In such case, an appropriate exception will be thrown increateFoo(...)
methods if the code is not found in the primary key column. Subclasses can overrides this method that way if this is the intended behavior.- Parameters:
code
- The code the inspect.- Returns:
true
if the code is probably a primary key.- Throws:
FactoryException
- if an unexpected error occured while inspecting the code.
-
dispose
Disposes any resources hold by this object.- Overrides:
dispose
in classAbstractCachedAuthorityFactory
- Throws:
FactoryException
- if an error occurred while closing the connection.
-
connect
Connect to the database in anticipation of of use.- Throws:
FactoryException
-
disconnect
Disconnect from the database, and remain idle. We will still keep our internal data structures, we are not going to hold onto a database connection unless we are going to be used.- Throws:
FactoryException
-
getConnection
Access to the connection used by this EpsgFactory. The connection will be created as needed.- Returns:
- the connection
- Throws:
SQLException
-
shutdown
Shutdown the database engine. This method is invoked twice byThreadedEpsgFactory
at JVM shutdown: one time before the connection is closed, and a second time after. This shutdown hook is useful for embedded database engine starting a server process in addition to the client process. Just closing the connection is not enough for them. Example:- HSQL database engine needs to execute a
"SHUTDOWN"
statement using the connection before it is closed. - Derby database engine needs to instruct the driver manager after all connections have been closed.
The default implementation does nothing, which is sufficient for implementations connecting to a distant server (i.e. non-embedded database engine), for example MS-Access or PostgreSQL.
- Parameters:
active
-true
if the connection is alive, orfalse
otherwise. This method is invoked first withactive
set totrue
, then a second time withactive
set tofalse
.- Throws:
SQLException
- if this method failed to shutdown the database engine.
- HSQL database engine needs to execute a
-
finalize
Invokesdispose()
when this factory is garbage collected.
-