Source Code Cross Referenced for PostgreDataSource.java in  » GIS » GeoTools-2.4.1 » org » geotools » referencing » factory » epsg » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.referencing.factory.epsg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.referencing.factory.epsg;
017:
018:        // J2SE dependencies
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.io.InputStream;
022:        import java.io.FileInputStream;
023:        import java.util.Properties;
024:        import java.sql.Connection;
025:        import java.sql.SQLException;
026:
027:        // Geotools dependencies
028:        import org.geotools.util.logging.Logging;
029:        import org.geotools.factory.Hints;
030:        import org.geotools.referencing.factory.AbstractAuthorityFactory;
031:
032:        // PostgreSQL dependencies
033:        import org.postgresql.jdbc3.Jdbc3SimpleDataSource;
034:
035:        /**
036:         * Connection to the EPSG database in PostgreSQL database engine using JDBC. The EPSG
037:         * database can be downloaded from <A HREF="http://www.epsg.org">http://www.epsg.org</A>.
038:         * It should have been imported into a PostgreSQL database, which doesn't need to be on
039:         * the local machine.
040:         * <p>
041:         * <h3>Connection parameters</h3>
042:         * The preferred way to specify connection parameters is through the JNDI interface.
043:         * However, this datasource provides the following alternative as a convenience: if an
044:         * {@value #CONFIGURATION_FILE} file is found in current directory or in the user's home
045:         * directory, then the following properties are fetch. Note that the default value may change
046:         * in a future version if a public server become available.
047:         * <P>
048:         * <TABLE BORDER="1">
049:         * <TR>
050:         *   <TH>Property</TH>
051:         *   <TH>Type</TH>
052:         *   <TH>Description</TH>
053:         *   <TH>Geotools Default</TH>
054:         * </TR>
055:         * <TR>
056:         *   <TD>{@code serverName}</TD>
057:         *   <TD>String</TD>
058:         *   <TD>PostgreSQL database server host name</TD>
059:         *   <TD>{@code localhost}</TD>
060:         * </TR>
061:         * <TR>
062:         *   <TD>{@code databaseName}</TD>
063:         *   <TD>String</TD>
064:         *   <TD>PostgreSQL database name</TD>
065:         *   <TD>{@code EPSG}</TD>
066:         * </TR>
067:         * <TR>
068:         *   <TD>{@code schema}</TD>
069:         *   <TD>String</TD>
070:         *   <TD>The schema for the EPSG tables</TD>
071:         *   <TD></TD>
072:         * </TR>
073:         * <TR>
074:         *   <TD>{@code portNumber}</TD>
075:         *   <TD>int</TD>
076:         *   <TD>TCP port which the PostgreSQL database server is listening on</TD>
077:         *   <TD>{@code 5432}</TD>
078:         * </TR>
079:         * <TR>
080:         *   <TD>{@code user}</TD>
081:         *   <TD>String</TD>
082:         *   <TD>User used to make database connections</TD>
083:         *   <TD>{@code GeoTools}</TD>
084:         * </TR>
085:         * <TR>
086:         *   <TD>{@code password}</TD>
087:         *   <TD>String</TD>
088:         *   <TD>Password used to make database connections</TD>
089:         *   <TD>{@code GeoTools}</TD></TR>
090:         * </TABLE>
091:         * <P>
092:         * The database version is given in the
093:         * {@linkplain org.opengis.metadata.citation.Citation#getEdition edition attribute}
094:         * of the {@linkplain org.opengis.referencing.AuthorityFactory#getAuthority authority}.
095:         * The postgreSQL database should be read only.
096:         * <P>
097:         * Just having this class accessible in the classpath, together with the registration in
098:         * the {@code META-INF/services/} directory, is suffisient to get a working EPSG authority
099:         * factory backed by this database. Vendors can create a copy of this class, modify it and
100:         * bundle it with their own distribution if they want to connect their users to an other
101:         * database.
102:         *
103:         * @since 2.2
104:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-postgresql/src/main/java/org/geotools/referencing/factory/epsg/PostgreDataSource.java $
105:         * @version $Id: PostgreDataSource.java 27848 2007-11-12 13:10:32Z desruisseaux $
106:         * @author Didier Richard
107:         * @author Martin Desruisseaux
108:         *
109:         * @tutorial http://docs.codehaus.org/display/GEOTOOLS/How+to+install+the+EPSG+database+in+PostgreSQL
110:         *
111:         * @deprecated Replaced by {@link FactoryOnPostgreSQL}.
112:         */
113:        public class PostgreDataSource extends Jdbc3SimpleDataSource implements 
114:                DataSource {
115:            /**
116:             * The user configuration file. This class search first for the first file found in the
117:             * following directories:
118:             * <ul>
119:             *   <li>The current directory</li>
120:             *   <li>The user's home directory</li>
121:             * </ul>
122:             */
123:            public static final String CONFIGURATION_FILE = "EPSG-DataSource.properties";
124:
125:            /**
126:             * The schema name, or {@code null} if none.
127:             */
128:            private final String schema;
129:
130:            /**
131:             * Creates a new instance of this data source.
132:             */
133:            public PostgreDataSource() {
134:                this ("localhost", "EPSG", null, "Geotools", "Geotools");
135:            }
136:
137:            /**
138:             * Creates a new instance of this data source with the specified default parameters.
139:             * If a {@linkplain #CONFIGURATION_FILE configuration file} has been found, then the
140:             * user setting will override the arguments supplied to this constructor.
141:             *
142:             * @param server   The server name.
143:             * @param database The database name.
144:             * @param schema   The schema name, or {@code null} if none.
145:             * @param user     The user name.
146:             * @param password The password.
147:             */
148:            public PostgreDataSource(final String server,
149:                    final String database, final String schema,
150:                    final String user, final String password) {
151:                final Properties p = new Properties();
152:                try {
153:                    load(p);
154:                } catch (IOException exception) {
155:                    Logging.unexpectedException(
156:                            "org.geotools.referencing.factory",
157:                            PostgreDataSource.class, "<init>", exception);
158:                }
159:                int port;
160:                try {
161:                    port = Integer
162:                            .parseInt(p.getProperty("portNumber", "5432"));
163:                } catch (NumberFormatException exception) {
164:                    port = 5432;
165:                    Logging.unexpectedException(
166:                            "org.geotools.referencing.factory",
167:                            PostgreDataSource.class, "<init>", exception);
168:                }
169:                setPortNumber(port);
170:                setServerName(p.getProperty("serverName", server));
171:                setDatabaseName(p.getProperty("databaseName", database));
172:                setUser(p.getProperty("user", user));
173:                setPassword(p.getProperty("password", password));
174:                this .schema = (p.getProperty("schema", schema));
175:            }
176:
177:            /**
178:             * Loads the {@linkplain #CONFIGURATION_FILE configuration file}.
179:             *
180:             * @param  The properties in which to stores the configuration informations.
181:             * @throws IOException if the configuration file was found, but an error occured while
182:             *         reading it.
183:             */
184:            private static void load(final Properties p) throws IOException {
185:                File file = new File(CONFIGURATION_FILE);
186:                if (!file.isFile()) {
187:                    file = new File(System.getProperty("user.home", "."),
188:                            CONFIGURATION_FILE);
189:                    if (!file.isFile()) {
190:                        return;
191:                    }
192:                }
193:                final InputStream in = new FileInputStream(file);
194:                p.load(in);
195:                in.close();
196:                return;
197:            }
198:
199:            /**
200:             * Returns the priority for this data source. This priority is set to a lower value than
201:             * the {@linkplain AccessDataSource}'s one in order to give the priority to any "official"
202:             * database installed locally by the user, when available.
203:             */
204:            public int getPriority() {
205:                return NORMAL_PRIORITY - 50;
206:            }
207:
208:            /**
209:             * Open a connection and creates an {@linkplain DirectEpsgFactory EPSG factory} for it.
210:             *
211:             * @param  hints A map of hints, including the low-level factories to use for CRS creation.
212:             * @return The EPSG factory using PostgreSQL syntax.
213:             * @throws SQLException if connection to the database failed.
214:             */
215:            public AbstractAuthorityFactory createFactory(final Hints hints)
216:                    throws SQLException {
217:                final FactoryUsingAnsiSQL factory = new FactoryUsingAnsiSQL(
218:                        hints, getConnection());
219:                if (schema != null) {
220:                    factory.setSchema(schema);
221:                }
222:                return factory;
223:            }
224:
225:            /**
226:             * For compilation with Java 6.
227:             */
228:            public boolean isWrapperFor(Class type) {
229:                return false;
230:            }
231:
232:            /**
233:             * For compilation with Java 6.
234:             */
235:            public Object unwrap(Class type) throws SQLException {
236:                throw new SQLException();
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.