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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2006-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.catalog.shapefile;
017:
018:        import java.io.IOException;
019:        import java.net.URI;
020:        import java.net.URISyntaxException;
021:
022:        import org.geotools.catalog.AbstractGeoResource;
023:        import org.geotools.catalog.GeoResource;
024:        import org.geotools.catalog.GeoResourceInfo;
025:        import org.geotools.catalog.Service;
026:        import org.geotools.catalog.defaults.DefaultGeoResourceInfo;
027:        import org.geotools.data.DataStore;
028:        import org.geotools.data.FeatureSource;
029:        import org.geotools.data.FeatureStore;
030:        import org.geotools.feature.Feature;
031:        import org.geotools.feature.FeatureIterator;
032:        import org.geotools.feature.FeatureType;
033:        import org.geotools.geometry.jts.ReferencedEnvelope;
034:        import org.geotools.util.ProgressListener;
035:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
036:
037:        import com.vividsolutions.jts.geom.Envelope;
038:
039:        /**
040:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/catalog/shapefile/ShapefileGeoResource.java $
041:         */
042:        public class ShapefileGeoResource extends AbstractGeoResource {
043:            private ShapefileService parent;
044:            private String typeName;
045:            private Throwable msg;
046:            private GeoResourceInfo info;
047:            private FeatureSource featureSource;
048:
049:            ShapefileGeoResource(ShapefileService parent, String typeName) {
050:                this .parent = parent;
051:                this .typeName = typeName;
052:            }
053:
054:            public boolean canResolve(Class adaptee) {
055:                if (adaptee == null) {
056:                    return false;
057:                }
058:
059:                return adaptee.isAssignableFrom(Service.class)
060:                        || adaptee.isAssignableFrom(GeoResourceInfo.class)
061:                        || adaptee.isAssignableFrom(FeatureStore.class)
062:                        || adaptee.isAssignableFrom(FeatureSource.class);
063:            }
064:
065:            public Object resolve(Class adaptee, ProgressListener monitor)
066:                    throws IOException {
067:                if (adaptee == null) {
068:                    return null;
069:                }
070:
071:                if (adaptee.isAssignableFrom(Service.class)) {
072:                    return parent;
073:                }
074:
075:                if (adaptee.isAssignableFrom(GeoResource.class)) {
076:                    return getInfo(monitor);
077:                }
078:
079:                if (adaptee.isAssignableFrom(FeatureStore.class)) {
080:                    FeatureSource featureSource = getFeatureSource(monitor);
081:
082:                    if (featureSource instanceof  FeatureStore) {
083:                        return featureSource;
084:                    }
085:                }
086:
087:                if (adaptee.isAssignableFrom(FeatureSource.class)) {
088:                    return getFeatureSource(monitor);
089:                }
090:
091:                return null;
092:            }
093:
094:            public GeoResourceInfo getInfo(ProgressListener monitor)
095:                    throws IOException {
096:                if (info == null) {
097:                    synchronized (parent.getDataStore(monitor)) {
098:                        if (info == null) {
099:                            //calculate some meta data based on the feature type
100:                            FeatureType type = getFeatureSource(monitor)
101:                                    .getSchema();
102:                            CoordinateReferenceSystem crs = type
103:                                    .getDefaultGeometry().getCoordinateSystem();
104:                            URI schema = type.getNamespace();
105:                            String name = type.getTypeName();
106:                            String title = name;
107:                            String description = name;
108:                            String[] keywords = new String[] { ".shp",
109:                                    "Shapefile", name, schema.toString() };
110:
111:                            //calculate bounds
112:                            ReferencedEnvelope bounds = null;
113:
114:                            try {
115:                                Envelope tmpBounds = getFeatureSource(monitor)
116:                                        .getBounds();
117:
118:                                if (tmpBounds instanceof  ReferencedEnvelope) {
119:                                    bounds = (ReferencedEnvelope) tmpBounds;
120:                                } else {
121:                                    bounds = new ReferencedEnvelope(tmpBounds,
122:                                            crs);
123:                                }
124:
125:                                if (bounds == null) {
126:                                    bounds = new ReferencedEnvelope(
127:                                            new Envelope(), crs);
128:                                    FeatureIterator reader = getFeatureSource(
129:                                            monitor).getFeatures().features();
130:                                    try {
131:                                        while (reader.hasNext()) {
132:                                            Feature element = reader.next();
133:
134:                                            if (bounds.isNull()) {
135:                                                bounds
136:                                                        .init(element
137:                                                                .getBounds());
138:                                            } else {
139:                                                bounds.expandToInclude(element
140:                                                        .getBounds());
141:                                            }
142:                                        }
143:                                    } finally {
144:                                        reader.close();
145:                                    }
146:                                }
147:                            } catch (Exception e) {
148:                                //something bad happend, return an i dont know
149:                                bounds = new ReferencedEnvelope(new Envelope(),
150:                                        crs);
151:                            }
152:
153:                            info = new DefaultGeoResourceInfo(title, name,
154:                                    description, schema, bounds, crs, keywords,
155:                                    null);
156:                        }
157:                    }
158:                }
159:
160:                return info;
161:            }
162:
163:            protected FeatureSource getFeatureSource(ProgressListener monitor)
164:                    throws IOException {
165:                if (featureSource == null) {
166:                    synchronized (parent.getDataStore(monitor)) {
167:                        if (featureSource == null) {
168:                            try {
169:                                msg = null;
170:
171:                                DataStore dataStore = parent
172:                                        .getDataStore(monitor);
173:
174:                                if (dataStore != null) {
175:                                    featureSource = dataStore
176:                                            .getFeatureSource(typeName);
177:                                }
178:                            } catch (IOException ioe) {
179:                                msg = ioe;
180:                                throw ioe;
181:                            } catch (Throwable t) {
182:                                msg = t;
183:                                throw (IOException) new IOException()
184:                                        .initCause(t);
185:                            }
186:                        }
187:                    }
188:                }
189:
190:                return featureSource;
191:            }
192:
193:            public Status getStatus() {
194:                if (msg == null) {
195:                    if (featureSource != null) {
196:                        return Status.CONNECTED;
197:                    }
198:
199:                    return Status.NOTCONNECTED;
200:                }
201:
202:                return Status.BROKEN;
203:            }
204:
205:            public Throwable getMessage() {
206:                return msg;
207:            }
208:
209:            public URI getIdentifier() {
210:                URI uri = parent.getIdentifier();
211:
212:                if (uri != null) {
213:                    try {
214:                        return new URI(uri.toString() + "#" + typeName);
215:                    } catch (URISyntaxException e) {
216:                        return null;
217:                    }
218:                }
219:
220:                return null;
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.