Class EPSGFactory
java.lang.Object
org.apache.sis.util.iso.AbstractFactory
org.apache.sis.referencing.factory.GeodeticAuthorityFactory
org.apache.sis.referencing.factory.ConcurrentAuthorityFactory<EPSGDataAccess>
org.apache.sis.referencing.factory.sql.EPSGFactory
- All Implemented Interfaces:
AutoCloseable,Localized,org.opengis.referencing.AuthorityFactory,org.opengis.referencing.crs.CRSAuthorityFactory,org.opengis.referencing.cs.CSAuthorityFactory,org.opengis.referencing.datum.DatumAuthorityFactory,org.opengis.referencing.operation.CoordinateOperationAuthorityFactory,org.opengis.util.Factory
public class EPSGFactory
extends ConcurrentAuthorityFactory<EPSGDataAccess>
implements org.opengis.referencing.crs.CRSAuthorityFactory, org.opengis.referencing.cs.CSAuthorityFactory, org.opengis.referencing.datum.DatumAuthorityFactory, org.opengis.referencing.operation.CoordinateOperationAuthorityFactory, Localized
A geodetic object factory backed by the EPSG database. This class creates JDBC connections to the EPSG database
when first needed using the
DataSource specified at construction time. The geodetic objects are cached
for reuse and the idle connections are closed after a timeout.
If no data source has been specified to the constructor, then EPSGFactory searches for a
default data source in JNDI, or in the directory given by the SIS_DATA environment variable,
or in the directory given by the "derby.system.home" property, in that order.
See the package documentation for more information.
EPSG dataset installation
This class tries to automatically detect the schema that contains the EPSG tables (seeSQLTranslator for examples of tables to look for). If the tables are not found,
then the install(Connection) method will be invoked for creating the EPSG schema.
The install(…) method can perform its work only if the definition files are reachable
on the classpath, or if the directory containing the files have been specified.
Data Access Object (DAO)
If there is no cached object for a given code, thenEPSGFactory creates an EPSGDataAccess instance
for performing the actual creation work. Developers who need to customize the geodetic object creation can override
the newDataAccess(Connection, SQLTranslator) method in order to return their own EPSGDataAccess
subclass.- Since:
- 0.7
- Version:
- 0.8
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe name of the catalog that contains the EPSG tables, ornullor an empty string.The namespace of EPSG codes.protected final org.opengis.referencing.operation.CoordinateOperationFactoryThe factory to use for creatingCoordinateOperationinstances from the properties read in the database.protected final org.opengis.referencing.crs.CRSFactoryThe factory to use for creatingCoordinateReferenceSysteminstances from the properties read in the database.protected final org.opengis.referencing.cs.CSFactoryThe factory to use for creatingCoordinateSysteminstances from the properties read in the database.protected final DataSourceThe factory to use for creatingConnections to the EPSG database.protected final org.opengis.referencing.datum.DatumFactoryThe factory to use for creatingDatuminstances from the properties read in the database.private final LocaleThe locale for producing error messages.protected final org.opengis.referencing.operation.MathTransformFactoryThe factory to use for creatingMathTransforminstances.protected final org.opengis.util.NameFactoryThe factory to use for creatingGenericNameinstances.private final StringThe name of the schema that contains the EPSG tables, ornullor an empty string.private final InstallationScriptProviderA provider of SQL scripts to use ifEPSGFactoryneeds to create the database, ornullfor the default mechanism.private SQLTranslatorThe translator from the SQL statements using MS-Access dialect to SQL statements using the dialect of the actual database. -
Constructor Summary
ConstructorsConstructorDescriptionEPSGFactory(Map<String, ?> properties) Creates a factory using the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanClose(EPSGDataAccess factory) Returnstrueif the given Data Access Object (DAO) can be closed.private StringReturns the message to put in anUnavailableFactoryExceptionhaving the given exception as its cause.private StringReturns the message to put in anUnavailableFactoryExceptionhaving the given cause.private static <F> FReturns the factory for the given key if it exists, or the default factory instance otherwise.Returns the namespace of EPSG codes.Returns the locale used by this factory for producing error messages.voidinstall(Connection connection) Creates the EPSG schema in the database and populates the tables with geodetic definitions.protected booleanisCacheable(String code, Object object) Returns whether the given object can be cached.protected EPSGDataAccessCreates the factory which will perform the actual geodetic object creation work.protected EPSGDataAccessnewDataAccess(Connection connection, SQLTranslator translator) Creates the factory which will perform the actual geodetic object creation from a given connection.Methods inherited from class org.apache.sis.referencing.factory.ConcurrentAuthorityFactory
close, 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, getAuthority, getAuthorityCodes, getDescriptionText, getTimeout, newIdentifiedObjectFinder, normalizeCode, printCacheContent, setTimeout, toStringMethods inherited from class org.apache.sis.referencing.factory.GeodeticAuthorityFactory
createParametricCRS, createParametricCS, createParametricDatum, trimNamespaceMethods inherited from class org.apache.sis.util.iso.AbstractFactory
getVendorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opengis.referencing.AuthorityFactory
createObject, getAuthority, getAuthorityCodes, getDescriptionTextMethods inherited from interface org.opengis.referencing.operation.CoordinateOperationAuthorityFactory
createCoordinateOperation, createFromCoordinateReferenceSystemCodes, createOperationMethodMethods inherited from interface org.opengis.referencing.crs.CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRSMethods inherited from interface org.opengis.referencing.cs.CSAuthorityFactory
createCartesianCS, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createUnit, createVerticalCSMethods inherited from interface org.opengis.referencing.datum.DatumAuthorityFactory
createDatum, createEllipsoid, createEngineeringDatum, createGeodeticDatum, createImageDatum, createPrimeMeridian, createTemporalDatum, createVerticalDatumMethods inherited from interface org.opengis.util.Factory
getVendor
-
Field Details
-
CODESPACES
The namespace of EPSG codes.- See Also:
-
dataSource
The factory to use for creatingConnections to the EPSG database. -
nameFactory
protected final org.opengis.util.NameFactory nameFactoryThe factory to use for creatingGenericNameinstances. -
datumFactory
protected final org.opengis.referencing.datum.DatumFactory datumFactoryThe factory to use for creatingDatuminstances from the properties read in the database. -
csFactory
protected final org.opengis.referencing.cs.CSFactory csFactoryThe factory to use for creatingCoordinateSysteminstances from the properties read in the database. -
crsFactory
protected final org.opengis.referencing.crs.CRSFactory crsFactoryThe factory to use for creatingCoordinateReferenceSysteminstances from the properties read in the database. -
copFactory
protected final org.opengis.referencing.operation.CoordinateOperationFactory copFactoryThe factory to use for creatingCoordinateOperationinstances from the properties read in the database. -
mtFactory
protected final org.opengis.referencing.operation.MathTransformFactory mtFactoryThe factory to use for creatingMathTransforminstances. The math transforms are created as part ofCoordinateOperationcreation process. -
catalog
The name of the catalog that contains the EPSG tables, ornullor an empty string.- The
""value retrieves the EPSG schema without a catalog. - The
nullvalue means that the catalog name should not be used to narrow the search.
- The
-
schema
The name of the schema that contains the EPSG tables, ornullor an empty string.- The
""value retrieves the EPSG tables without a schema. In such case, table names are prefixed by "epsg_". - The
nullvalue means that the schema name should not be used to narrow the search. In such case,SQLTranslatorwill tries to automatically detect the schema.
- The
-
scriptProvider
A provider of SQL scripts to use ifEPSGFactoryneeds to create the database, ornullfor the default mechanism. -
translator
The translator from the SQL statements using MS-Access dialect to SQL statements using the dialect of the actual database. If null, will be created when first needed. -
locale
The locale for producing error messages. This is usually the default locale.- See Also:
-
-
Constructor Details
-
EPSGFactory
Creates a factory using the given configuration. The properties recognized by this constructor are listed in the table below. Any property not listed below will be ignored by this constructor. All properties are optional and cannullor omitted, in which case default values are used. Those default values are implementation-specific and may change in any future SIS version.Recognized properties Key Value class Description dataSourceDataSourceThe factory to use for creating Connections to the EPSG database.nameFactoryNameFactoryThe factory to use for creating GenericNameinstances.datumFactoryDatumAuthorityFactoryThe factory to use for creating Datuminstances.csFactoryCSAuthorityFactoryThe factory to use for creating CoordinateSysteminstances.crsFactoryCRSAuthorityFactoryThe factory to use for creating CoordinateReferenceSysteminstances.copFactoryCoordinateOperationAuthorityFactoryThe factory to use for creating CoordinateOperationinstances.mtFactoryMathTransformFactoryThe factory to use for creating MathTransforminstances.catalogStringThe database catalog that contains the EPSG schema (see install). schemaStringThe database schema that contains the EPSG tables (see install). scriptProviderInstallationScriptProviderA provider of SQL scripts to use if EPSGFactoryneeds to create the database.localeLocaleThe locale for producing error messages on a best effort basis. Default values
- If no
dataSourceis specified, this constructor defaults to the search algorithm described in the package documentation. - If no
catalogorschemais specified,SQLTranslatorwill try to auto-detect the schema that contains the EPSG tables. - If no
localeis specified, this constructor defaults to the display locale.
- Parameters:
properties- the data source, authority factories and other configuration properties, ornullfor the default values.- Throws:
ClassCastException- if a property value is not of the expected class.IllegalArgumentException- if a property value is invalid.org.opengis.util.FactoryException- if an error occurred while creating the EPSG factory.
- If no
-
-
Method Details
-
factory
Returns the factory for the given key if it exists, or the default factory instance otherwise. -
canNotUse
Returns the message to put in anUnavailableFactoryExceptionhaving the given exception as its cause. -
canNotUse
Returns the message to put in anUnavailableFactoryExceptionhaving the given cause. -
getCodeSpaces
Returns the namespace of EPSG codes.- Overrides:
getCodeSpacesin classGeodeticAuthorityFactory- Returns:
- the
"EPSG"string in a singleton map.
-
getLocale
Returns the locale used by this factory for producing error messages. This locale does not change the way data are read from the EPSG database. -
install
Creates the EPSG schema in the database and populates the tables with geodetic definitions. This method is invoked automatically whennewDataAccess()detects that the EPSG dataset is not installed. Users can also invoke this method explicitly if they wish to force the dataset installation.This method uses the following properties from the map specified at construction time:
catalog:
aStringgiving the name of the database catalog where to create the EPSG schema. If non-null, that catalog shall exist prior this method call (this method does not create any catalog). If no catalog is specified or if the catalog is an empty string, then the EPSG schema will be created without catalog. If the database does not support catalogs in table definitions or in data manipulation, then this property is ignored.schema:
aStringgiving the name of the database schema where to create the EPSG tables. That schema shall not exist prior this method call; the schema will be created by thisinstall(…)method. If the schema is an empty string, then the tables will be created without schema. If no schema is specified, then the default schema is"EPSG". If the database does not support schemas in table definitions or in data manipulation, then this property is ignored.scriptProvider:
anInstallationScriptProvidergiving the SQL scripts to execute for creating the EPSG database. If no provider is specified, then this method will search on the classpath (withServiceLoader) for user-provided implementations ofInstallationScriptProvider. If no user-specified provider is found, then this method will search for"EPSG_*Tables.sql","EPSG_*Data.sql"and"EPSG_*FKeys.sql"files in the$SIS_DATA/Databases/ExternalSourcesdirectory where*stands for any characters provided that there is no ambiguity.
Legal constraint
The EPSG dataset cannot be distributed with Apache SIS at this time for licensing reasons. Users need to either install the dataset manually (for example with the help of this method), or add on the classpath to a separated bundle likeorg.apache.sis:non-free:sis-epsg.jar. See How to use EPSG geodetic dataset for more information.- Parameters:
connection- connection to the database where to create the EPSG schema.- Throws:
UnavailableFactoryException- if installation failed. The exception will have aFileNotFoundExceptioncause if a SQL script has not been found (typically because a required resource is not on the classpath), anIOExceptionif an I/O error occurred while reading a SQL script, or aSQLExceptionif an error occurred while writing to the database.- See Also:
-
newDataAccess
Creates the factory which will perform the actual geodetic object creation work. This method is invoked automatically when a new worker is required, either because the previous one has been disposed after its timeout or because a new one is required for concurrency.The default implementation performs the following steps:
- Gets a new connection from the
dataSource. - If this method is invoked for the first time, verifies if the EPSG tables exists.
If the tables are not found, invokes
install(Connection). - Delegates to
newDataAccess(Connection, SQLTranslator), which provides an easier overriding point for subclasses wanting to return a customEPSGDataAccessinstance.
- Specified by:
newDataAccessin classConcurrentAuthorityFactory<EPSGDataAccess>- Returns:
- Data Access Object (DAO) to use in
createFoo(String)methods. - Throws:
org.opengis.util.FactoryException- if the constructor failed to connect to the EPSG database. This exception usually has aSQLExceptionas its cause.
- Gets a new connection from the
-
newDataAccess
protected EPSGDataAccess newDataAccess(Connection connection, SQLTranslator translator) throws SQLException Creates the factory which will perform the actual geodetic object creation from a given connection. This method is a convenience hook easier to override thannewDataAccess()for subclasses wanting to return instances of their ownEPSGDataAccesssubclass. The default implementation is simply: Subclasses can override this method with a similar code but withnew EPSGDataAccess(…)replaced bynew MyDataAccessSubclass(…).- Parameters:
connection- a connection to the EPSG database.translator- the translator from the SQL statements using MS-Access dialect to SQL statements using the dialect of the actual database.- Returns:
- Data Access Object (DAO) to use in
createFoo(String)methods. - Throws:
SQLException- if a problem with the database has been detected.- See Also:
-
canClose
Returnstrueif the given Data Access Object (DAO) can be closed. This method is invoked automatically after the timeout if the given DAO has been idle during all that time. The default implementation always returnsfalseif a set returned byEPSGDataAccess.getAuthorityCodes(Class)is still in use.- Overrides:
canClosein classConcurrentAuthorityFactory<EPSGDataAccess>- Parameters:
factory- the Data Access Object which is about to be closed.- Returns:
trueif the given Data Access Object can be closed.- See Also:
-
isCacheable
Returns whether the given object can be cached. This method is invoked afterEPSGDataAccesscreated a new object not previously in the cache.- Overrides:
isCacheablein classConcurrentAuthorityFactory<EPSGDataAccess>- Parameters:
code- the authority code specified by the caller for creating an object.object- the object created for the given authority code.- Returns:
- whether the given object should be cached.
- Since:
- 0.8
- See Also:
-