Source Code Cross Referenced for FeatureWrapper.java in  » GIS » udig-1.1 » net » refractions » udig » catalog » ui » export » 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 » udig 1.1 » net.refractions.udig.catalog.ui.export 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.catalog.ui.export;
016:
017:        import net.refractions.udig.catalog.CatalogPlugin;
018:
019:        import org.eclipse.core.runtime.IStatus;
020:        import org.eclipse.core.runtime.Status;
021:        import org.geotools.feature.AttributeType;
022:        import org.geotools.feature.Feature;
023:        import org.geotools.feature.FeatureCollection;
024:        import org.geotools.feature.FeatureType;
025:        import org.geotools.feature.GeometryAttributeType;
026:        import org.geotools.feature.IllegalAttributeException;
027:        import org.geotools.feature.type.GeometricAttributeType;
028:
029:        import com.vividsolutions.jts.geom.Envelope;
030:        import com.vividsolutions.jts.geom.Geometry;
031:
032:        /**
033:         * Adapts an existing feature of one Feature type to another of a "compatible" feature type.  
034:         * <p>
035:         * A compatible feature type are feature types that have the same attributes types but maybe in a different order 
036:         * and the second (the type being adapted to) may have fewer attribute types. 
037:         * </p>
038:         * 
039:         * @author Jesse
040:         */
041:        class FeatureWrapper implements  Feature {
042:            protected final Feature wrapped;
043:            protected final FeatureType featureType;
044:            protected final Geometry[] geometry;
045:            protected final String[] geomAttNames;
046:            protected Geometry defaultGeometry;
047:
048:            /**
049:             * New instance
050:             * @param wrapped Feature that needs to be adapted to new FeatureType
051:             * @param featureType the new feature type.  Must be "compatible" with featureType of wrapped.  
052:             * 			See javadocs for class for more information
053:             * @param geometries the geometries to use instead of the feature's geometries this allows the geometries to be transformed
054:             * @param geomAttNames the attribute names of the geometries so we know how to put them in the attribute array.
055:             * 
056:             * @throws IllegalAttributeException Thrown if the default geometry does not exist
057:             */
058:            public FeatureWrapper(final Feature wrapped,
059:                    final FeatureType featureType, Geometry[] geometries,
060:                    String[] geomAttNames) throws IllegalArgumentException {
061:                super ();
062:                this .wrapped = wrapped;
063:                this .featureType = featureType;
064:                this .geometry = geometries;
065:                this .geomAttNames = geomAttNames;
066:                String defaultGeomName = featureType.getDefaultGeometry()
067:                        .getName();
068:                this .defaultGeometry = findTransformedGeometry(defaultGeomName);
069:            }
070:
071:            private Geometry findTransformedGeometry(String defaultGeomName)
072:                    throws IllegalArgumentException {
073:                for (int i = 0; i < geomAttNames.length; i++) {
074:                    String attName = geomAttNames[i];
075:                    if (attName.equals(defaultGeomName))
076:                        return geometry[i];
077:                }
078:                throw new IllegalArgumentException(
079:                        "Attribute does not exist:" + defaultGeomName); //$NON-NLS-1$
080:            }
081:
082:            public final Object getAttribute(int index) {
083:                return getAttribute(featureType.getAttributeType(index)
084:                        .getName());
085:            }
086:
087:            public Object getAttribute(String xPath) {
088:                AttributeType type = featureType.getAttributeType(xPath);
089:
090:                if (type instanceof  GeometryAttributeType) {
091:                    return findTransformedGeometry(xPath);
092:                }
093:
094:                return wrapped.getAttribute(xPath);
095:            }
096:
097:            public Object[] getAttributes(Object[] attributes) {
098:                if (attributes == null || attributes.length == 0) {
099:                    attributes = new Object[featureType.getAttributeCount()];
100:                }
101:                if (attributes.length < featureType.getAttributeCount())
102:                    throw new IllegalArgumentException(
103:                            "There needs to be at least " + featureType.getAttributeCount() + " elements in the provided array"); //$NON-NLS-1$ //$NON-NLS-2$
104:
105:                Object[] atts = new Object[wrapped.getNumberOfAttributes()];
106:                atts = wrapped.getAttributes(atts);
107:                for (int i = 0; i < atts.length; i++) {
108:                    Object object = atts[i];
109:                    AttributeType attributeType = wrapped.getFeatureType()
110:                            .getAttributeType(i);
111:                    int index = featureType.find(attributeType.getName());
112:                    if (index == -1)
113:                        continue;
114:                    if (attributeType instanceof  GeometricAttributeType) {
115:                        attributes[index] = findTransformedGeometry(attributeType
116:                                .getName());
117:                    } else {
118:                        attributes[index] = object;
119:                    }
120:                }
121:                return attributes;
122:            }
123:
124:            public Envelope getBounds() {
125:                return defaultGeometry.getEnvelopeInternal();
126:            }
127:
128:            public Geometry getDefaultGeometry() {
129:                return defaultGeometry;
130:            }
131:
132:            public FeatureType getFeatureType() {
133:                return featureType;
134:            }
135:
136:            public String getID() {
137:                return wrapped.getID();
138:            }
139:
140:            public int getNumberOfAttributes() {
141:                return featureType.getAttributeCount();
142:            }
143:
144:            @SuppressWarnings("deprecation")
145:            public FeatureCollection getParent() {
146:                return wrapped.getParent();
147:            }
148:
149:            public void setAttribute(int position, Object val)
150:                    throws IllegalAttributeException,
151:                    ArrayIndexOutOfBoundsException {
152:                throw new UnsupportedOperationException();
153:            }
154:
155:            public void setAttribute(String xPath, Object attribute)
156:                    throws IllegalAttributeException {
157:                throw new UnsupportedOperationException();
158:            }
159:
160:            public void setDefaultGeometry(Geometry geometry)
161:                    throws IllegalAttributeException {
162:                throw new UnsupportedOperationException();
163:            }
164:
165:            public void setParent(FeatureCollection collection) {
166:                throw new UnsupportedOperationException();
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.