package com.ximple.io.dgn7; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.channels.FileChannel; import org.apache.log4j.Logger; import org.geotools.TestData; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** * Dgn7fileReaderTest * User: Ulysses * Date: 2007/10/24 * Time: �W�� 01:43:41 * To change this template use File | Settings | File Templates. */ public class Dgn7fileReaderTest { private final static Logger logger = Logger.getLogger(Dgn7fileReaderTest.class); // private final static String testFilePath = "test-data\\testHV.dgn"; private final static String testFilePath = "testHV.dgn"; private FileInputStream _fs; @BeforeTest public void setUp() throws IOException { File dataFile = TestData.file(this, testFilePath); if (!dataFile.exists()) { return; } _fs = new FileInputStream(dataFile); } @Test public void testRead() throws Dgn7fileException, IOException { if (_fs == null) return; FileChannel fc = _fs.getChannel(); Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock()); int count = 0; Element lastComplex = null; while (reader.hasNext()) { Element.FileRecord record = reader.nextElement(); if (record.element() != null) { Element element = (Element) record.element(); ElementType type = element.getElementType(); if ((!type.isComplexElement()) && (!element.isComponentElement())) { if (lastComplex != null) { // @todo add process in here lastComplex = null; } // @todo add process in here } else if (element.isComponentElement()) { if (lastComplex != null) { ((ComplexElement) lastComplex).add(element); } } else if (type.isComplexElement()) { if (lastComplex == null) { lastComplex = element; } else { // @todo add process in here 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(); } } } } count++; } logger.info("FileRecord Count=" + count); } }