From 1939acb5eeca2792e93a0e236ed2f4a60b4d4008 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Wed, 25 Jun 2008 19:24:44 +0800
Subject: [PATCH] update for EOFM-127

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java |   87 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java
index bcef716..2b146b3 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleElementLogger.java
@@ -12,6 +12,7 @@
 import java.sql.Statement;
 import java.sql.Types;
 import java.util.ArrayList;
+import java.util.ListIterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -31,11 +32,13 @@
 import com.ximple.io.dgn7.ShapeElement;
 import com.ximple.io.dgn7.TextElement;
 import com.ximple.io.dgn7.TextNodeElement;
+import com.ximple.io.dgn7.IElementHandler;
+import com.ximple.io.dgn7.Dgn7fileException;
 
 public class OracleElementLogger
 {
     static Log logger = LogFactory.getLog(OracleElementLogger.class);
-    private static final String ELMOUTPATH = "elmout";
+    private static final String DEFAULT_ELMOUTPATH = "elmout";
     private static final String TAB_IGDSSEED = "SD$IGDSSET_SEED";
 
     private Connection connection;
@@ -47,17 +50,25 @@
     private FileChannel fch = null;
     private int logCount = 0;
     private ArrayList<byte[]> dgnFileHeader = null;
+    private String elmOutPath;
 
     public OracleElementLogger(Connection connection)
     {
         this.connection = connection;
+        elmOutPath = DEFAULT_ELMOUTPATH;
+    }
+
+    public OracleElementLogger(Connection connection, String elmOutPath)
+    {
+        this.connection = connection;
+        this.elmOutPath = elmOutPath;
     }
 
     public String getDataOutPath()
     {
         if (dataOut == null)
         {
-            File outPath = new File(getDataPath(), ELMOUTPATH);
+            File outPath = new File(getDataPath(), elmOutPath);
             if (!outPath.exists())
             {
                 outPath.mkdir();
@@ -118,6 +129,7 @@
             }
         }
 
+        ArrayList<ByteBuffer> subBuffers = new ArrayList<ByteBuffer>();
         if (fch != null)
         {
             ByteBuffer buf = null;
@@ -141,11 +153,45 @@
                 int size = ComplexChainElement.ElementHandler.getInstance().getLength(element);
                 buf = ByteBuffer.allocate(size * 2);
                 ComplexChainElement.ElementHandler.getInstance().write(buf, element);
+                ComplexChainElement complexElement = (ComplexChainElement) element;
+                ListIterator it = complexElement.listIterator();
+                while (it.hasNext())
+                {
+                    Element subElm = (Element) it.next();
+                    try
+                    {
+                        IElementHandler handler = subElm.getElementType().getElementHandler();
+                        size = handler.getLength(subElm);
+                        ByteBuffer subBuf = ByteBuffer.allocate(size * 2);
+                        handler.write(subBuf, subElm);
+                        subBuffers.add(subBuf);
+                    } catch (Dgn7fileException e)
+                    {
+                        logger.warn(e.getMessage(), e);
+                    }
+                }
             } else if (element instanceof ComplexShapeElement)
             {
                 int size = ComplexShapeElement.ElementHandler.getInstance().getLength(element);
                 buf = ByteBuffer.allocate(size * 2);
                 ComplexShapeElement.ElementHandler.getInstance().write(buf, element);
+                ComplexShapeElement complexElement = (ComplexShapeElement) element;
+                ListIterator it = complexElement.listIterator();
+                while (it.hasNext())
+                {
+                    Element subElm = (Element) it.next();
+                    try
+                    {
+                        IElementHandler handler = subElm.getElementType().getElementHandler();
+                        size = handler.getLength(subElm);
+                        ByteBuffer subBuf = ByteBuffer.allocate(size * 2);
+                        handler.write(subBuf, subElm);
+                        subBuffers.add(subBuf);
+                    } catch (Dgn7fileException e)
+                    {
+                        logger.warn(e.getMessage(), e);
+                    }
+                }
             } else if (element instanceof ArcElement)
             {
                 int size = ArcElement.ElementHandler.getInstance().getLength(element);
@@ -166,6 +212,23 @@
                 int size = TextNodeElement.ElementHandler.getInstance().getLength(element);
                 buf = ByteBuffer.allocate(size * 2);
                 TextNodeElement.ElementHandler.getInstance().write(buf, element);
+                TextNodeElement nodeElement = (TextNodeElement) element;
+                ListIterator it = nodeElement.listIterator();
+                while (it.hasNext())
+                {
+                    Element subElm = (Element) it.next();
+                    try
+                    {
+                        IElementHandler handler = subElm.getElementType().getElementHandler();
+                        size = handler.getLength(subElm);
+                        ByteBuffer subBuf = ByteBuffer.allocate(size * 2);
+                        handler.write(subBuf, subElm);
+                        subBuffers.add(subBuf);
+                    } catch (Dgn7fileException e)
+                    {
+                        logger.warn(e.getMessage(), e);
+                    }
+                }
             }
 
             if ((buf != null) && (fch != null))
@@ -185,6 +248,26 @@
                 }
             }
         }
+
+        if ((subBuffers.size() != 0) && (fch != null))
+        {
+            for (ByteBuffer buf : subBuffers)
+            {
+                try
+                {
+                    buf.position(0);
+                    int size = fch.write(buf);
+                    if (size != buf.limit())
+                    {
+                        long position = fch.position();
+                        logger.info("Pos:" + position);
+                    }
+                } catch (IOException e)
+                {
+                    logger.warn(e.getMessage(), e);
+                }
+            }
+        }
     }
 
     private void createNewStream() throws IOException, SQLException

--
Gitblit v0.0.0-SNAPSHOT