Source Code Cross Referenced for OGRDataStoreFactory.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » ogr » 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.data.ogr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-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; either
009:         *    version 2.1 of the License, or (at your option) any later version.
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.data.ogr;
017:
018:        import java.io.IOException;
019:        import java.net.MalformedURLException;
020:        import java.net.URI;
021:        import java.net.URL;
022:        import java.util.Collections;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:
026:        import org.gdal.ogr.DataSource;
027:        import org.gdal.ogr.Driver;
028:        import org.gdal.ogr.ogr;
029:        import org.geotools.data.DataSourceException;
030:        import org.geotools.data.DataStore;
031:        import org.geotools.data.DataStoreFactorySpi;
032:        import org.geotools.data.FileDataStoreFactorySpi;
033:
034:        /**
035:         * Implementation of the DataStore service provider interface for OGR.
036:         *
037:         * @author Andrea Aime, TOPP
038:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/ogr/src/main/java/org/geotools/data/ogr/OGRDataStoreFactory.java $
039:         * @version $Id: OGRDataStoreFactory.java 25075 2007-04-09 19:20:46Z desruisseaux $
040:         */
041:        public class OGRDataStoreFactory implements  DataStoreFactorySpi {
042:            public static final Param OGR_NAME = new Param("OGRName",
043:                    String.class,
044:                    "Name of the file, or data source to try and open", true);
045:
046:            public static final Param OGR_DRIVER_NAME = new Param(
047:                    "OGRDriverName",
048:                    String.class,
049:                    "Name of the OGR driver to be used. Required to create a new data source, optional when opening an existing one",
050:                    false);
051:
052:            public static final Param NAMESPACEP = new Param("namespace",
053:                    URI.class, "uri to a the namespace", false); //not required
054:
055:            static {
056:                // perform OGR format registration once
057:                if (ogr.GetDriverCount() == 0)
058:                    ogr.RegisterAll();
059:            }
060:
061:            /** 
062:             * Caches opened data stores. 
063:             * TODO: is this beneficial or problematic? It's a static cache, so opening a lot of
064:             * datastore (thousands, hundreds of thousands...) may become a memory problem.
065:             * Plus OGR is not designed to be thread safe.
066:             */
067:            private Map liveStores = new HashMap();
068:
069:            public boolean canProcess(Map params) {
070:                boolean accept = false;
071:                String ogrName = null;
072:                String ogrDriver = null;
073:                try {
074:                    ogrName = (String) OGR_NAME.lookUp(params);
075:                } catch (IOException ioe) {
076:                    // yes, I am eating this
077:                }
078:                try {
079:                    ogrDriver = (String) OGR_DRIVER_NAME.lookUp(params);
080:                } catch (IOException ioe) {
081:                    // yes, I am eating this
082:                }
083:
084:                accept = canProcess(ogrName, ogrDriver);
085:                return accept;
086:            }
087:
088:            public DataStore createDataStore(Map params) throws IOException {
089:                DataStore ds = null;
090:                if (!liveStores.containsKey(params)) {
091:
092:                    URL url = null;
093:                    try {
094:                        ds = createNewDataStore(params);
095:                        liveStores.put(params, ds);
096:                    } catch (MalformedURLException mue) {
097:                        throw new DataSourceException(
098:                                "Unable to attatch datastore to " + url, mue);
099:                    }
100:                } else
101:                    ds = (DataStore) liveStores.get(params);
102:                return ds;
103:            }
104:
105:            /**
106:             * Not implemented yet.
107:             *
108:             * @param params
109:             *
110:             * @throws IOException 
111:             *
112:             * @throws IOException DOCUMENT ME!
113:             * @throws UnsupportedOperationException
114:             */
115:            public DataStore createNewDataStore(Map params) throws IOException {
116:
117:                DataStore ds = null;
118:
119:                String ogrName = (String) OGR_NAME.lookUp(params);
120:                String ogrDriver = (String) OGR_DRIVER_NAME.lookUp(params);
121:                URI namespace = (URI) NAMESPACEP.lookUp(params);
122:                ds = new OGRDataStore(ogrName, ogrDriver, namespace);
123:
124:                return ds;
125:            }
126:
127:            public String getDisplayName() {
128:                return "Shapefile";
129:            }
130:
131:            /**
132:             * Describes the type of data the datastore returned by this factory works
133:             * with.
134:             *
135:             * @return String a human readable description of the type of restore
136:             *         supported by this datastore.
137:             */
138:            public String getDescription() {
139:                return "ESRI(tm) Shapefiles (*.shp)";
140:            }
141:
142:            //    public DataSourceMetadataEnity createMetadata( Map params )
143:            //            throws IOException {
144:            //        
145:            //        URL url = (URL) URLP.lookUp(params);
146:            //        Boolean mm = (Boolean) MEMORY_MAPPED.lookUp(params);
147:            //        
148:            //        String server;
149:            //        String name;
150:            //        if( url.getProtocol().equals("file")){
151:            //            server = "localhost";
152:            //            name = url.getPath();
153:            //        }
154:            //        else {
155:            //            server = url.getHost()+":"+url.getPort();
156:            //            name = url.getFile();
157:            //        }
158:            //        return new DataSourceMetadataEnity( server, name, "Shapefile access for "+url );
159:            //    }
160:            /**
161:             * Test to see if this datastore is available, if it has all the
162:             * appropriate libraries to construct a datastore.  This datastore just
163:             * returns true for now.
164:             *
165:             * @return <tt>true</tt> if and only if this factory is available to create
166:             *         DataStores.
167:             *
168:             * @task REVISIT: I'm just adding this method to compile, maintainer should
169:             *       revisit to check for any libraries that may be necessary for
170:             *       datastore creations.
171:             */
172:            public boolean isAvailable() {
173:                return true;
174:            }
175:
176:            /**
177:             * Describe parameters.
178:             *
179:             *
180:             * @see org.geotools.data.DataStoreFactorySpi#getParametersInfo()
181:             */
182:            public Param[] getParametersInfo() {
183:                return new Param[] { OGR_NAME };
184:            }
185:
186:            /**
187:             * @see org.geotools.data.dir.FileDataStoreFactorySpi#getFileExtensions()
188:             */
189:            public String[] getFileExtensions() {
190:                return new String[] { ".shp", };
191:            }
192:
193:            /**
194:             * Assume we can process an ogrName if the ogrName exists and can be opened, or if
195:             * the specified driver does exist.
196:             * @param ogrName
197:             * @param driver
198:             * @return
199:             */
200:            public boolean canProcess(String ogrName, String driver) {
201:                DataSource ds = ogr.OpenShared(ogrName, OGRDataStore.FALSE);
202:                if (ds != null) {
203:                    ds.delete();
204:                    return true;
205:                }
206:
207:                Driver dr = ogr.GetDriverByName(driver);
208:                if (dr != null) {
209:                    dr.delete();
210:                    return true;
211:                }
212:
213:                return false;
214:
215:            }
216:
217:            public Map getImplementationHints() {
218:                return Collections.EMPTY_MAP;
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.