001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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: package org.geotools.gml;
017:
018: /**
019: * Specifies how a generic OGC simple geometry handler should behave.
020: *
021: * @author Ian Turton, CCG
022: * @author Rob Hranac, Vision for New York
023: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/gml/SubHandler.java $
024: * @version $Id: SubHandler.java 26168 2007-07-06 19:58:03Z jgarnett $
025: */
026: public abstract class SubHandler {
027: /** Indicates start of a geometry. */
028: public static final int GEOMETRY_START = 1;
029:
030: /** Indicates end of a geometry. */
031: public static final int GEOMETRY_END = 2;
032:
033: /** Indicates a sub geometry message. */
034: public static final int GEOMETRY_SUB = 3;
035:
036: private String srs = null;
037:
038: /**
039: * @return the srs
040: */
041: protected String getSRS() {
042: return srs;
043: }
044:
045: /**
046: * Creates a basic SRID by looking at the provided srs.
047: * <p>
048: * As an example "EPSG:4326" would be turned into 4326
049: *
050: * @return An int value based on the srs field, or 0
051: */
052: protected int getSRID() {
053: if (srs == null)
054: return 0;
055: String split[] = srs.split("\\:");
056: try {
057: return Integer.parseInt(split[split.length - 1]);
058: } catch (NumberFormatException ignore) {
059: return 0; // probably some complicated OGC SRS
060: }
061: }
062:
063: public void setSRS(String SRS) {
064: srs = SRS;
065: }
066:
067: /**
068: * Adds a coordinate to the object being built if appropriate.
069: *
070: * @param coordinate Coordinate to add
071: */
072: public abstract void addCoordinate(
073: com.vividsolutions.jts.geom.Coordinate coordinate);
074:
075: /**
076: * Tells the handler that it just saw a subhandler.
077: *
078: * @param message The sub geometry message (i.e. isInnerBoundary).
079: * @param type The type of sub message (start, end, etc.)
080: */
081: public void subGeometry(String message, int type) {
082: }
083:
084: /**
085: * Determines whether or not the geometry is ready to return.
086: *
087: * @param message The geometry to inspect.
088: *
089: * @return Flag for a complete geometry.
090: */
091: public abstract boolean isComplete(String message);
092:
093: /**
094: * Creates a new JTS geometry.
095: *
096: * @param geometryFactory The JTS geometry factory to use for geometry
097: * creation.
098: *
099: * @return An OGC simple geometry type for return.
100: */
101: public abstract com.vividsolutions.jts.geom.Geometry create(
102: com.vividsolutions.jts.geom.GeometryFactory geometryFactory);
103:
104: /**
105: * Describes the handler.
106: *
107: * @return String representation of the current handler.
108: */
109: public String toString() {
110: String name = this .getClass().getName();
111: int index = name.lastIndexOf('.');
112:
113: return name.substring(index + 1);
114: }
115: }
|