From 2dc52b4a4b6f2ca3defdeb3e10b8f34f1f38dea9 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Tue, 06 May 2008 18:45:25 +0800
Subject: [PATCH] update for EOFM-75

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java   |   69 +++---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java       |   15 
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java     |  154 ++++++---------
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java |  282 ++++++++++++++++++++++++++++
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java  |   20 -
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java        |   17 -
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java    |   27 +-
 7 files changed, 410 insertions(+), 174 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
index ebe84cd..769c62d 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
@@ -25,7 +25,7 @@
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
-    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
 
     public CreateLineStringStrategy()
     {
@@ -58,8 +58,7 @@
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("COLOR", String.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
         }
@@ -74,16 +73,15 @@
         if (element instanceof LineStringElement)
         {
             LineStringElement lineStringElement = (LineStringElement) element;
-            convertDecordator.setConverter(lineStringElement);
+            convertDecorator.setConverter(lineStringElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     lineStringElement.getLevelIndex(),
                     colorTable.getColorCode(lineStringElement.getColorIndex()),
-                    colorTable.getColor(lineStringElement.getColorIndex()).getRGB(),
                     lineStringElement.getWeight(),
                     lineStringElement.getLineStyle()
             });
@@ -91,16 +89,15 @@
         } else if (element instanceof ComplexChainElement)
         {
             ComplexChainElement complexChain = (ComplexChainElement) element;
-            convertDecordator.setConverter(complexChain);
+            convertDecorator.setConverter(complexChain);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     complexChain.getLevelIndex(),
                     colorTable.getColorCode(complexChain.getColorIndex()),
-                    colorTable.getColor(complexChain.getColorIndex()).getRGB(),
                     complexChain.getWeight(),
                     complexChain.getLineStyle()
             });
@@ -108,16 +105,15 @@
         } else if (element instanceof LineElement)
         {
             LineElement lineElement = (LineElement) element;
-            convertDecordator.setConverter(lineElement);
+            convertDecorator.setConverter(lineElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     lineElement.getLevelIndex(),
                     colorTable.getColorCode(lineElement.getColorIndex()),
-                    colorTable.getColor(lineElement.getColorIndex()).getRGB(),
                     lineElement.getWeight(),
                     lineElement.getLineStyle()
             });
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java
index 97e69e7..4c7dce0 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.java
@@ -17,19 +17,19 @@
 import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
 import com.ximple.eofms.util.DefaultColorTable;
 import com.ximple.eofms.util.TWDDatumConverter;
+import com.ximple.io.dgn7.ComplexChainElement;
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.FrammeAttributeData;
 import com.ximple.io.dgn7.LineElement;
 import com.ximple.io.dgn7.LineStringElement;
 import com.ximple.io.dgn7.TextElement;
 import com.ximple.io.dgn7.UserAttributeData;
-import com.ximple.io.dgn7.ComplexChainElement;
 
 public class CreateLineTextStrategy  implements CreateFeatureTypeStrategy
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
-    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
 
     public CreateLineTextStrategy()
     {
@@ -62,8 +62,7 @@
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("COLOR", String.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
         }
@@ -78,16 +77,15 @@
         if (element instanceof LineStringElement)
         {
             LineStringElement lineStringElement = (LineStringElement) element;
-            convertDecordator.setConverter(lineStringElement);
+            convertDecorator.setConverter(lineStringElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     lineStringElement.getLevelIndex(),
                     colorTable.getColorCode(lineStringElement.getColorIndex()),
-                    colorTable.getColor(lineStringElement.getColorIndex()).getRGB(),
                     lineStringElement.getWeight(),
                     lineStringElement.getLineStyle()
             });
@@ -104,8 +102,8 @@
             vect[1] = TWDDatumConverter.fromTM2ToTWD97(ptEnd);
 
             LineString line = geometryFactory.createLineString(vect);
-            // convertDecordator.setConverter(txtElement);
-            // Geometry geom = convertDecordator.toGeometry(geometryFactory);
+            // convertDecorator.setConverter(txtElement);
+            // Geometry geom = convertDecorator.toGeometry(geometryFactory);
 
             txtElement.getRotationAngle();
 
@@ -117,7 +115,6 @@
                     0,
                     txtElement.getLevelIndex(),
                     colorTable.getColorCode(txtElement.getColorIndex()),
-                    colorTable.getColor(txtElement.getColorIndex()).getRGB(),
                     txtElement.getWeight(),
                     txtElement.getLineStyle()
             });
@@ -125,16 +122,15 @@
         } else if (element instanceof ComplexChainElement)
         {
             ComplexChainElement complexChain = (ComplexChainElement) element;
-            convertDecordator.setConverter(complexChain);
+            convertDecorator.setConverter(complexChain);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     complexChain.getLevelIndex(),
                     colorTable.getColorCode(complexChain.getColorIndex()),
-                    colorTable.getColor(complexChain.getColorIndex()).getRGB(),
                     complexChain.getWeight(),
                     complexChain.getLineStyle()
             });
@@ -142,16 +138,15 @@
         } else if (element instanceof LineElement)
         {
             LineElement lineElement = (LineElement) element;
-            convertDecordator.setConverter(lineElement);
+            convertDecorator.setConverter(lineElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     lineElement.getLevelIndex(),
                     colorTable.getColorCode(lineElement.getColorIndex()),
-                    colorTable.getColor(lineElement.getColorIndex()).getRGB(),
                     lineElement.getWeight(),
                     lineElement.getLineStyle()
             });
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
index 3657701..a6da3c7 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
@@ -24,7 +24,7 @@
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
-    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
 
     public CreateShapeStrategy()
     {
@@ -57,8 +57,7 @@
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("COLOR", String.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
         }
@@ -73,16 +72,15 @@
         if (element instanceof ShapeElement)
         {
             ShapeElement shapeElement = (ShapeElement) element;
-            convertDecordator.setConverter(shapeElement);
+            convertDecorator.setConverter(shapeElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     shapeElement.getLevelIndex(),
                     colorTable.getColorCode(shapeElement.getColorIndex()),
-                    colorTable.getColor(shapeElement.getColorIndex()).getRGB(),
                     shapeElement.getWeight(),
                     shapeElement.getLineStyle()
             });
@@ -90,16 +88,15 @@
         } else if (element instanceof ComplexShapeElement)
         {
             ComplexShapeElement complexShape = (ComplexShapeElement) element;
-            convertDecordator.setConverter(complexShape);
+            convertDecorator.setConverter(complexShape);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     complexShape.getLevelIndex(),
                     colorTable.getColorCode(complexShape.getColorIndex()),
-                    colorTable.getColor(complexShape.getColorIndex()).getRGB(),
                     complexShape.getWeight(),
                     complexShape.getLineStyle()
             });
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
index d25cf59..ec303b1 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
@@ -24,7 +24,7 @@
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
-    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
 
     public CreateTextStrategy()
     {
@@ -57,11 +57,10 @@
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("COLOR", String.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
-            typeBuilder.addType(AttributeTypeFactory.newAttributeType("FONT", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("FONT", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("JUST", Integer.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("HEIGHT", Double.class));
             typeBuilder.addType(AttributeTypeFactory.newAttributeType("WIDTH", Double.class));
@@ -82,16 +81,15 @@
             double angle = txtElement.getRotationAngle();
             angle += 180.0;
             angle = ((angle > 360.0)? (angle - 360.0) : (angle));
-            convertDecordator.setConverter(txtElement);
+            convertDecorator.setConverter(txtElement);
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     txtElement.getLevelIndex(),
                     colorTable.getColorCode(txtElement.getColorIndex()),
-                    colorTable.getColor(txtElement.getColorIndex()).getRGB(),
                     txtElement.getWeight(),
                     txtElement.getLineStyle(),
                     txtElement.getFontIndex(),
@@ -105,7 +103,7 @@
         } else if (element instanceof TextNodeElement)
         {
             TextNodeElement nodeElement = (TextNodeElement) element;
-            convertDecordator.setConverter(nodeElement);
+            convertDecorator.setConverter(nodeElement);
             String[] texts = nodeElement.getTextArray();
             StringBuffer sb = new StringBuffer();
             for (String text : texts)
@@ -119,14 +117,13 @@
             angle += 180.0;
             angle = ((angle > 360.0)? (angle - 360.0) : (angle));
             Feature feature = featureType.create(new Object[]{
-                    convertDecordator.toGeometry(geometryFactory),
+                    convertDecorator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
                     0,
                     nodeElement.getLevelIndex(),
                     colorTable.getColorCode(nodeElement.getColorIndex()),
-                    colorTable.getColor(nodeElement.getColorIndex()).getRGB(),
                     nodeElement.getWeight(),
                     nodeElement.getLineStyle(),
                     nodeElement.getFontIndex(),
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 a2bf495..715b4f2 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
@@ -1,15 +1,90 @@
 package com.ximple.eofms.jobs;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.transaction.memory.PessimisticMapWrapper;
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
+import org.apache.commons.transaction.util.LoggerFacade;
+import org.geotools.data.FeatureWriter;
+import org.geotools.data.Transaction;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.feature.AttributeTypeFactory;
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureType;
+import org.geotools.feature.FeatureTypeBuilder;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
+import org.geotools.feature.SimpleFeature;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.eofms.util.DefaultColorTable;
+import com.ximple.io.dgn7.Element;
+import com.ximple.io.dgn7.FrammeAttributeData;
+import com.ximple.io.dgn7.LineElement;
+import com.ximple.io.dgn7.LineStringElement;
+import com.ximple.io.dgn7.TextElement;
+import com.ximple.io.dgn7.UserAttributeData;
 
 public class GeneralDgnConvertJobContext extends AbstractDgnFileJobContext
 {
-    private final static String SHPOUTPATH = "shpout";
+    static final Log logger = LogFactory.getLog(IndexDgnConvertJobContext.class);
+    static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
+    static final GeometryFactory geometryFactory = new GeometryFactory();
+    static final String SHPOUTPATH = "shpout";
+
     private String dataOut = null;
+
+    private HashMap featuresContext = new HashMap();
+    private HashMap featuresWriterContext = new HashMap();
+
+    private PessimisticMapWrapper txFeaturesContext;
+    private FeatureTypeBuilder typeBuilder = null;
+    private TreeMap<String, FeatureType> featureTypes = new TreeMap<String, FeatureType>();
+
+    private TWD97GeometryConverterDecorator convertDecorator = null;
+    private String featureBaseName = null;
 
     public GeneralDgnConvertJobContext(String dataPath)
     {
         super(dataPath);
+        txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger);
+        convertDecorator = new TWD97GeometryConverterDecorator();
+    }
+
+    public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException
+    {
+        FeatureType ft = lookupFeatureType(element);
+        if (ft == null)
+        {
+            Feature feature = createFeature(ft, element);
+            if (feature == null)
+            {
+                logger.info("cannot craete feature." + element.toString() + "'" +
+                        ((TextElement) element).getText() + "'");
+                return;
+            }
+
+            if (!txFeaturesContext.containsKey(feature.getFeatureType()))
+            {
+                txFeaturesContext.put(feature.getFeatureType(), new ArrayList());
+            }
+            ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType());
+            arrayList.add(feature);
+        } else
+        {
+            logger.info("Unknown Element :" + element.getType() + ", lv=" + element.getLevelIndex());
+        }
     }
 
     public void startTransaction()
@@ -18,10 +93,79 @@
 
     public void commitTransaction()
     {
+        if (!txFeaturesContext.isEmpty())
+        {
+            logger.debug("Transaction size = " + txFeaturesContext.size());
+            //txFeaturesContext.commitTransaction();
+        } else
+        {
+            logger.debug("Transaction is empty.");
+        }
+
+        if (!featuresContext.isEmpty())
+        {
+            updateDataStore();
+        }
     }
 
     public void rollbackTransaction()
     {
+        //txFeaturesContext.rollbackTransaction();
+        if (!featuresContext.isEmpty())
+        {
+            updateDataStore();
+        }
+    }
+
+    private void updateDataStore()
+    {
+        Iterator it = featuresContext.keySet().iterator();
+
+        try
+        {
+            while (it.hasNext())
+            {
+                FeatureType featureType = (FeatureType) it.next();
+                File sfile = new File(getDataOutPath() + "\\" + featureType.getTypeName());
+                logger.debug("Begin Save shapefile:" + sfile.toURI());
+
+                FeatureWriter writer;
+                if (featuresWriterContext.containsKey(featureType.getTypeName()))
+                {
+                    writer = (FeatureWriter) 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);
+                Iterator itFeature = features.iterator();
+                while (itFeature.hasNext())
+                {
+                    Feature feature = (Feature) itFeature.next();
+                    ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null));
+                }
+                //writer.close();
+                logger.debug("End Save shapefile:" + sfile.toURI());
+            }
+            featuresContext.clear();
+        } catch (MalformedURLException e)
+        {
+            logger.error(e.getMessage(), e);
+        } catch (IllegalAttributeException e)
+        {
+            logger.error(e.getMessage(), e);
+        } catch (IOException e)
+        {
+            logger.error(e.getMessage(), e);
+        }
     }
 
     public String getDataOutPath()
@@ -40,4 +184,140 @@
         }
         return dataOut;
     }
+
+    public FeatureType createPointFeatureElement(String featureName) throws SchemaException
+    {
+        if (typeBuilder == null)
+        {
+            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("FONT", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("JUST", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("HEIGHT", Double.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("WIDTH", Double.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("ANGLE", Double.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("CONTEXT", String.class));
+        }
+        return typeBuilder.getFeatureType();
+    }
+
+    public FeatureType createLineFeatureElement(String featureName) throws SchemaException
+    {
+        if (typeBuilder == null)
+        {
+            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
+        }
+        return typeBuilder.getFeatureType();
+    }
+
+    public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
+    {
+        DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
+        if (element instanceof TextElement)
+        {
+            TextElement textElement = (TextElement) element;
+            convertDecorator.setConverter(textElement);
+            Feature feature = featureType.create(new Object[]{
+                    convertDecorator.toGeometry(geometryFactory),
+                    colorTable.getColorCode(textElement.getColorIndex()),
+                    textElement.getFontIndex(),
+                    textElement.getJustification(),
+                    textElement.getTextHeight(),
+                    textElement.getTextWidth(),
+                    textElement.getRotationAngle(),
+                    textElement.getText()
+            });
+            return feature;
+        } else if (element instanceof LineStringElement)
+        {
+            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;
+        } else if (element instanceof LineElement)
+        {
+            LineElement line = (LineElement) element;
+            convertDecorator.setConverter(line);
+            Feature feature = featureType.create(new Object[]{
+                    convertDecorator.toGeometry(geometryFactory),
+                    colorTable.getColorCode(line.getColorIndex()),
+                    line.getWeight(),
+                    line.getLineStyle()
+            });
+            return feature;
+        }
+        return null;
+    }
+
+    private String getFeatureBaseName()
+    {
+        if (featureBaseName == null)
+        {
+            String dgnname = getFilename().toLowerCase();
+            int i = dgnname.lastIndexOf(".");
+            if (i != -1)
+            {
+                dgnname = dgnname.substring(0, i);
+            }
+            featureBaseName = dgnname;
+        }
+        return featureBaseName;
+    }
+    private FeatureType lookupFeatureType(Element element) throws SchemaException, IllegalAttributeException
+    {
+        String typeName;
+        if (element instanceof TextElement)
+        {
+            typeName = getFeatureBaseName() + "P";
+            if (!featureTypes.containsKey(typeName))
+            {
+                featureTypes.put(typeName, createPointFeatureElement(typeName));
+            }
+            return featureTypes.get(typeName);
+        } else if (element instanceof LineStringElement)
+        {
+            typeName = getFeatureBaseName() + "L";
+            if (!featureTypes.containsKey(typeName))
+            {
+                featureTypes.put(typeName, createLineFeatureElement(typeName));
+            }
+            return featureTypes.get(typeName);
+        } else if (element instanceof LineElement)
+        {
+            typeName = getFeatureBaseName() + "L";
+            if (!featureTypes.containsKey(typeName))
+            {
+                featureTypes.put(typeName, createLineFeatureElement(typeName));
+            }
+            return featureTypes.get(typeName);
+        }
+
+        return null;
+    }
+
+    protected FrammeAttributeData getFeatureLinkage(Element element)
+    {
+        if (!element.hasUserAttributeData())
+            return null;
+
+        List<UserAttributeData> usrDatas = element.getUserAttributeData();
+        for (UserAttributeData anUsrData : usrDatas)
+        {
+            if (anUsrData instanceof FrammeAttributeData)
+            {
+                return (FrammeAttributeData) anUsrData;
+            }
+        }
+        return null;
+    }
 }
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java
index bdb7c76..27b1a9d 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java
@@ -2,49 +2,47 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Iterator;
 import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 
-import org.geotools.feature.Feature;
-import org.geotools.feature.FeatureType;
-import org.geotools.feature.SchemaException;
-import org.geotools.feature.FeatureTypeBuilder;
-import org.geotools.feature.AttributeTypeFactory;
-import org.geotools.feature.FeatureTypeFactory;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.SimpleFeature;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.transaction.memory.PessimisticMapWrapper;
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
+import org.apache.commons.transaction.util.LoggerFacade;
 import org.geotools.data.FeatureWriter;
 import org.geotools.data.Transaction;
 import org.geotools.data.shapefile.ShapefileDataStore;
-import org.apache.commons.transaction.memory.PessimisticMapWrapper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.geotools.feature.AttributeTypeFactory;
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureType;
+import org.geotools.feature.FeatureTypeBuilder;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
+import org.geotools.feature.SimpleFeature;
 
+import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.Coordinate;
 
-import com.ximple.io.dgn7.Dgn7fileReader;
+import com.ximple.eofms.util.DefaultColorTable;
+import com.ximple.eofms.util.TPCLIDConverter;
+import com.ximple.eofms.util.TWDDatumConverter;
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.FrammeAttributeData;
 import com.ximple.io.dgn7.TextElement;
-import com.ximple.io.dgn7.ShapeElement;
-import com.ximple.io.dgn7.ComplexShapeElement;
 import com.ximple.io.dgn7.UserAttributeData;
-import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter;
-import com.ximple.eofms.util.TPCLIDConverter;
-import com.ximple.eofms.util.DefaultColorTable;
-import com.ximple.eofms.util.StringUtils;
 
 public class IndexDgnConvertJobContext extends AbstractDgnFileJobContext
 {
-    static Log logger = LogFactory.getLog(IndexDgnConvertJobContext.class);
-    static GeometryFactory geometryFactory = new GeometryFactory();
-    private final static String SHPOUTPATH = "shpout";
+    static final Log logger = LogFactory.getLog(IndexDgnConvertJobContext.class);
+    static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
+    static final GeometryFactory geometryFactory = new GeometryFactory();
+    static final String SHPOUTPATH = "shpout";
 
     private String dataOut = null;
 
@@ -58,6 +56,7 @@
     public IndexDgnConvertJobContext(String dataPath)
     {
         super(dataPath);
+        txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger);
     }
 
     public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException
@@ -125,7 +124,7 @@
                 File sfile = new File(getDataOutPath() + "\\" + featureType.getTypeName());
                 logger.debug("Begin Save shapefile:" + sfile.toURI());
 
-                FeatureWriter writer = null;
+                FeatureWriter writer;
                 if(featuresWriterContext.containsKey(featureType.getTypeName()))
                 {
                     writer = (FeatureWriter) featuresWriterContext.get(featureType.getTypeName()) ;
@@ -163,7 +162,6 @@
         {
             logger.error(e.getMessage(), e);
         }
-
     }
 
     public String getDataOutPath()
@@ -206,20 +204,19 @@
         DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
         if (element instanceof TextElement)
         {
-            TextElement textElm = (TextElement) element;
-            String tpclid = textElm.getText();
+            TextElement textElement = (TextElement) element;
+            String tpclid = textElement.getText();
 
             Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid);
             Geometry geom = geometryFactory.createLinearRing(new Coordinate[]
             {
-                    new Coordinate(extent.getMinX(), extent.getMinY()),
-                    new Coordinate(extent.getMaxX(), extent.getMinY()),
-                    new Coordinate(extent.getMaxX(), extent.getMaxY()),
-                    new Coordinate(extent.getMinX(), extent.getMaxY()),
-                    new Coordinate(extent.getMinX(), extent.getMinY()),
+                    TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMinY())),
+                    TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMaxX(), extent.getMinY())),
+                    TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMaxX(), extent.getMaxY())),
+                    TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMaxY())),
+                    TWDDatumConverter.fromTM2ToTWD97(new Coordinate(extent.getMinX(), extent.getMinY())),
             });
 
-            TextElement textElement = (TextElement) element;
             Feature feature = featureType.create(new Object[]{
                     geom,
                     extent.getMinX(),
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
index 82b14d9..5ff3300 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
@@ -1,10 +1,10 @@
 package com.ximple.eofms.jobs;
 
-import java.io.IOException;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
@@ -14,22 +14,19 @@
 import java.sql.Statement;
 import java.sql.Types;
 import java.util.Date;
-import java.util.List;
-import java.util.Iterator;
 
 import org.apache.commons.collections.OrderedMap;
 import org.apache.commons.collections.OrderedMapIterator;
 import org.apache.commons.collections.map.LinkedMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.SchemaException;
 
 import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.Envelope;
 
 import oracle.jdbc.OracleConnection;
 import oracle.jdbc.OracleResultSet;
@@ -38,21 +35,15 @@
 
 import com.ximple.eofms.util.BinConverter;
 import com.ximple.eofms.util.ByteArrayCompressor;
-import com.ximple.eofms.util.TPCLIDConverter;
 import com.ximple.eofms.util.StringUtils;
 import com.ximple.io.dgn7.ComplexElement;
 import com.ximple.io.dgn7.Dgn7fileException;
+import com.ximple.io.dgn7.Dgn7fileReader;
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.ElementType;
 import com.ximple.io.dgn7.IElementHandler;
-import com.ximple.io.dgn7.Dgn7fileReader;
 import com.ximple.io.dgn7.Lock;
-import com.ximple.io.dgn7.ComplexChainElement;
-import com.ximple.io.dgn7.ComplexShapeElement;
-import com.ximple.io.dgn7.TextNodeElement;
 import com.ximple.io.dgn7.TextElement;
-import com.ximple.io.dgn7.UserAttributeData;
-import com.ximple.io.dgn7.FrammeAttributeData;
 import com.ximple.util.PrintfFormat;
 
 /**
@@ -60,7 +51,7 @@
  */
 public class OracleConvertDgn2ShpJob extends AbstractOracleDatabaseJob
 {
-    static Log logger = LogFactory.getLog(OracleConvertDgn2ShpJob.class);
+    final static Log logger = LogFactory.getLog(OracleConvertDgn2ShpJob.class);
 
     private static final int FETCHSIZE = 30;
     private static final int BATCHSIZE = 25;
@@ -539,7 +530,7 @@
                 {
                     lastComplex = null;
 
-                    processElement(element, convertContext);
+                    processIndexElement(element, convertContext);
                 } else if (element.isComponentElement())
                 {
                     if (lastComplex != null)
@@ -553,7 +544,7 @@
                         lastComplex = element;
                     } else
                     {
-                        processElement(element, convertContext);
+                        processIndexElement(element, convertContext);
                         lastComplex = element;
                     }
                 }
@@ -564,7 +555,7 @@
         logger.debug("ElementRecord Count=" + count);
     }
 
-    private void processElement(Element element, IndexDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException
+    private void processIndexElement(Element element, IndexDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException
     {
         if (element instanceof TextElement)
         {
@@ -577,7 +568,7 @@
      * �����ഫ��L�]�p���ɪ��u�@
      * @param context
      */
-    private void convertOtherDesignFile(JobExecutionContext context)
+    private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException
     {
         File otherDir = new File(getDataPath(), "other");
         if (!otherDir.exists())
@@ -602,11 +593,51 @@
         for (File dgnFile : dgnFiles)
         {
             GeneralDgnConvertJobContext convertContext = new GeneralDgnConvertJobContext(getDataPath());
-            convertContext.setExecutionContext(context);
+            try
+            {
+                convertContext.setExecutionContext(context);
+                String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator);
+                convertContext.setFilename(dgnPaths[dgnPaths.length - 1]);
+
+                FileInputStream fs = new FileInputStream(dgnFile);
+                FileChannel fc = fs.getChannel();
+                Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock());
+                convertContext.setReader(reader);
+
+                scanOtherDgnElement(convertContext);
+
+                convertContext.commitTransaction();
+            } catch (FileNotFoundException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (Dgn7fileException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (IOException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (IllegalAttributeException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            } catch (SchemaException e)
+            {
+                convertContext.rollbackTransaction();
+                logger.warn(e.getMessage(), e);
+                throw new JobExecutionException(e.getMessage(), e);
+            }
         }
     }
 
-    public void scanOtherDgnElement(GeneralDgnConvertJobContext convertContext) throws Dgn7fileException, IOException
+    public void scanOtherDgnElement(GeneralDgnConvertJobContext convertContext)
+            throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException
     {
         Dgn7fileReader reader = convertContext.getReader();
         int count = 0;
@@ -621,13 +652,9 @@
 
                 if ((!type.isComplexElement()) && (!element.isComponentElement()))
                 {
-                    if (lastComplex != null)
-                    {
-                        // @todo add process in here
-                        lastComplex = null;
-                    }
+                    lastComplex = null;
 
-                    // @todo add process in here
+                    processOtherElement(element, convertContext);
                 } else if (element.isComponentElement())
                 {
                     if (lastComplex != null)
@@ -641,75 +668,22 @@
                         lastComplex = element;
                     } else
                     {
-                        // @todo add process in here
+                        processOtherElement(element, convertContext);
                         lastComplex = element;
-                    }
-                }
-
-                if (element.getElementType().isComplexElement())
-                {
-                    if (element instanceof ComplexChainElement)
-                    {
-                        ComplexChainElement complexChain = (ComplexChainElement) element;
-                        int size = complexChain.size();
-                        for (Object aComplexChain : complexChain)
-                        {
-                            Element subElement = (Element) aComplexChain;
-                            subElement.getType();
-                        }
-                    }
-
-                    if (element instanceof ComplexShapeElement)
-                    {
-                        ComplexShapeElement complexShape = (ComplexShapeElement) element;
-                    }
-
-                    if (element instanceof TextNodeElement)
-                    {
-                        TextNodeElement textNode = (TextNodeElement) element;
-                        int size = textNode.size();
-                        for (int i = 0; i < size; i++)
-                        {
-                            Element subElement = (Element) textNode.get(i);
-                            subElement.getElementType();
-                        }
-                    }
-
-                } else
-                {
-                    boolean hasLinkage = false;
-                    if (element instanceof TextElement)
-                    {
-                        TextElement textElm = (TextElement) element;
-                        List<UserAttributeData> usrData = textElm.getUserAttributeData();
-                        Iterator<UserAttributeData> it = usrData.iterator();
-                        while (it.hasNext())
-                        {
-                            UserAttributeData attr = it.next();
-                            if (attr instanceof FrammeAttributeData)
-                            {
-                                hasLinkage = true;
-                                System.out.println("------------------------------------------");
-                                System.out.println("FSC=" + ((FrammeAttributeData) attr).getFsc() + ":" +
-                                        ((FrammeAttributeData) attr).getUfid());
-                            }
-                        }
-
-                        if (hasLinkage)
-                        {
-                            System.out.println("Text.Font=" + textElm.getFontIndex());
-                            System.out.println("Text.Just=" + textElm.getJustification());
-                            System.out.println("usrData.len=" + usrData.size());
-                            System.out.println("text=" + textElm.getText());
-                            System.out.println("Origin=" + textElm.getOrigin());
-                            System.out.println("UserOrigin=" + textElm.getUserOrigin());
-                        }
                     }
                 }
             }
             count++;
         }
 
-        logger.info("ElementRecord Count=" + count);
+        logger.debug("ElementRecord Count=" + count);
+    }
+
+    private void processOtherElement(Element element, GeneralDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException
+    {
+        if (element instanceof TextElement)
+        {
+            convertContext.putFeatureCollection(element);
+        }
     }
 }

--
Gitblit v0.0.0-SNAPSHOT