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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-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.data;
017:
018:        import java.io.IOException;
019:        import java.util.NoSuchElementException;
020:        import java.util.logging.Logger;
021:
022:        import org.geotools.feature.Feature;
023:        import org.geotools.feature.FeatureType;
024:        import org.geotools.feature.FeatureTypeFactory;
025:        import org.geotools.feature.IllegalAttributeException;
026:        import org.geotools.feature.SchemaException;
027:
028:        /**
029:         * Experimental FeatureReader that always takes the first column of the
030:         * attributeReader as the FeatureID.  I want to get this working with postgis,
031:         * but then will consider other options, for those who want featureIDs created
032:         * automatically.  Perhaps a constructor param or a method to say that you
033:         * would just like to have the FeatureReader increment one for each feature,
034:         * prepending the typeName.  I'm also don't really like the one argument
035:         * constructor defaulting to the xxx typename.  I feel that it should perhaps
036:         * take a typename.  If people deliberately set to null then we could use xxx
037:         * or something. ch
038:         * 
039:         * <p>
040:         * This now feels sorta hacky, I'm not sure that I like it, but I'm going to
041:         * commit as I need to go now and revisit it in a bit.  I think the idea of
042:         * passing in an FIDAttributeReader might be cleaner, and if none is provided
043:         * then do an auto-increment one.  This might then work as the
044:         * DefaultFeatureReader.
045:         * </p>
046:         *
047:         * @author Ian Schneider
048:         * @author Chris Holmes, TOPP
049:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/data/FIDFeatureReader.java $
050:         * @version $Id: FIDFeatureReader.java 27862 2007-11-12 19:51:19Z desruisseaux $
051:         */
052:        public class FIDFeatureReader implements  FeatureReader {
053:            /** The logger for the data module. */
054:            private static final Logger LOGGER = org.geotools.util.logging.Logging
055:                    .getLogger("org.geotools.data");
056:            private final AttributeReader attributeReader;
057:            private final FeatureType schema;
058:            private final FIDReader fidReader;
059:            protected final Object[] attributes;
060:
061:            /**
062:             * Creates a new instance of AbstractFeatureReader
063:             *
064:             * @param attributeReader AttributeReader
065:             * @param fidReader FIDReader used to ID Features
066:             * @param schema FeatureType to use, may be <code>null</code>
067:             *
068:             * @throws SchemaException if we could not determine the correct
069:             *         FeatureType
070:             */
071:            public FIDFeatureReader(AttributeReader attributeReader,
072:                    FIDReader fidReader, FeatureType schema)
073:                    throws SchemaException {
074:                this .attributeReader = attributeReader;
075:                this .fidReader = fidReader;
076:
077:                if (schema == null) {
078:                    schema = createSchema();
079:                }
080:
081:                this .schema = schema;
082:                this .attributes = new Object[attributeReader
083:                        .getAttributeCount()];
084:            }
085:
086:            public FIDFeatureReader(AttributeReader attributeReader,
087:                    FIDReader fidReader) throws SchemaException {
088:                this (attributeReader, fidReader, null);
089:            }
090:
091:            public Feature next() throws IOException,
092:                    IllegalAttributeException, NoSuchElementException {
093:                if (attributeReader.hasNext()) {
094:                    attributeReader.next();
095:
096:                    return readFeature(attributeReader);
097:                } else {
098:                    throw new NoSuchElementException(
099:                            "There are no more Features to be read");
100:                }
101:            }
102:
103:            protected FeatureType createSchema() throws SchemaException {
104:                FeatureTypeFactory factory = FeatureTypeFactory
105:                        .newInstance("xxx");
106:
107:                for (int i = 0, ii = attributeReader.getAttributeCount(); i < ii; i++) {
108:                    factory.addType(attributeReader.getAttributeType(i));
109:                }
110:
111:                return factory.getFeatureType();
112:            }
113:
114:            protected Feature readFeature(AttributeReader atts)
115:                    throws IllegalAttributeException, IOException {
116:
117:                //Seems like doing it here could be a bit expensive.
118:                //The other option from this is to have this constructed with two
119:                //attributeReaders, the FID one and real attributes one.  Could then
120:                //have default FIDAttributeReader.
121:                String fid = fidReader.next();
122:
123:                for (int i = 0, ii = atts.getAttributeCount(); i < ii; i++) {
124:                    attributes[i] = atts.read(i);
125:                }
126:
127:                return schema.create(attributes, fid);
128:            }
129:
130:            public void close() throws IOException {
131:                fidReader.close();
132:                attributeReader.close();
133:            }
134:
135:            public FeatureType getFeatureType() {
136:                return schema;
137:            }
138:
139:            public boolean hasNext() throws IOException {
140:                return attributeReader.hasNext();
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.