root / branches / v2_0_0_prep / libraries / libFMap_dataFile / src-test / org / gvsig / fmap / data / feature / file / dgn / DGNTest.java @ 22958
History | View | Annotate | Download (3.87 KB)
1 |
package org.gvsig.fmap.data.feature.file.dgn; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.gvsig.fmap.data.CloseException; |
9 |
import org.gvsig.fmap.data.DataManager; |
10 |
import org.gvsig.fmap.data.InitializeException; |
11 |
import org.gvsig.fmap.data.ReadException; |
12 |
import org.gvsig.fmap.data.feature.Feature; |
13 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.data.feature.FeatureCollection; |
15 |
import org.gvsig.fmap.data.feature.FeatureType; |
16 |
import org.gvsig.fmap.data.feature.file.DataStoreTest; |
17 |
|
18 |
public class DGNTest extends TestCase { |
19 |
|
20 |
public static final File file = new File(DataStoreTest.class.getResource( |
21 |
"data/prueba.dgn").getFile());
|
22 |
|
23 |
|
24 |
public static void main(String[] args) { |
25 |
} |
26 |
|
27 |
protected void setUp() throws Exception { |
28 |
super.setUp();
|
29 |
} |
30 |
|
31 |
public void testInitialize() { |
32 |
Register.selfRegister(); |
33 |
DataManager manager = DataManager.getManager(); |
34 |
DGNStore store = null;
|
35 |
|
36 |
DGNStoreParameters dgnParameters=null;
|
37 |
try {
|
38 |
dgnParameters=(DGNStoreParameters)manager.createDataStoreParameters(DGNStore.DATASTORE_NAME); |
39 |
} catch (InitializeException e1) {
|
40 |
e1.printStackTrace(); |
41 |
fail(); |
42 |
} |
43 |
dgnParameters.setFile(file); |
44 |
try {
|
45 |
store = (DGNStore)manager.createDataStore(dgnParameters); |
46 |
} catch (InitializeException e) {
|
47 |
// TODO Auto-generated catch block
|
48 |
e.printStackTrace(); |
49 |
} |
50 |
|
51 |
FeatureType ft=store.getDefaultFeatureType(); |
52 |
FeatureCollection featureCollection=null;
|
53 |
try {
|
54 |
featureCollection = (FeatureCollection)store.getDataCollection(ft,null,null); |
55 |
} catch (ReadException e) {
|
56 |
// TODO Auto-generated catch block
|
57 |
e.printStackTrace(); |
58 |
} |
59 |
Iterator iter = featureCollection.iterator();
|
60 |
while (iter.hasNext()) {
|
61 |
Feature feature = (Feature)iter.next(); |
62 |
System.out.println("DGN Feature ------------------- "); |
63 |
Iterator iterator=ft.iterator();
|
64 |
while (iterator.hasNext()) {
|
65 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next(); |
66 |
int i=descriptor.ordinal();
|
67 |
String type=descriptor.getDataType();
|
68 |
if (type.equals(FeatureAttributeDescriptor.TYPE_BOOLEAN)){
|
69 |
System.out.println("Boolean ----- "+ feature.getBoolean(i)); |
70 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_BYTE)){ |
71 |
System.out.println("Byte ----- "+ feature.getByte(i)); |
72 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_DATE)){ |
73 |
System.out.println("Date ----- "+ feature.getDate(i)); |
74 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_DOUBLE)){ |
75 |
System.out.println("Double ----- "+ feature.getDouble(i)); |
76 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_FLOAT)){ |
77 |
System.out.println("Float ----- "+ feature.getFloat(i)); |
78 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_INT)){ |
79 |
System.out.println("Integer ----- "+ feature.getInt(i)); |
80 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_LONG)){ |
81 |
System.out.println("Long ----- "+ feature.getLong(i)); |
82 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_STRING)){ |
83 |
System.out.println("String ----- "+ feature.getString(i)); |
84 |
}else if (type.equals(FeatureAttributeDescriptor.TYPE_GEOMETRY)){ |
85 |
|
86 |
System.out.println("Geometry ----- "+ feature.getGeometry(i)); |
87 |
} |
88 |
} |
89 |
} |
90 |
iter = null;
|
91 |
featureCollection.dispose(); |
92 |
|
93 |
try {
|
94 |
store.dispose(); |
95 |
} catch (CloseException e) {
|
96 |
// TODO Auto-generated catch block
|
97 |
e.printStackTrace(); |
98 |
} |
99 |
} |
100 |
|
101 |
public void test_Resources(){ |
102 |
|
103 |
DataManager manager = DataManager.getManager(); |
104 |
Register.selfRegister(); |
105 |
|
106 |
DGNStoreParameters parameters=null;
|
107 |
|
108 |
try {
|
109 |
parameters=(DGNStoreParameters)manager.createDataStoreParameters(DGNStore.DATASTORE_NAME); |
110 |
} catch (InitializeException e) {
|
111 |
e.printStackTrace(); |
112 |
fail(); |
113 |
} |
114 |
parameters.setFile(file); |
115 |
|
116 |
|
117 |
DataStoreTest.doFileResourceTest(parameters); |
118 |
} |
119 |
|
120 |
} |