From: Markus Schaber Date: Wed, 2 Mar 2005 12:06:28 +0000 (+0000) Subject: Code cleanups, Makefile improvements. X-Git-Tag: pgis_1_0_0RC4~93 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9656d2d168cd668610d1eb811edb4eab5629206e;p=postgis Code cleanups, Makefile improvements. git-svn-id: http://svn.osgeo.org/postgis/trunk@1457 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/CHANGES b/CHANGES index d1cca89c0..0cee952cf 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ PostGIS 1.0.0 - early return from force_collection - segfault fix in geom_accum() - consistency check fix in SnapToGrid() + - jdbc2: code cleanups, Makefile improvements PostGIS 1.0.0RC3 2005/02/24 diff --git a/jdbc2/Makefile b/jdbc2/Makefile index ad2dfaecf..dc359e0b7 100644 --- a/jdbc2/Makefile +++ b/jdbc2/Makefile @@ -52,17 +52,39 @@ top_builddir:=$(PGSQL_SRC) top_makefile:=$(PGSQL_SRC)/src/Makefile.global -include $(top_makefile) -# Make sure you CLASSPATH environmental variable includes your postgresql.jar -# We set a reasonable default for un*xoid systems here. Note that some JREs -# (e. G. sablevm on debian woody) seem to need their own system classes -# to be included in the classpath, because they do not adhere to the standard -# concept of -classpath and -bootclasspath. SUN jdk, IBM jdk, Blackdown JDK, -# gij and kaffe are known to work fine. +# Make sure our classpath includes your postgresql.jar. This is somehow +# difficult because some JREs (e. G. those on debian woody or sablevm) seem +# to forget their own system classes (aka bootclasspath) as soon as _any_ +# classpath is set, either via environment or via command line. They do not +# implement the concept of distinct classpath and bootclasspath settings, +# as most current java implementations do. This makes it necessary to either +# explicitly include the system classes in the set classpath, or use +# non-standard options line --addclasspath to add both the postgresql.jar +# and our own classes. We also cannot set an unset CLASSPATH variable here +# for this reason. Current (Jan 2005) implementations from SUN, IBM, +# Blackdown, gij and kaffe are known to work fine. + +# If you set POSTGIS_BUILD_CLASSPATH via Environment (even to an empty string), we +# simply use it and do not try to guess anything. If POSTGIS_CLASSPATH is +# not set, we use the contents of CLASSPATH. If CLASSPATH is empty or not +# set, we try to guess a default location that works on most unixoid systems. + +ifeq (${CLASSPATH},) + TEMP=/usr/share/java/postgresql.jar +else + TEMP=${CLASSPATH} +endif + +POSTGIS_BUILD_CLASSPATH?=$(TEMP) -CLASSPATH?=/usr/share/java/postgresql.jar +# Set those to --addclasspath for sablevm, to avoid overriding the +# BOOTCLASSPATH, the first one is for the compiler, the second one for JRE. +COMP_ADDCP?=-classpath +EXEC_ADDCP?=-classpath # This are used for the online regression tests, override via environment -# as applicable. +# as applicable. The jtest needs table creation privilege in current_schema(), +# the others only call self contained SELECTs that do not access any tables. PGHOST?=localhost PGPORT?=5432 PGDATABASE?=jdbc_test @@ -75,8 +97,8 @@ PGPASS?=guess SRCDIR=src EXAMPLES=examples BUILD=bin -RUNCP=$(CLASSPATH):postgis.jar -BUILDCP=$(STUBBUILD):$(SRCDIR):$(CLASSPATH) +RUNCP=$(POSTGIS_BUILD_CLASSPATH):postgis.jar +BUILDCP=$(STUBBUILD):$(POSTGIS_BUILD_CLASSPATH) # All the java files to compile SRC= $(SRCDIR)/examples/Test.java \ @@ -160,29 +182,29 @@ stubcompile: $(STUBBUILD) touch stubcompile compile: stubcompile $(BUILD) $(SRC) - $(JAVAC) -classpath "$(BUILDCP)" -d $(BUILD) $(SRC) + $(JAVAC) $(COMP_ADDCP) "$(BUILDCP)" -d $(BUILD) $(SRC) touch compile test: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/Test + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/Test jtest: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestServer jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestServer jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) ptestoffline: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestParser offline + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser offline ptest: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestParser jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestParser jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) boxtestoffline: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestBoxes offline + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes offline boxtest: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestBoxes jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestBoxes jdbc:postgresql_postGIS://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) autoregistertest: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/TestAutoregister jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/TestAutoregister jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) offlinetests: boxtestoffline ptestoffline test @@ -190,7 +212,7 @@ onlinetests: boxtest ptest jtest autoregistertest # Print all available versions versions: postgis.jar - $(JAVA) -classpath "$(RUNCP)" $(EXAMPLES)/VersionPrinter jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) $(EXEC_ADDCP) "$(RUNCP)" $(EXAMPLES)/VersionPrinter jdbc:postgresql://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) # boxtest and ptest include boxtestoffline and ptestoffline, so we only need # to run test in addition to the onlinetests @@ -223,14 +245,14 @@ $(JTSBUILD): jtscompile: compile stubcompile $(JTSBUILD) $(JTSSRC) - $(JAVAC) -classpath "$(BUILD):$(CP)" -d $(JTSBUILD) $(JTSSRC) + $(JAVAC) $(COMP_ADDCP) "$(BUILD):$(CP)" -d $(JTSBUILD) $(JTSSRC) touch jtscompile jtstestoffline: jtscompile - $(JAVA) -classpath "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser offline + $(JAVA) $(EXEC_ADDCP) "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser offline jtstest: jtscompile - $(JAVA) -classpath "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser jdbc:postgres_jts://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) + $(JAVA) -$(EXEC_ADDCP) "$(JTSBUILD):$(BUILD):$(CP)" $(EXAMPLES)/JtsTestParser jdbc:postgres_jts://$(PGHOST):$(PGPORT)/$(PGDATABASE) $(PGUSER) $(PGPASS) postgis_jts.jar: jtscompile $(SRCDIR)/org/postgresql/driverconfig.properties $(JAR) -cf postgis_jts.jar -C $(BUILD) . \ diff --git a/jdbc2/src/org/postgis/ComposedGeom.java b/jdbc2/src/org/postgis/ComposedGeom.java index 652a59ad9..4f1f63d69 100644 --- a/jdbc2/src/org/postgis/ComposedGeom.java +++ b/jdbc2/src/org/postgis/ComposedGeom.java @@ -26,6 +26,9 @@ package org.postgis; +import org.postgresql.util.PGtokenizer; + +import java.sql.SQLException; import java.util.Iterator; /** @@ -70,6 +73,51 @@ public abstract class ComposedGeom extends Geometry { } } + protected ComposedGeom(int type, String value, boolean haveM) throws SQLException { + super(type); + value = value.trim(); + String typestring = getTypeString(); + if (value.indexOf(typestring) == 0) { + int pfxlen = typestring.length(); + if (value.charAt(pfxlen) == 'M') { + pfxlen += 1; + haveM = true; + } + value = value.substring(pfxlen).trim(); + } else if (value.charAt(0) != '(') { + // we are neigher inner nor outer rep. + throw new SQLException("Error parsing a " + typestring + " out of " + value); + } + if (value.equals("(EMPTY)")) { + // Special case for PostGIS 0.X style empty geometry collections + // (which are not OpenGIS compliant) + return; + } + PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); + int subgeomcount = t.getSize(); + subgeoms = createSubGeomArray(subgeomcount); + for (int p = 0; p < subgeomcount; p++) { + subgeoms[p] = createSubGeomInstance(t.getToken(p), haveM); + } + dimension = subgeoms[0].dimension; + // fetch haveMeasure from subpoint because haveM does only work with + // 2d+M, not with 3d+M geometries + haveMeasure = subgeoms[0].haveMeasure; + } + + /** + * Return the appropriate instance of the subgeometry - this encapsulates + * subclass specific constructor calls + */ + protected abstract Geometry createSubGeomInstance(String token, boolean haveM) + throws SQLException; + + /** + * Return the appropriate instance of the subgeometry array - this + * encapsulates subclass specific array instantiation + */ + protected abstract Geometry[] createSubGeomArray(int size); + protected boolean equalsintern(Geometry other) { // Can be assumed to be the same subclass of Geometry, so it must be a // ComposedGeom, too. diff --git a/jdbc2/src/org/postgis/Geometry.java b/jdbc2/src/org/postgis/Geometry.java index c196436d2..bfbdcd565 100644 --- a/jdbc2/src/org/postgis/Geometry.java +++ b/jdbc2/src/org/postgis/Geometry.java @@ -108,11 +108,6 @@ public abstract class Geometry implements Serializable { */ public final int type; - /** - * The string rep of the current type - */ - public final String typestring; - /** * The spacial reference system id of this geometry, default (no srid) is -1 */ @@ -125,7 +120,6 @@ public abstract class Geometry implements Serializable { */ protected Geometry(int type) { this.type = type; - this.typestring = getTypeString(type); } /** @@ -242,7 +236,7 @@ public abstract class Geometry implements Serializable { * StringBuffer. */ public void outerWKT(StringBuffer sb, boolean putM) { - sb.append(typestring); + sb.append(getTypeString()); if (putM && haveMeasure && dimension == 2) { sb.append('M'); } diff --git a/jdbc2/src/org/postgis/GeometryCollection.java b/jdbc2/src/org/postgis/GeometryCollection.java index 07d188715..484306141 100644 --- a/jdbc2/src/org/postgis/GeometryCollection.java +++ b/jdbc2/src/org/postgis/GeometryCollection.java @@ -26,8 +26,6 @@ package org.postgis; -import org.postgresql.util.PGtokenizer; - import java.sql.SQLException; /** @@ -40,8 +38,10 @@ import java.sql.SQLException; */ public class GeometryCollection extends ComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; + public static final String GeoCollID = "GEOMETRYCOLLECTION"; - public static final String EmptyColl = GeoCollID + "(EMPTY)"; public GeometryCollection() { super(GEOMETRYCOLLECTION); @@ -56,29 +56,15 @@ public class GeometryCollection extends ComposedGeom { } public GeometryCollection(String value, boolean haveM) throws SQLException { - this(); - value = value.trim(); - if (value.equals(EmptyColl)) { - //Do nothing - } else if (value.startsWith(GeoCollID)) { - int pfxlen = typestring.length(); - if (value.charAt(pfxlen) == 'M') { - pfxlen += 1; - haveM = true; - } - value = value.substring(pfxlen).trim(); + super(GEOMETRYCOLLECTION, value, haveM); + } - PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); - int ngeoms = t.getSize(); - subgeoms = new Geometry[ngeoms]; - for (int p = 0; p < ngeoms; p++) { - subgeoms[p] = PGgeometry.geomFromString(t.getToken(p), haveM); - } - dimension = subgeoms[0].dimension; - haveMeasure = subgeoms[0].haveMeasure; - } else { - throw new SQLException("postgis.geocollection"); - } + protected Geometry[] createSubGeomArray(int ngeoms) { + return new Geometry[ngeoms]; + } + + protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException { + return PGgeometry.geomFromString(token, haveM); } protected void innerWKT(StringBuffer SB) { diff --git a/jdbc2/src/org/postgis/LineString.java b/jdbc2/src/org/postgis/LineString.java index db283337b..0f5443b3c 100644 --- a/jdbc2/src/org/postgis/LineString.java +++ b/jdbc2/src/org/postgis/LineString.java @@ -29,6 +29,8 @@ package org.postgis; import java.sql.SQLException; public class LineString extends PointComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; double len = -1.; diff --git a/jdbc2/src/org/postgis/LinearRing.java b/jdbc2/src/org/postgis/LinearRing.java index 3a72152de..f590f7470 100644 --- a/jdbc2/src/org/postgis/LinearRing.java +++ b/jdbc2/src/org/postgis/LinearRing.java @@ -35,6 +35,8 @@ import java.sql.SQLException; * the polygon types, but is not stored or retrieved directly from the database. */ public class LinearRing extends PointComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public LinearRing(Point[] points) { super(LINEARRING, points); diff --git a/jdbc2/src/org/postgis/MultiLineString.java b/jdbc2/src/org/postgis/MultiLineString.java index c6fe1f852..013cb65a7 100644 --- a/jdbc2/src/org/postgis/MultiLineString.java +++ b/jdbc2/src/org/postgis/MultiLineString.java @@ -26,11 +26,11 @@ package org.postgis; -import org.postgresql.util.PGtokenizer; - import java.sql.SQLException; public class MultiLineString extends ComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; double len = -1; @@ -49,28 +49,17 @@ public class MultiLineString extends ComposedGeom { public MultiLineString(String value) throws SQLException { this(value, false); } - - protected MultiLineString(String value, boolean haveM) throws SQLException { - this(); - value = value.trim(); - if (value.indexOf(typestring) == 0) { - int pfxlen = typestring.length(); - if (value.charAt(pfxlen) == 'M') { - pfxlen += 1; - haveM = true; - } - value = value.substring(pfxlen).trim(); - PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); - int nlines = t.getSize(); - subgeoms = new LineString[nlines]; - for (int p = 0; p < nlines; p++) { - subgeoms[p] = new LineString(t.getToken(p), haveM); - } - dimension = subgeoms[0].dimension; - haveMeasure = subgeoms[0].haveMeasure; - } else { - throw new SQLException("postgis.multilinestringgeometry"); - } + + public MultiLineString(String value, boolean haveM) throws SQLException { + super(MULTILINESTRING, value, haveM); + } + + protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException { + return new LineString(token, haveM); + } + + protected Geometry[] createSubGeomArray(int nlines) { + return new LineString[nlines]; } public int numLines() { diff --git a/jdbc2/src/org/postgis/MultiPoint.java b/jdbc2/src/org/postgis/MultiPoint.java index 63bff7954..a6f2aca2c 100644 --- a/jdbc2/src/org/postgis/MultiPoint.java +++ b/jdbc2/src/org/postgis/MultiPoint.java @@ -29,6 +29,8 @@ package org.postgis; import java.sql.SQLException; public class MultiPoint extends PointComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public MultiPoint() { super(MULTIPOINT); diff --git a/jdbc2/src/org/postgis/MultiPolygon.java b/jdbc2/src/org/postgis/MultiPolygon.java index 548b13c79..ace6cbd1d 100644 --- a/jdbc2/src/org/postgis/MultiPolygon.java +++ b/jdbc2/src/org/postgis/MultiPolygon.java @@ -26,11 +26,11 @@ package org.postgis; -import org.postgresql.util.PGtokenizer; - import java.sql.SQLException; public class MultiPolygon extends ComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public MultiPolygon() { super(MULTIPOLYGON); @@ -45,28 +45,15 @@ public class MultiPolygon extends ComposedGeom { } protected MultiPolygon(String value, boolean haveM) throws SQLException { - this(); - value = value.trim(); - if (value.indexOf("MULTIPOLYGON") == 0) { - int pfxlen = typestring.length(); - if (value.charAt(pfxlen) == 'M') { - pfxlen += 1; - haveM = true; - } - value = value.substring(pfxlen).trim(); - PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); - int npolygons = t.getSize(); - subgeoms = new Polygon[npolygons]; - for (int p = 0; p < npolygons; p++) { - subgeoms[p] = new Polygon(t.getToken(p), haveM); - } - dimension = subgeoms[0].dimension; - // fetch haveMeasure from subpoint because haveM does only work with - // 2d+M, not with 3d+M geometries - this.haveMeasure = subgeoms[0].haveMeasure; - } else { - throw new SQLException("postgis.multipolygongeometry"); - } + super(MULTIPOLYGON, value, haveM); + } + + protected Geometry[] createSubGeomArray(int npolygons) { + return new Polygon[npolygons]; + } + + protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException { + return new Polygon(token, haveM); } public int numPolygons() { @@ -80,5 +67,4 @@ public class MultiPolygon extends ComposedGeom { return null; } } - } \ No newline at end of file diff --git a/jdbc2/src/org/postgis/PGbox2d.java b/jdbc2/src/org/postgis/PGbox2d.java index 22fd32b07..ff51c9019 100644 --- a/jdbc2/src/org/postgis/PGbox2d.java +++ b/jdbc2/src/org/postgis/PGbox2d.java @@ -29,6 +29,8 @@ package org.postgis; import java.sql.SQLException; public class PGbox2d extends PGboxbase { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public PGbox2d() { super(); diff --git a/jdbc2/src/org/postgis/PGbox3d.java b/jdbc2/src/org/postgis/PGbox3d.java index 61642d2e5..5f13f6550 100644 --- a/jdbc2/src/org/postgis/PGbox3d.java +++ b/jdbc2/src/org/postgis/PGbox3d.java @@ -30,6 +30,9 @@ package org.postgis; import java.sql.SQLException; public class PGbox3d extends PGboxbase { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; + public PGbox3d() { super(); } diff --git a/jdbc2/src/org/postgis/PGgeometry.java b/jdbc2/src/org/postgis/PGgeometry.java index ee37aa531..2f5420f7d 100644 --- a/jdbc2/src/org/postgis/PGgeometry.java +++ b/jdbc2/src/org/postgis/PGgeometry.java @@ -32,6 +32,8 @@ import org.postgresql.util.PGobject; import java.sql.SQLException; public class PGgeometry extends PGobject { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; Geometry geom; BinaryParser bp = new BinaryParser(); @@ -78,7 +80,7 @@ public class PGgeometry extends PGobject { int srid = -1; if (value.startsWith(SRIDPREFIX)) { - //break up geometry into srid and wkt + // break up geometry into srid and wkt String[] parts = PGgeometry.splitSRID(value); value = parts[1].trim(); srid = Integer.parseInt(parts[0].substring(5)); diff --git a/jdbc2/src/org/postgis/Point.java b/jdbc2/src/org/postgis/Point.java index c3de048a0..661c26c04 100644 --- a/jdbc2/src/org/postgis/Point.java +++ b/jdbc2/src/org/postgis/Point.java @@ -31,6 +31,8 @@ import org.postgresql.util.PGtokenizer; import java.sql.SQLException; public class Point extends Geometry { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public static final boolean CUTINTS = true; @@ -163,7 +165,7 @@ public class Point extends Geometry { m = Double.valueOf(t.getToken(dimension)).doubleValue(); } } catch (NumberFormatException e) { - throw new SQLException("postgis.Point" + e.toString()); + throw new SQLException("Error parsing Point: " + e.toString()); } haveMeasure = haveM; } diff --git a/jdbc2/src/org/postgis/PointComposedGeom.java b/jdbc2/src/org/postgis/PointComposedGeom.java index 8166d098f..74514e024 100644 --- a/jdbc2/src/org/postgis/PointComposedGeom.java +++ b/jdbc2/src/org/postgis/PointComposedGeom.java @@ -25,8 +25,6 @@ */ package org.postgis; -import org.postgresql.util.PGtokenizer; - import java.sql.SQLException; /** @@ -50,30 +48,17 @@ public abstract class PointComposedGeom extends ComposedGeom { public PointComposedGeom(int type, String value) throws SQLException { this(type, value, false); } + public PointComposedGeom(int type, String value, boolean haveM) throws SQLException { - this(type); - value = value.trim(); - if (value.indexOf(typestring) == 0) { - int pfxlen = typestring.length(); - if (value.charAt(pfxlen)=='M') { - pfxlen += 1; - haveM=true; - } - value = value.substring(pfxlen).trim(); - } - if (value.charAt(0) == '(') { - PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); - int npoints = t.getSize(); - subgeoms = new Point[npoints]; - for (int p = 0; p < npoints; p++) { - subgeoms[p] = new Point(t.getToken(p), haveM); - } - dimension = subgeoms[0].dimension; - haveM |= subgeoms[0].haveMeasure; - } else { - throw new SQLException("postgis.multipointgeometry"); - } - this.haveMeasure = haveM; + super(type, value, haveM); + } + + protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException { + return new Point(token, haveM); + } + + protected Geometry[] createSubGeomArray(int pointcount) { + return new Point[pointcount]; } protected void innerWKT(StringBuffer sb) { diff --git a/jdbc2/src/org/postgis/Polygon.java b/jdbc2/src/org/postgis/Polygon.java index 9269321fa..a158570c3 100644 --- a/jdbc2/src/org/postgis/Polygon.java +++ b/jdbc2/src/org/postgis/Polygon.java @@ -26,11 +26,11 @@ package org.postgis; -import org.postgresql.util.PGtokenizer; - import java.sql.SQLException; public class Polygon extends ComposedGeom { + /* JDK 1.5 Serialization */ + private static final long serialVersionUID = 0x100; public Polygon() { super(POLYGON); @@ -43,28 +43,17 @@ public class Polygon extends ComposedGeom { public Polygon(String value) throws SQLException { this(value, false); } - - public Polygon(String value, boolean haveM) throws SQLException{ - this(); - value = value.trim(); - if (value.indexOf(typestring) == 0) { - int pfxlen = typestring.length(); - if (value.charAt(pfxlen) == 'M') { - pfxlen += 1; - haveM = true; - } - value = value.substring(pfxlen).trim(); - } - PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ','); - int nrings = t.getSize(); - subgeoms = new LinearRing[nrings]; - for (int r = 0; r < nrings; r++) { - subgeoms[r] = new LinearRing(t.getToken(r), haveM); - } - dimension = subgeoms[0].dimension; - // fetch haveMeasure from subpoint because haveM does only work with - // 2d+M, not with 3d+M geometries - this.haveMeasure = subgeoms[0].haveMeasure; + + public Polygon(String value, boolean haveM) throws SQLException { + super(POLYGON, value, haveM); + } + + protected Geometry createSubGeomInstance(String token, boolean haveM) throws SQLException { + return new LinearRing(token, haveM); + } + + protected Geometry[] createSubGeomArray(int ringcount) { + return new LinearRing[ringcount]; } public int numRings() {