]> granicus.if.org Git - postgis/commitdiff
Code cleanups, Makefile improvements.
authorMarkus Schaber <markus@schabi.de>
Wed, 2 Mar 2005 12:06:28 +0000 (12:06 +0000)
committerMarkus Schaber <markus@schabi.de>
Wed, 2 Mar 2005 12:06:28 +0000 (12:06 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1457 b70326c6-7e19-0410-871a-916f4a2858ee

16 files changed:
CHANGES
jdbc2/Makefile
jdbc2/src/org/postgis/ComposedGeom.java
jdbc2/src/org/postgis/Geometry.java
jdbc2/src/org/postgis/GeometryCollection.java
jdbc2/src/org/postgis/LineString.java
jdbc2/src/org/postgis/LinearRing.java
jdbc2/src/org/postgis/MultiLineString.java
jdbc2/src/org/postgis/MultiPoint.java
jdbc2/src/org/postgis/MultiPolygon.java
jdbc2/src/org/postgis/PGbox2d.java
jdbc2/src/org/postgis/PGbox3d.java
jdbc2/src/org/postgis/PGgeometry.java
jdbc2/src/org/postgis/Point.java
jdbc2/src/org/postgis/PointComposedGeom.java
jdbc2/src/org/postgis/Polygon.java

diff --git a/CHANGES b/CHANGES
index d1cca89c088d39681968413fc0bb55b56e6cb29a..0cee952cfe9aaf1309f48102facbf61744c8b849 100644 (file)
--- 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
index ad2dfaecfac73e4bbb0204e9fdfaf912944cf02a..dc359e0b7141524cf65b47a3b9f3ce226e9f0f68 100644 (file)
@@ -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) . \
index 652a59ad96f809a713a85669c1e781d905e3277c..4f1f63d694585671aeca9a1b30b0c6b1b876d8ab 100644 (file)
@@ -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.
index c196436d250c45e17243a4d9aacb12207cbc46b5..bfbdcd5658f679eca292bd7ebafa26679b4fe338 100644 (file)
@@ -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');
         }
index 07d188715d6fa53c55cec085c2454441cdaf9710..48430614159f8dda971640272827865cac7803cb 100644 (file)
@@ -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) {
index db283337b81ab748bdcc4886f2ffdffc10344f5b..0f5443b3cbdc6f5077376c335eb5d50c77777943 100644 (file)
@@ -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.;
 
index 3a72152de9780321de93de11a8361a1cb8d8b007..f590f7470887a6e6a96b055333cfa62c46019674 100644 (file)
@@ -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);
index c6fe1f85265e653de29bced4a6bba51fe3b9431f..013cb65a7354752a57f902650c5c145475023a0b 100644 (file)
 
 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() {
index 63bff7954dd3ff008a2db847f91a953f2845c347..a6f2aca2c14b8205799c7b149c94949ab397b763 100644 (file)
@@ -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);
index 548b13c799b73955f72db8ebadf039ddc692a273..ace6cbd1db82bd5540573dfa8526fccc44bdfef0 100644 (file)
 
 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
index 22fd32b074fafac3f183025b0360610483899da7..ff51c901927938824c7d6cef48e29098bf04380b 100644 (file)
@@ -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();
index 61642d2e57fda94372f25dc2ad2d925456812cc2..5f13f6550624194c7409117cd875a27622e48f22 100644 (file)
@@ -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();
     }
index ee37aa5318df910005cd69d18040c32c749b6f75..2f5420f7d996ccf93d252a5cfd9d8113b88c7fe8 100644 (file)
@@ -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));
index c3de048a0b88e74b391079c8415ab75857873a70..661c26c040cadc7d5fb821ce56d56a3080b21845 100644 (file)
@@ -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;
     }
index 8166d098f38b6d379f9bea2e29cb7387840246ce..74514e0247c7ed1e50297f2b36254cc672a85b73 100644 (file)
@@ -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) {
index 9269321faad3a1e60cf5e2c53523128df66b37e6..a158570c358d852fc5556f8ed8355a2495416ea9 100644 (file)
 
 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() {