| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | ArrayList<ByteBuffer> subBuffers = new ArrayList<ByteBuffer>(); |
| | | if (fch != null) |
| | | { |
| | | ByteBuffer buf = null; |
| | |
| | | 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); |
| | |
| | | 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)) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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 |