001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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.xml;
017:
018: import java.io.File;
019: import java.net.URI;
020: import java.util.logging.Level;
021:
022: import javax.xml.parsers.SAXParser;
023: import javax.xml.parsers.SAXParserFactory;
024:
025: import org.geotools.feature.Feature;
026: import org.geotools.feature.FeatureCollection;
027: import org.geotools.feature.FeatureIterator;
028: import org.geotools.TestData;
029:
030: import junit.framework.TestCase;
031:
032: /**
033: *
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/GMLInheritanceTest.java $
035: */
036: public class GMLInheritanceTest extends TestCase {
037:
038: public void testNestedFeature() throws Throwable {
039: SAXParserFactory spf = SAXParserFactory.newInstance();
040: spf.setNamespaceAware(true);
041: spf.setValidating(false);
042:
043: SAXParser parser = spf.newSAXParser();
044:
045: String path = "xml/sample/nestedFeatures.xml";
046: File f = TestData.copy(this , path);
047: TestData.copy(this , "xml/sample/nestedFeatures.xsd");
048: URI u = f.toURI();
049:
050: XMLSAXHandler xmlContentHandler = new XMLSAXHandler(u, null);
051: XMLSAXHandler.setLogLevel(Level.FINEST);
052: XSISAXHandler.setLogLevel(Level.FINEST);
053: XMLElementHandler.setLogLevel(Level.FINEST);
054: XSIElementHandler.setLogLevel(Level.FINEST);
055:
056: parser.parse(f, xmlContentHandler);
057:
058: Object doc = xmlContentHandler.getDocument();
059: assertNotNull("Document missing", doc);
060: // System.out.println(doc);
061:
062: checkFeatureCollection((FeatureCollection) doc);
063: }
064:
065: public void testMultiInheritance() throws Throwable {
066: SAXParserFactory spf = SAXParserFactory.newInstance();
067: spf.setNamespaceAware(true);
068: spf.setValidating(false);
069:
070: SAXParser parser = spf.newSAXParser();
071:
072: String path = "xml/sample/multiInheritance.xml";
073: File f = TestData.copy(this , path);
074: TestData.copy(this , "xml/sample/multiInheritance.xsd");
075: URI u = f.toURI();
076:
077: XMLSAXHandler xmlContentHandler = new XMLSAXHandler(u, null);
078: XMLSAXHandler.setLogLevel(Level.FINEST);
079: XSISAXHandler.setLogLevel(Level.FINEST);
080: XMLElementHandler.setLogLevel(Level.FINEST);
081: XSIElementHandler.setLogLevel(Level.FINEST);
082:
083: parser.parse(f, xmlContentHandler);
084:
085: Object doc = xmlContentHandler.getDocument();
086: assertNotNull("Document missing", doc);
087: // System.out.println(doc);
088:
089: checkFeatureCollection((FeatureCollection) doc);
090: }
091:
092: private void checkFeatureCollection(FeatureCollection doc) {
093:
094: //remaining slot (s) should be feature(s)
095: assertTrue("Requires atleast one feature", doc.size() > 0); //bbox + feature
096: FeatureIterator i = doc.features();
097: int j = 1;
098: while (i.hasNext()) {
099: Feature ft = i.next();
100: assertNotNull("Feature #" + j + " is null", ft);
101: // assertNotNull("Feature #"+j+" missing crs ",ft.getFeatureType().getDefaultGeometry().getCoordinateSystem());
102: // System.out.println("Feature "+j+" : "+ft);
103: j++;
104: }
105: assertEquals(2, j);
106: // System.out.println("Found "+j+" Features");
107: }
108: }
|