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


001:        /*
002:         *    Geotools2 - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-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:         */
017:        package org.geotools.data.complex;
018:
019:        import java.io.IOException;
020:        import java.net.URL;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Map;
025:        import java.util.Set;
026:        import java.util.logging.Logger;
027:
028:        import junit.framework.TestCase;
029:
030:        import org.apache.xml.resolver.Catalog;
031:        import org.apache.xml.resolver.tools.ResolvingXMLReader;
032:        import org.geotools.data.DataAccessFinder;
033:        import org.geotools.data.complex.config.ComplexDataStoreConfigurator;
034:        import org.geotools.data.complex.config.ComplexDataStoreDTO;
035:        import org.geotools.data.complex.config.EmfAppSchemaReader;
036:        import org.geotools.data.complex.config.XMLConfigDigester;
037:        import org.geotools.data.complex.filter.XPath.StepList;
038:        import org.geotools.data.feature.FeatureAccess;
039:        import org.geotools.data.feature.FeatureSource2;
040:        import org.geotools.feature.iso.Types;
041:        import org.geotools.test.TestData;
042:        import org.opengis.feature.Feature;
043:        import org.opengis.feature.FeatureCollection;
044:        import org.opengis.feature.type.AttributeDescriptor;
045:        import org.opengis.feature.type.ComplexType;
046:        import org.opengis.feature.type.FeatureType;
047:        import org.opengis.feature.type.Name;
048:        import org.opengis.filter.expression.Expression;
049:        import org.opengis.filter.expression.Function;
050:        import org.opengis.filter.expression.Literal;
051:        import org.opengis.filter.expression.PropertyName;
052:
053:        /**
054:         * DOCUMENT ME!
055:         * 
056:         * @author Rob Atkinson
057:         * @version $Id: GeoSciMLTest.java 29135 2008-02-07 19:49:09Z desruisseaux $
058:         * @source $URL:
059:         *         http://svn.geotools.org/geotools/branches/2.4.x/modules/unsupported/community-schemas/community-schema-ds/src/test/java/org/geotools/data/complex/BoreholeTest.java $
060:         * @since 2.4
061:         */
062:        public class GeoSciMLTest extends TestCase {
063:            private static final Logger LOGGER = org.geotools.util.logging.Logging
064:                    .getLogger(GeoSciMLTest.class.getPackage().getName());
065:
066:            private static final String GSMLNS = "http://www.cgi-iugs.org/xml/GeoSciML/2";
067:
068:            private static final String GMLNS = "http://www.opengis.net/gml";
069:
070:            final String schemaBase = "/test-data/";
071:
072:            EmfAppSchemaReader reader;
073:
074:            private FeatureSource2 source;
075:
076:            /**
077:             * DOCUMENT ME!
078:             * 
079:             * @throws Exception
080:             *             DOCUMENT ME!
081:             */
082:            protected void setUp() throws Exception {
083:                super .setUp();
084:                reader = EmfAppSchemaReader.newInstance();
085:                // Logging.GEOTOOLS.forceMonolineConsoleOutput(Level.FINEST);
086:            }
087:
088:            /**
089:             * DOCUMENT ME!
090:             * 
091:             * @throws Exception
092:             *             DOCUMENT ME!
093:             */
094:            protected void tearDown() throws Exception {
095:                super .tearDown();
096:            }
097:
098:            /**
099:             * 
100:             * @param location
101:             *            schema location path discoverable through
102:             *            getClass().getResource()
103:             */
104:            private void loadSchema(String location) throws IOException {
105:                // load needed GML types directly from the gml schemas
106:                //        URL schemaLocation = getClass().getResource(location);
107:                //        assertNotNull(location, schemaLocation);
108:
109:                URL catalogLocation = getClass().getResource(
110:                        schemaBase + "mappedPolygons.oasis.xml");
111:                Catalog catalog = new ResolvingXMLReader().getCatalog();
112:                catalog.getCatalogManager().setVerbosity(9);
113:                catalog.parseCatalog(catalogLocation);
114:
115:                reader.setCatalog(catalog);
116:
117:                reader.parse(new URL(location));
118:            }
119:
120:            /**
121:             * Tests if the schema-to-FM parsing code developed for complex datastore
122:             * configuration loading can parse the GeoSciML types
123:             * 
124:             * @throws Exception
125:             */
126:            public void testParseSchema() throws Exception {
127:                try {
128:                    //loadSchema(schemaBase + "commonSchemas_new/GeoSciML/Gsml.xsd");
129:                    //use the absolute URL and let the Oasis Catalog resolve it to the local FS
130:                    loadSchema("http://schemas.opengis.net/GeoSciML/Gsml.xsd");
131:                } catch (Exception e) {
132:                    e.printStackTrace();
133:                    throw e;
134:                }
135:
136:                Map typeRegistry = reader.getTypeRegistry();
137:
138:                Name typeName = Types.typeName(GSMLNS, "MappedFeatureType");
139:                ComplexType mf = (ComplexType) typeRegistry.get(typeName);
140:                assertNotNull(mf);
141:                assertTrue(mf instanceof  FeatureType);
142:
143:                typeName = Types.typeName(
144:                        "http://www.opengis.net/sampling/1.0",
145:                        "SamplingFeatureType");
146:                mf = (ComplexType) typeRegistry.get(typeName);
147:                assertNotNull(mf);
148:                assertTrue(mf instanceof  FeatureType);
149:                /*
150:                 * AttributeType superType = mf.getSuper(); assertNotNull(superType);
151:                 * Name superTypeName = Types.typeName(SANS, "ProfileType");
152:                 * assertEquals(superTypeName, superType.getName());
153:                 * assertTrue(superType instanceof FeatureType); // ensure all needed
154:                 * types were parsed and aren't just empty proxies Collection properties =
155:                 * mf.getProperties(); assertEquals(16, properties.size()); Map
156:                 * expectedNamesAndTypes = new HashMap(); // from
157:                 * gml:AbstractFeatureType expectedNamesAndTypes.put(name(GMLNS,
158:                 * "metaDataProperty"), typeName(GMLNS, "MetaDataPropertyType"));
159:                 * expectedNamesAndTypes.put(name(GMLNS, "description"), typeName(GMLNS,
160:                 * "StringOrRefType")); expectedNamesAndTypes.put(name(GMLNS, "name"),
161:                 * typeName(GMLNS, "CodeType")); expectedNamesAndTypes.put(name(GMLNS,
162:                 * "boundedBy"), typeName(GMLNS, "BoundingShapeType"));
163:                 * expectedNamesAndTypes.put(name(GMLNS, "location"), typeName(GMLNS,
164:                 * "LocationPropertyType")); // from sa:ProfileType
165:                 * expectedNamesAndTypes.put(name(SANS, "begin"), typeName(GMLNS,
166:                 * "PointPropertyType")); expectedNamesAndTypes.put(name(SANS, "end"),
167:                 * typeName(GMLNS, "PointPropertyType"));
168:                 * expectedNamesAndTypes.put(name(SANS, "length"), typeName(SWENS,
169:                 * "RelativeMeasureType")); expectedNamesAndTypes.put(name(SANS,
170:                 * "shape"), typeName(GEONS, "Shape1DPropertyType")); //
171:                 * sa:SamplingFeatureType expectedNamesAndTypes.put(name(SANS,
172:                 * "member"), typeName(SANS, "SamplingFeaturePropertyType"));
173:                 * expectedNamesAndTypes.put(name(SANS, "surveyDetails"), typeName(SANS,
174:                 * "SurveyProcedurePropertyType")); expectedNamesAndTypes.put(name(SANS,
175:                 * "associatedSpecimen"), typeName(SANS, "SpecimenPropertyType"));
176:                 * expectedNamesAndTypes.put(name(SANS, "relatedObservation"),
177:                 * typeName(OMNS, "AbstractObservationPropertyType")); // from
178:                 * xmml:mfType expectedNamesAndTypes.put(name(XMMLNS, "drillMethod"),
179:                 * typeName(XMMLNS, "drillCode"));
180:                 * expectedNamesAndTypes.put(name(XMMLNS, "collarDiameter"),
181:                 * typeName(GMLNS, "MeasureType"));
182:                 * expectedNamesAndTypes.put(name(XMMLNS, "log"), typeName(XMMLNS,
183:                 * "LogPropertyType"));
184:                 * 
185:                 * for (Iterator it = expectedNamesAndTypes.entrySet().iterator();
186:                 * it.hasNext();) { Map.Entry entry = (Entry) it.next(); Name dName =
187:                 * (Name) entry.getKey(); Name tName = (Name) entry.getValue();
188:                 * 
189:                 * AttributeDescriptor d = (AttributeDescriptor) Types.descriptor(mf,
190:                 * dName); assertNotNull("Descriptor not found: " + dName, d);
191:                 * AttributeType type; try { type = d.getType(); } catch (Exception e) {
192:                 * LOGGER.log(Level.SEVERE, "type not parsed for " +
193:                 * ((AttributeDescriptor) d).getName(), e); throw e; }
194:                 * assertNotNull(type); assertNotNull(type.getName());
195:                 * assertNotNull(type.getBinding()); if (tName != null) {
196:                 * assertEquals(tName, type.getName()); } }
197:                 * 
198:                 * Name tcl = Types.typeName(SWENS, "TypedCategoryListType");
199:                 * AttributeType typedCategoryListType = (AttributeType)
200:                 * typeRegistry.get(tcl); assertNotNull(typedCategoryListType);
201:                 * assertFalse(typedCategoryListType instanceof ComplexType);
202:                 */
203:            }
204:
205:            private Name typeName(String ns, String localName) {
206:                return Types.typeName(ns, localName);
207:            }
208:
209:            private Object name(String ns, String localName) {
210:                return new org.geotools.feature.Name(ns, localName);
211:            }
212:
213:            public void testLoadMappingsConfig() throws Exception {
214:                XMLConfigDigester reader = new XMLConfigDigester();
215:                final URL url = getClass().getResource(
216:                        schemaBase + "mappedPolygons.xml");
217:
218:                ComplexDataStoreDTO config = reader.parse(url);
219:
220:                Set mappings = ComplexDataStoreConfigurator
221:                        .buildMappings(config);
222:
223:                assertNotNull(mappings);
224:                assertEquals(1, mappings.size());
225:            }
226:
227:            public void testDataStore() throws Exception {
228:                try {
229:                    final Map dsParams = new HashMap();
230:                    final URL url = getClass().getResource(
231:                            schemaBase + "mappedPolygons.xml");
232:                    assertNotNull(url);
233:                    dsParams.put("dbtype", "complex");
234:                    dsParams.put("url", url.toExternalForm());
235:
236:                    final Name typeName = new org.geotools.feature.Name(GSMLNS,
237:                            "MappedFeature");
238:
239:                    FeatureAccess mappingDataStore = (FeatureAccess) DataAccessFinder
240:                            .createAccess(dsParams);
241:                    assertNotNull(mappingDataStore);
242:                    AttributeDescriptor mappedFeature = (AttributeDescriptor) mappingDataStore
243:                            .describe(typeName);
244:                    assertNotNull(mappedFeature);
245:                    assertTrue(mappedFeature.type() instanceof  FeatureType);
246:                    FeatureType boreholeType = (FeatureType) mappedFeature
247:                            .type();
248:
249:                    FeatureSource2 fSource = (FeatureSource2) mappingDataStore
250:                            .access(typeName);
251:
252:                    final int EXPECTED_RESULT_COUNT = 2;
253:
254:                    FeatureCollection features = (FeatureCollection) fSource
255:                            .content();
256:
257:                    int resultCount = getCount(features);
258:                    assertEquals(EXPECTED_RESULT_COUNT, resultCount);
259:
260:                    Feature feature;
261:                    int count = 0;
262:                    Iterator it = features.iterator();
263:                    for (; it.hasNext();) {
264:                        feature = (Feature) it.next();
265:                        count++;
266:                    }
267:                    features.close(it);
268:                    assertEquals(EXPECTED_RESULT_COUNT, count);
269:                } catch (Exception e) {
270:                    e.printStackTrace();
271:                    throw e;
272:                }
273:            }
274:
275:            private int getCount(FeatureCollection features) {
276:                Iterator iterator = features.iterator();
277:                int count = 0;
278:                try {
279:                    while (iterator.hasNext()) {
280:                        iterator.next();
281:                        count++;
282:                    }
283:                } finally {
284:                    features.close(iterator);
285:                }
286:                return count;
287:            }
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.