From 1e25c2c090a837ce475ab5a66f99da2ecbecec95 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Wed, 07 May 2008 18:48:45 +0800
Subject: [PATCH] update for EOFM-75

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java |   91 ++++++++++++++++++++++++---------------------
 1 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
index 0e1fc7a..fef0b39 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
@@ -29,7 +29,6 @@
 import com.vividsolutions.jts.geom.GeometryFactory;
 
 import com.ximple.eofms.util.DefaultColorTable;
-import com.ximple.io.dgn7.ArcElement;
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.FrammeAttributeData;
 import com.ximple.io.dgn7.LineElement;
@@ -47,8 +46,8 @@
 
     private String dataOut = null;
 
-    private HashMap featuresContext = new HashMap();
-    private HashMap featuresWriterContext = new HashMap();
+    private HashMap<String, ArrayList<Feature>> featuresContext = new HashMap<String, ArrayList<Feature>>();
+    private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>();
 
     private PessimisticMapWrapper txFeaturesContext;
     private FeatureTypeBuilder typeBuilder = null;
@@ -88,9 +87,9 @@
 
             if (!txFeaturesContext.containsKey(feature.getFeatureType()))
             {
-                txFeaturesContext.put(feature.getFeatureType(), new ArrayList());
+                txFeaturesContext.put(feature.getFeatureType(), new ArrayList<Feature>());
             }
-            ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType());
+            ArrayList<Feature> arrayList = (ArrayList<Feature>) txFeaturesContext.get(feature.getFeatureType());
             arrayList.add(feature);
         } else
         {
@@ -143,20 +142,16 @@
                 FeatureWriter writer;
                 if (featuresWriterContext.containsKey(featureType.getTypeName()))
                 {
-                    writer = (FeatureWriter) featuresWriterContext.get(featureType.getTypeName());
+                    writer = featuresWriterContext.get(featureType.getTypeName());
                 } else
                 {
                     ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL());
                     shapefileDataStore.createSchema(featureType);
                     writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT);
-                    if (this.featuresWriterContext == null)
-                    {
-                        this.featuresWriterContext = new HashMap();
-                    }
                     featuresWriterContext.put(featureType.getTypeName(), writer);
                 }
 
-                ArrayList features = (ArrayList) featuresContext.get(featureType);
+                ArrayList<Feature> features = featuresContext.get(featureType);
                 Iterator itFeature = features.iterator();
                 while (itFeature.hasNext())
                 {
@@ -194,6 +189,16 @@
             dataOut = outPath.toString();
         }
         return dataOut;
+    }
+
+    public void closeFeatureWriter() throws IOException {
+
+        for (FeatureWriter featureWriter : this.featuresWriterContext.values())
+        {
+            featureWriter.close();
+        }
+
+        this.featuresWriterContext.clear();
     }
 
     public FeatureType createPointFeatureElement(String featureName) throws SchemaException
@@ -286,13 +291,15 @@
         {
             LineStringElement linestring = (LineStringElement) element;
             convertDecorator.setConverter(linestring);
-            Feature feature = featureType.create(new Object[]{
-                    convertDecorator.toGeometry(geometryFactory),
-                    colorTable.getColorCode(linestring.getColorIndex()),
-                    linestring.getWeight(),
-                    linestring.getLineStyle()
-            });
-            return feature;
+            Geometry geom = convertDecorator.toGeometry(geometryFactory);
+            if (geom != null)
+                return featureType.create(new Object[]{
+                        geom,
+                        colorTable.getColorCode(linestring.getColorIndex()),
+                        linestring.getWeight(),
+                        linestring.getLineStyle()
+                });
+            return null;
         } else if (element instanceof LineElement)
         {
             LineElement line = (LineElement) element;
@@ -306,21 +313,21 @@
                         line.getLineStyle()
                 });
             return null;
-        /*
-        } else if (element instanceof ArcElement)
-        {
-            ArcElement arcElement = (ArcElement) element;
-            convertDecorator.setConverter(arcElement);
-            Geometry geom = convertDecorator.toGeometry(geometryFactory);
-            if (geom != null)
-                return featureType.create(new Object[]{
-                        geom,
-                        colorTable.getColorCode(arcElement.getColorIndex()),
-                        arcElement.getWeight(),
-                        arcElement.getLineStyle()
-                });
-            return null;
-        */
+            /*
+            } else if (element instanceof ArcElement)
+            {
+                ArcElement arcElement = (ArcElement) element;
+                convertDecorator.setConverter(arcElement);
+                Geometry geom = convertDecorator.toGeometry(geometryFactory);
+                if (geom != null)
+                    return featureType.create(new Object[]{
+                            geom,
+                            colorTable.getColorCode(arcElement.getColorIndex()),
+                            arcElement.getWeight(),
+                            arcElement.getLineStyle()
+                    });
+                return null;
+            */
         }
         return null;
     }
@@ -375,16 +382,16 @@
                 featureTypes.put(typeName, createLineFeatureElement(typeName));
             }
             return featureTypes.get(typeName);
-        /*
-        } else if (element instanceof ArcElement)
-        {
-            typeName = getFeatureBaseName() + "A";
-            if (!featureTypes.containsKey(typeName))
+            /*
+            } else if (element instanceof ArcElement)
             {
-                featureTypes.put(typeName, createArcFeatureElement(typeName));
-            }
-            return featureTypes.get(typeName);
-        */
+                typeName = getFeatureBaseName() + "A";
+                if (!featureTypes.containsKey(typeName))
+                {
+                    featureTypes.put(typeName, createArcFeatureElement(typeName));
+                }
+                return featureTypes.get(typeName);
+            */
         }
 
         return null;

--
Gitblit v0.0.0-SNAPSHOT