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 +++++++++++++++++ xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java | 98 +++++++++++++++++++ .gitattributes | 2 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java | 2 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java | 1 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java | 2 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java | 13 ++ xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java | 47 +++++++++ xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java | 1 9 files changed, 245 insertions(+), 8 deletions(-) diff --git a/.gitattributes b/.gitattributes index 5d98d7a..8aac53f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,7 +19,7 @@ xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java svneol=native#text/plain xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/FrammeAttributeData.java svneol=native#text/plain xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/GeometryConverter.java svneol=native#text/plain -xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java svneol=native#text/plain +xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java -text xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java svneol=native#text/plain xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java svneol=native#text/plain xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Lock.java svneol=native#text/plain diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java index 363de3c..9b722d7 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java @@ -8,10 +8,8 @@ import org.apache.log4j.Logger; -import com.vividsolutions.jts.geom.CoordinateList; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.LineString; /** diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java index f1788ac..030b950 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java @@ -5,9 +5,9 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.List; -import java.util.Arrays; import com.vividsolutions.jts.geom.Envelope; @@ -71,6 +71,29 @@ DgnUtility.converUnitToCoord(lowCoorY), DgnUtility.converUnitToCoord(highCoorY)); } + public void setRange(Envelope bbox) + { + int lowCoordX = DgnUtility.converCoordToUnit(bbox.getMinX()); + int temp = DgnUtility.converToDGN(lowCoordX); + raw[3] = (short) (temp >> 16 & 0x0000ffff); + raw[2] = (short) (temp & 0x0000ffff); + + int lowCoordY = DgnUtility.converCoordToUnit(bbox.getMinY()); + temp = DgnUtility.converToDGN(lowCoordY); + raw[5] = (short) (temp >> 16 & 0x0000ffff); + raw[4] = (short) (temp & 0x0000ffff); + + int highCoorX = DgnUtility.converCoordToUnit(bbox.getMaxX()); + temp = DgnUtility.converToDGN(highCoorX); + raw[9] = (short) (temp >> 16 & 0x0000ffff); + raw[8] = (short) (temp & 0x0000ffff); + + int highCoorY = DgnUtility.converCoordToUnit(bbox.getMaxY()); + temp = DgnUtility.converToDGN(highCoorY); + raw[11] = (short) (temp >> 16 & 0x0000ffff); + raw[10] = (short) (temp & 0x0000ffff); + } + public boolean isComponentElement() { return (short) ((raw[0] >>> 7) & 0x0001) == 1; @@ -109,6 +132,11 @@ public int getLevelIndex() { return (raw[0] & 0x003f); + } + + public void setLevelIndex(int value) + { + raw[0] = (short) ((raw[0] & 0xffc0) | (value & 0x003f)); } public int getWeight() @@ -227,6 +255,18 @@ return offset * 2; } + public void resyncBuffer() + { + byte[] tempRaw = new byte[this.raw.length * 2]; + ByteBuffer tempBuffer = ByteBuffer.wrap(tempRaw); + tempBuffer.order(ByteOrder.LITTLE_ENDIAN); + tempBuffer.asShortBuffer().put(this.raw); + + int pos = rawBuffer.position(); + rawBuffer = tempBuffer; + rawBuffer.position(pos); + } + public static class ElementHandler implements IElementHandler { ElementType elementType; @@ -281,6 +321,11 @@ return ((Element) element).raw.length; } + public int getBufferLength(Object element) + { + return ((Element) element).rawBuffer.limit(); + } + protected Element createElement(byte[] raw) { return new Element(raw); diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java index c98b9f3..37af5e9 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java @@ -20,4 +20,6 @@ public void write(ByteBuffer buffer, Object element); public int getLength(Object element); + + public int getBufferLength(Object element); } diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java index f9d9cd5..79ca5eb 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java @@ -312,6 +312,19 @@ return new Coordinate(dstPt[0], dstPt[1]); } + public Object clone() throws CloneNotSupportedException + { + int pos = this.rawBuffer.position(); + this.rawBuffer.position(0); + byte[] rawBytes = this.rawBuffer.array(); + byte[] otherRaw = new byte[rawBytes.length]; + System.arraycopy(rawBytes, 0, otherRaw, 0, rawBytes.length); + this.rawBuffer.position(pos); + + TextElement other = new TextElement(otherRaw); + return other; + } + public static class ElementHandler extends Element.ElementHandler { private static ElementHandler instance = null; diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java index 8a959dc..fbab7cd 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java @@ -184,9 +184,24 @@ // return factory.createMultiPoint(coords.toCoordinateArray()); } + public int getTotalWords() + { + return (raw[18] & 0x0000ffff); + } + + public void setTotalWords(int value) + { + raw[18] = (short) (value & 0x0000ffff); + } + public int getNumString() { return (raw[19] & 0x0000ffff); + } + + public void setNumString(int value) + { + raw[19] = (short) (value & 0x0000ffff); } public int getNodeNumber() @@ -194,9 +209,19 @@ return (raw[20] & 0x0000ffff); } + public void setNodeNumber(int value) + { + raw[20] = (short) (value & 0x0000ffff); + } + public int getMaxLength() { return (raw[21] & 0x00ff); + } + + public void setMaxLength(int value) + { + raw[21] = (short) ((value & 0x00ff) | (raw[21] & 0xff00)); } public int getMaxUsed() @@ -204,14 +229,29 @@ return ((raw[21] >> 8) & 0x00ff); } + public void setMaxUsed(int value) + { + raw[21] = (short) (((value << 8) & 0xff00) | (raw[21] & 0x00ff)); + } + public int getJustification() { return ((raw[22] >> 8) & 0x00ff); } + public void setJustification(int value) + { + raw[22] = (short) (((value << 8) & 0xff00) | (raw[22] & 0x00ff)); + } + public int getFontIndex() { return (raw[22] & 0x00ff); + } + + public void setFontIndex(int value) + { + raw[22] = (short) ((value & 0x00ff) | (raw[22] & 0xff00)); } public double getLineSpacing() @@ -220,6 +260,13 @@ lineSpace = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff); return lineSpace; + } + + public void setLineSpacing(double value) + { + int temp = (int) (value*1000.0); + raw[23] = (short) ((temp >> 16) & 0x0000ffff); + raw[24] = (short) (temp & 0x0000ffff); } public double getTextNodeLength() @@ -232,6 +279,13 @@ return DgnUtility.converIntToDouble(lengthMult); } + public void setTextNodeLength(double value) + { + int temp = DgnUtility.converDoubleToInt(value); + raw[25] = (short) ((temp >> 16) & 0x0000ffff); + raw[26] = (short) (temp & 0x0000ffff); + } + public double getTextNodeHeight() { int heightMult; @@ -242,12 +296,26 @@ return DgnUtility.converIntToDouble(heightMult); } + public void setTextNodeHeight(double value) + { + int temp = DgnUtility.converDoubleToInt(value); + raw[27] = (short) ((temp >> 16) & 0x0000ffff); + raw[28] = (short) (temp & 0x0000ffff); + } + public double getRotationAngle() { int rotation = (raw[29] << 16 & 0xffff0000); rotation += raw[30]; return DgnUtility.converIntToRotation(rotation); + } + + public void setRotationAngle(double value) + { + int temp = DgnUtility.converRotatioToInt(value); + raw[29] = (short) (temp >> 16 & 0x0000ffff); + raw[30] = (short) (temp & 0x0000ffff); } public Coordinate getOrigin() @@ -262,6 +330,36 @@ return new Coordinate(dx, dy); } + public void setOrigin(Coordinate value) + { + int x = DgnUtility.converCoordToUnit(value.x); + raw[31] = (short) (x >> 16 & 0x0000ffff); + raw[32] = (short) (x & 0x0000ffff); + + int y = DgnUtility.converCoordToUnit(value.y); + raw[33] = (short) (y >> 16 & 0x0000ffff); + raw[34] = (short) (y & 0x0000ffff); + } + + public Object clone() throws CloneNotSupportedException + { + int pos = this.rawBuffer.position(); + this.rawBuffer.position(0); + byte[] rawBytes = this.rawBuffer.array(); + byte[] otherRaw = new byte[rawBytes.length]; + System.arraycopy(rawBytes, 0, otherRaw, 0, rawBytes.length); + this.rawBuffer.position(pos); + + TextNodeElement other = new TextNodeElement(otherRaw); + for (Object o : this) + { + TextElement textElm = (TextElement) o; + other.add(textElm.clone()); + } + + return other; + } + public static class ElementHandler extends Element.ElementHandler { private static ElementHandler instance = null; diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java index 8fb69d3..ccea789 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java @@ -14,7 +14,6 @@ import java.sql.Statement; import java.sql.Types; import java.sql.Connection; -import java.util.Calendar; import java.util.Date; import java.util.Map; import java.util.TreeMap; diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java index f13c971..e444094 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java @@ -14,7 +14,6 @@ import java.sql.Statement; import java.sql.Types; import java.sql.Connection; -import java.util.Calendar; import java.util.Date; import java.util.Map; import java.util.TreeMap; 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