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


001:        package org.geotools.data.store;
002:
003:        import java.util.Iterator;
004:
005:        import org.geotools.feature.AttributeType;
006:        import org.geotools.feature.Feature;
007:        import org.geotools.feature.FeatureType;
008:        import org.geotools.feature.IllegalAttributeException;
009:
010:        /**
011:         * Iterator wrapper which re-types features on the fly based on a target 
012:         * feature type.
013:         * 
014:         * @author Justin Deoliveira, The Open Planning Project
015:         *
016:         */
017:        public class ReTypingIterator implements  Iterator {
018:
019:            /**
020:             * The delegate iterator
021:             */
022:            Iterator delegate;
023:            /**
024:             * The target feature type
025:             */
026:            FeatureType target;
027:            /**
028:             * The matching types from target 
029:             */
030:            AttributeType[] types;
031:
032:            public ReTypingIterator(Iterator delegate, FeatureType source,
033:                    FeatureType target) {
034:                this .delegate = delegate;
035:                this .target = target;
036:                types = typeAttributes(source, target);
037:            }
038:
039:            public Iterator getDelegate() {
040:                return delegate;
041:            }
042:
043:            public void remove() {
044:                delegate.remove();
045:            }
046:
047:            public boolean hasNext() {
048:                return delegate.hasNext();
049:            }
050:
051:            public Object next() {
052:                Feature next = (Feature) delegate.next();
053:                String id = next.getID();
054:
055:                Object[] attributes = new Object[types.length];
056:                String xpath;
057:
058:                try {
059:                    for (int i = 0; i < types.length; i++) {
060:                        xpath = types[i].getName();
061:                        //attributes[i] = types[i].duplicate(next.getAttribute(xpath));
062:                        attributes[i] = next.getAttribute(xpath);
063:                    }
064:
065:                    return target.create(attributes, id);
066:                } catch (IllegalAttributeException e) {
067:                    throw new RuntimeException(e);
068:                }
069:            }
070:
071:            /**
072:             * Supplies mapping from origional to target FeatureType.
073:             * 
074:             * <p>
075:             * Will also ensure that origional can cover target
076:             * </p>
077:             *
078:             * @param target Desired FeatureType
079:             * @param origional Origional FeatureType
080:             *
081:             * @return Mapping from originoal to target FeatureType
082:             *
083:             * @throws IllegalArgumentException if unable to provide a mapping
084:             */
085:            protected AttributeType[] typeAttributes(FeatureType original,
086:                    FeatureType target) {
087:                if (target.equals(original)) {
088:                    throw new IllegalArgumentException(
089:                            "FeatureReader allready produces contents with the correct schema");
090:                }
091:
092:                if (target.getAttributeCount() > original.getAttributeCount()) {
093:                    throw new IllegalArgumentException(
094:                            "Unable to retype FeatureReader (origional does not cover requested type)");
095:                }
096:
097:                String xpath;
098:                AttributeType[] types = new AttributeType[target
099:                        .getAttributeCount()];
100:
101:                for (int i = 0; i < target.getAttributeCount(); i++) {
102:                    AttributeType attrib = target.getAttributeType(i);
103:                    xpath = attrib.getName();
104:                    types[i] = attrib;
105:
106:                    if (!attrib.equals(original.getAttributeType(xpath))) {
107:                        throw new IllegalArgumentException(
108:                                "Unable to retype FeatureReader (origional does not cover "
109:                                        + xpath + ")");
110:                    }
111:                }
112:
113:                return types;
114:            }
115:
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.