Index: modules/library/main/src/main/java/org/geotools/gml/SubHandlerPolygon.java =================================================================== --- modules/library/main/src/main/java/org/geotools/gml/SubHandlerPolygon.java (r‚vision 25355) +++ modules/library/main/src/main/java/org/geotools/gml/SubHandlerPolygon.java (copie de travail) @@ -112,6 +112,7 @@ newPoints[i] = points[j]; } + //Curious : the exception seems to be never thrown try { ring = geometryFactory.createLinearRing(newPoints); innerBoundaries.add(ring); @@ -140,6 +141,7 @@ newPoints[i] = points[j]; } + //Curious : the exception seems to be never thrown try { outerBoundary = geometryFactory.createLinearRing(newPoints); //System.out.println("outer boundary: " + message); @@ -209,15 +211,12 @@ * * @return Completed OGC Polygon. */ - public Geometry create(GeometryFactory geometryFactory) { + public Geometry create(GeometryFactory geometryFactory) throws TopologyException { for (int i = 0; i < innerBoundaries.size(); i++) { LinearRing hole = (LinearRing) innerBoundaries.get(i); - if (hole.crosses(outerBoundary)) { - LOGGER.warning("Topology Error building polygon"); - - return null; - } + if (hole.crosses(outerBoundary)) + throw new TopologyException("hole crosses outer boundary"); } return geometryFactory.createPolygon(outerBoundary, Index: modules/library/main/src/main/java/org/geotools/gml/GMLFilterGeometry.java =================================================================== --- modules/library/main/src/main/java/org/geotools/gml/GMLFilterGeometry.java (r‚vision 25355) +++ modules/library/main/src/main/java/org/geotools/gml/GMLFilterGeometry.java (copie de travail) @@ -17,7 +17,9 @@ import org.xml.sax.SAXException; +import com.vividsolutions.jts.geom.TopologyException; + /** * LEVEL2 saxGML4j GML filter: translates coordinates and GML events into OGC * simple types. @@ -73,7 +75,7 @@ * @throws SAXException parser error. */ public void geometryStart(String localName, org.xml.sax.Attributes atts) - throws SAXException { + throws SAXException, TopologyException { for (int i = 0; i < atts.getLength(); i++) { //getName(i); } @@ -96,7 +98,7 @@ * * @throws SAXException parser error. */ - public void geometryEnd(String localName) throws SAXException { + public void geometryEnd(String localName) throws SAXException, TopologyException { if (currentHandler.isComplete(localName)) { parent.geometry(currentHandler.create(geometryFactory)); currentHandler = null; @@ -114,7 +116,7 @@ * * @throws SAXException parser error. */ - public void geometrySub(String localName) throws SAXException { + public void geometrySub(String localName) throws SAXException, TopologyException { currentHandler.subGeometry(localName, currentHandler.GEOMETRY_SUB); } @@ -128,7 +130,11 @@ * @throws SAXException parser error. */ public void gmlCoordinates(double x, double y) throws SAXException { - currentHandler.addCoordinate(new com.vividsolutions.jts.geom.Coordinate( + //TODO : try to provide a better explanation of why we are reading coordinates + //in what is apparently a wrong place + if (currentHandler == null) + throw new SAXException("geometryStart() has not been called, currentHandler is null"); + currentHandler.addCoordinate(new com.vividsolutions.jts.geom.Coordinate( x, y)); } @@ -144,6 +150,10 @@ */ public void gmlCoordinates(double x, double y, double z) throws SAXException { + //TODO : try to provide a better explanation of why we are reading coordinates + //in what is apparently a wrong place + if (currentHandler == null) + throw new SAXException("geometryStart() has not been called, currentHandler is null"); currentHandler.addCoordinate(new com.vividsolutions.jts.geom.Coordinate( x, y, z)); } Index: modules/library/main/src/main/java/org/geotools/gml/SubHandlerMulti.java =================================================================== --- modules/library/main/src/main/java/org/geotools/gml/SubHandlerMulti.java (r‚vision 25355) +++ modules/library/main/src/main/java/org/geotools/gml/SubHandlerMulti.java (copie de travail) @@ -26,6 +26,7 @@ import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.MultiPoint; import com.vividsolutions.jts.geom.MultiPolygon; +import com.vividsolutions.jts.geom.TopologyException; /** @@ -77,7 +78,7 @@ * @param message The sub geometry type found. * @param type Whether or not it is at a start or end. */ - public void subGeometry(String message, int type) { + public void subGeometry(String message, int type) throws TopologyException { LOGGER.fine("subGeometry message = " + message + " type = " + type); // if the internal type is not yet set, set it Index: modules/library/main/src/main/java/org/geotools/gml/GMLFilterDocument.java =================================================================== --- modules/library/main/src/main/java/org/geotools/gml/GMLFilterDocument.java (r‚vision 25355) +++ modules/library/main/src/main/java/org/geotools/gml/GMLFilterDocument.java (copie de travail) @@ -20,7 +20,9 @@ import org.xml.sax.SAXException; +import com.vividsolutions.jts.geom.TopologyException; + /** * LEVEL1 saxGML4j GML filter: Sends basic alerts for GML types to * GMLFilterGeometry. @@ -133,30 +135,40 @@ * how to handle the element */ if (namespaceURI != null && namespaceURI.equals(GML_NAMESPACE)) { - // if geometry, pass it on down the filter chain - if (BASE_GEOMETRY_TYPES.contains(localName)) { - parent.geometryStart(localName, atts); - } else if (SUB_GEOMETRY_TYPES.contains(localName)) { - parent.geometrySub(localName); - } else if (COORDINATES_NAME.equals(localName)) { - // if coordinate, set one of the internal coordinate methods - coordinateReader.insideCoordinates(true, atts); - buffer = new StringBuffer(); - } else if (COORD_NAME.equals(localName)) { - coordinateReader.insideCoord(true); - buffer = new StringBuffer(); - } else if (X_NAME.equals(localName)) { - buffer = new StringBuffer(); - coordinateReader.insideX(true); - } else if (Y_NAME.equals(localName)) { - buffer = new StringBuffer(); - coordinateReader.insideY(true); - } else if (Z_NAME.equals(localName)) { - buffer = new StringBuffer(); - coordinateReader.insideZ(true); - } else { - parent.startElement(namespaceURI, localName, qName, atts); - } + try { + // if geometry, pass it on down the filter chain + if (BASE_GEOMETRY_TYPES.contains(localName)) { + parent.geometryStart(localName, atts); + } else if (SUB_GEOMETRY_TYPES.contains(localName)) { + parent.geometrySub(localName); + } else if (COORDINATES_NAME.equals(localName)) { + // if coordinate, set one of the internal coordinate methods + coordinateReader.insideCoordinates(true, atts); + buffer = new StringBuffer(); + } else if (COORD_NAME.equals(localName)) { + coordinateReader.insideCoord(true); + buffer = new StringBuffer(); + } else if (X_NAME.equals(localName)) { + buffer = new StringBuffer(); + coordinateReader.insideX(true); + } else if (Y_NAME.equals(localName)) { + buffer = new StringBuffer(); + coordinateReader.insideY(true); + } else if (Z_NAME.equals(localName)) { + buffer = new StringBuffer(); + coordinateReader.insideZ(true); + } else { + parent.startElement(namespaceURI, localName, qName, atts); + } + } catch (SAXException e) { + SAXException e1 = new SAXException("Exception when starting <" + qName + ">"); + e1.initCause(e); + throw e1; + } catch (TopologyException e) { + SAXException e1 = new SAXException("Exception when starting <" + qName + ">"); + e1.initCause(e); + throw e1; + } } else { /* all non-GML elements passed on down the filter chain without * modification @@ -247,38 +259,48 @@ * internal or external method */ if (namespaceURI.equals(GML_NAMESPACE) || !namespaceAware) { - // if geometry, pass on down the chain to appropriate handlers - if (BASE_GEOMETRY_TYPES.contains(localName)) { - parent.geometryEnd(localName); - } else if (SUB_GEOMETRY_TYPES.contains(localName)) { - parent.geometrySub(localName); - } else if (COORDINATES_NAME.equals(localName)) { - // Convert the string buffer to a string and process the - // coordinate, then end the coordinate status in the handler. - coordinateReader.readCoordinates(buffer.toString()); - coordinateReader.insideCoordinates(false); - } else if (COORD_NAME.equals(localName)) { - coordinateReader.readCoord(buffer.toString()); - coordinateReader.insideCoord(false); - } else if (X_NAME.equals(localName)) { - coordinateReader.readCoord(buffer.toString()); - coordinateReader.insideX(false); - } else if (Y_NAME.equals(localName)) { - coordinateReader.readCoord(buffer.toString()); - coordinateReader.insideY(false); - } else if (Z_NAME.equals(localName)) { - coordinateReader.readCoord(buffer.toString()); - coordinateReader.insideZ(false); - } else if (!namespaceAware) { - /* if not namespace aware, then just pass element through; - * otherwise, there is some error in the GML - */ - parent.endElement(namespaceURI, localName, qName); - } else { - parent.endElement(namespaceURI, localName, qName); - } - - //else { throw new SAXException("Unrecognized GML element."); } + try { + // if geometry, pass on down the chain to appropriate handlers + if (BASE_GEOMETRY_TYPES.contains(localName)) { + parent.geometryEnd(localName); + } else if (SUB_GEOMETRY_TYPES.contains(localName)) { + parent.geometrySub(localName); + } else if (COORDINATES_NAME.equals(localName)) { + // Convert the string buffer to a string and process the + // coordinate, then end the coordinate status in the handler. + coordinateReader.readCoordinates(buffer.toString()); + coordinateReader.insideCoordinates(false); + } else if (COORD_NAME.equals(localName)) { + coordinateReader.readCoord(buffer.toString()); + coordinateReader.insideCoord(false); + } else if (X_NAME.equals(localName)) { + coordinateReader.readCoord(buffer.toString()); + coordinateReader.insideX(false); + } else if (Y_NAME.equals(localName)) { + coordinateReader.readCoord(buffer.toString()); + coordinateReader.insideY(false); + } else if (Z_NAME.equals(localName)) { + coordinateReader.readCoord(buffer.toString()); + coordinateReader.insideZ(false); + } else if (!namespaceAware) { + /* if not namespace aware, then just pass element through; + * otherwise, there is some error in the GML + */ + parent.endElement(namespaceURI, localName, qName); + } else { + parent.endElement(namespaceURI, localName, qName); + } + + //else { throw new SAXException("Unrecognized GML element."); } + } catch (SAXException e) { + SAXException e1 = new SAXException("Exception when ending <" + qName + ">"); + e1.initCause(e); + throw e1; + } catch (TopologyException e) { + SAXException e1 = new SAXException("Exception when ending <" + qName + ">"); + e1.initCause(e); + throw e1; + } } else { /* all non-GML elements passed on down the filter chain * without modification