001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2005, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.referencing.factory.epsg;
018:
019: // J2SE dependencies
020: import java.sql.Connection;
021: import java.sql.SQLException;
022: import javax.sql.DataSource;
023:
024: // Geotools dependencies
025: import org.geotools.factory.Hints;
026: import org.geotools.referencing.factory.AbstractAuthorityFactory;
027:
028: /**
029: * Connection to the EPSG database in MS-Access format using JDBC-ODBC bridge. The EPSG
030: * database can be downloaded from <A HREF="http://www.epsg.org">http://www.epsg.org</A>.
031: * The JDBC-ODBC bridge is a documented feature of Sun's J2SE distribution. See
032: * <A HREF="http://java.sun.com/j2se/1.5/docs/guide/jdbc/bridge.html">New data source
033: * implementations in the JDBC-ODBC bridge</A>.
034: * <P>
035: * Just having this class accessible in the classpath, together with the registration in
036: * the {@code META-INF/services/} directory, is suffisient to get a working EPSG authority
037: * factory backed by this database. Vendors can create a copy of this class, modify it and
038: * bundle it with their own distribution if they want to connect their users to an other
039: * database (for example a PostgreSQL database reachable on internet).
040: *
041: * @since 2.4
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-access/src/main/java/org/geotools/referencing/factory/epsg/FactoryOnAccess.java $
043: * @version $Id: FactoryOnAccess.java 26328 2007-07-24 16:57:19Z desruisseaux $
044: * @author Martin Desruisseaux
045: *
046: * @deprecated Will be renamed {@code ThreadedAccessEpsgFactory} in Geotools 2.5.
047: */
048: public class FactoryOnAccess extends DefaultFactory {
049: /**
050: * Creates a new instance of this factory.
051: */
052: public FactoryOnAccess() {
053: this (null);
054: }
055:
056: /**
057: * Creates a new instance of this factory using the specified set of hints.
058: */
059: public FactoryOnAccess(final Hints hints) {
060: super (hints, PRIORITY + 9);
061: }
062:
063: /**
064: * Returns a data source using the JDBC-ODBC bridge for the "EPSG" database.
065: */
066: //@Override
067: protected DataSource createDataSource() throws SQLException {
068: DataSource candidate = super .createDataSource();
069: if (candidate == null) {
070: final sun.jdbc.odbc.ee.DataSource source = new sun.jdbc.odbc.ee.DataSource();
071: source.setDatabaseName("EPSG");
072: candidate = source;
073: }
074: return candidate;
075: }
076:
077: /**
078: * Returns the backing-store factory for MS-Access syntax.
079: *
080: * @param hints A map of hints, including the low-level factories to use for CRS creation.
081: * @return The EPSG factory using MS-Access syntax.
082: * @throws SQLException if connection to the database failed.
083: */
084: protected AbstractAuthorityFactory createBackingStore(
085: final Hints hints) throws SQLException {
086: final DataSource source = getDataSource();
087: final Connection connection;
088: try {
089: connection = source.getConnection();
090: } catch (RuntimeException exception) {
091: /*
092: * This try...catch block should NOT be needed. We added it as a workaround because
093: * the JDBC-ODBC bridge on Linux throws a NullPointerException when trying to log a
094: * warning to the tracer.
095: */
096: SQLException e = new SQLException(
097: "Unexpected exception in JDBC data source.");
098: e.initCause(exception);
099: throw e;
100: }
101: return new FactoryUsingSQL(hints, connection);
102: }
103: }
|