forked from geodmms/xdgnjobs

?? ?
2010-04-22 6523c1f6534042d89ff8a07d4e7c06050276521e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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);
    }
}