root / branches / Mobile_Compatible_Hito_1 / libFMap / src-file / org / gvsig / data / datastores / vectorial / file / shp_jni / JNISHPStore.java @ 21606
History | View | Annotate | Download (5.74 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.shp_jni; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
import java.sql.Types; |
6 |
import java.util.List; |
7 |
|
8 |
import org.gvsig.data.IDataCollection; |
9 |
import org.gvsig.data.IDataExplorer; |
10 |
import org.gvsig.data.IDataStoreParameters; |
11 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters; |
12 |
import org.gvsig.data.datastores.vectorial.file.shp_mem.MemSHPRegister; |
13 |
import org.gvsig.data.datastores.vectorial.file.shp_util.IGeometricDataStore; |
14 |
import org.gvsig.data.datastores.vectorial.file.shp_util.SHPDataCollection; |
15 |
import org.gvsig.data.exception.CloseException; |
16 |
import org.gvsig.data.exception.InitializeException; |
17 |
import org.gvsig.data.exception.OpenException; |
18 |
import org.gvsig.data.exception.ReadException; |
19 |
import org.gvsig.data.exception.WriteException; |
20 |
import org.gvsig.data.spatialprovisional.Extent; |
21 |
import org.gvsig.data.spatialprovisional.IExtent; |
22 |
import org.gvsig.data.vectorial.AbstractFeatureStore; |
23 |
import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
24 |
import org.gvsig.data.vectorial.DefaultFeatureType; |
25 |
import org.gvsig.data.vectorial.IFeature; |
26 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
27 |
import org.gvsig.data.vectorial.IFeatureID; |
28 |
import org.gvsig.data.vectorial.IFeatureType; |
29 |
import org.gvsig.exceptions.BaseException; |
30 |
import org.gvsig.metadata.IMetadata; |
31 |
|
32 |
import com.hardcode.gdbms.engine.data.DataSource; |
33 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
34 |
|
35 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.dbf.DbfDiskDataSource; |
36 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.dbf.DbfMemoryDataSource; |
37 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.shp.DiskShpDriver; |
38 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.shp.MemoryShpDriver; |
39 |
|
40 |
public class JNISHPStore extends AbstractFeatureStore implements IGeometricDataStore { |
41 |
|
42 |
public static final String DATASTORE_NAME = "JNISHPStore"; |
43 |
|
44 |
static {
|
45 |
JNISHPRegister.selfRegister(); |
46 |
} |
47 |
|
48 |
|
49 |
protected IMetadata metadata;
|
50 |
|
51 |
private DiskShpDriver shp_drv = null; |
52 |
private DbfDiskDataSource dbf_ds = null; |
53 |
|
54 |
private File shp_file = null; |
55 |
protected IFeatureType featureType = null; |
56 |
private IExtent extent = null; |
57 |
|
58 |
private boolean onlyGeometry = false; |
59 |
|
60 |
public void init(IDataStoreParameters p) throws InitializeException { |
61 |
super.init(p);
|
62 |
shp_drv = new DiskShpDriver();
|
63 |
shp_file = ((SHPStoreParameters) p).getSHPFile(); |
64 |
|
65 |
File dbff = ((SHPStoreParameters) p).getDBFFile();
|
66 |
dbf_ds = new DbfDiskDataSource(dbff);
|
67 |
|
68 |
featureType = new DefaultFeatureType();
|
69 |
|
70 |
DefaultAttributeDescriptor dad = new DefaultAttributeDescriptor();
|
71 |
dad.setOrdinal(featureType.size()); |
72 |
dad.setName("GEOMETRY");
|
73 |
dad.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY); |
74 |
featureType.add(dad); |
75 |
featureType.setDefaultGeometry("GEOMETRY");
|
76 |
|
77 |
} |
78 |
|
79 |
|
80 |
protected void doFinishEdition() throws WriteException, ReadException { |
81 |
// TODO Auto-generated method stub
|
82 |
|
83 |
} |
84 |
|
85 |
public IDataCollection getDataCollection(IFeatureType type, String filter, |
86 |
String order) throws ReadException { |
87 |
return new SHPDataCollection(shp_drv, dbf_ds, featureType, onlyGeometry); |
88 |
} |
89 |
|
90 |
public IFeature getFeatureByID(IFeatureID id) throws ReadException { |
91 |
// TODO Auto-generated method stub
|
92 |
return null; |
93 |
} |
94 |
|
95 |
public List getFeatureTypes() { |
96 |
// TODO Auto-generated method stub
|
97 |
return null; |
98 |
} |
99 |
|
100 |
public IFeatureType getDefaultFeatureType() {
|
101 |
// TODO Auto-generated method stub
|
102 |
return featureType;
|
103 |
} |
104 |
|
105 |
public boolean isWithDefaultLegend() { |
106 |
// TODO Auto-generated method stub
|
107 |
return false; |
108 |
} |
109 |
|
110 |
public Object getDefaultLegend() { |
111 |
// TODO Auto-generated method stub
|
112 |
return null; |
113 |
} |
114 |
|
115 |
public Object getDefaultLabelingStrategy() { |
116 |
// TODO Auto-generated method stub
|
117 |
return null; |
118 |
} |
119 |
|
120 |
public boolean canAlterFeatureType() { |
121 |
// TODO Auto-generated method stub
|
122 |
return false; |
123 |
} |
124 |
|
125 |
public String getName() { |
126 |
return DATASTORE_NAME;
|
127 |
} |
128 |
|
129 |
public void open() throws OpenException { |
130 |
try {
|
131 |
shp_drv.open(shp_file); |
132 |
shp_drv.initialize(); |
133 |
extent = new Extent(shp_drv.getFullExtent());
|
134 |
dbf_ds.start(); |
135 |
|
136 |
for (int i = 0; i < dbf_ds.getFieldCount(); i++) { |
137 |
featureType.add(createFeatureAttribute(dbf_ds, i)); |
138 |
} |
139 |
|
140 |
} catch (Exception e) { |
141 |
throw new OpenException(e.getMessage(), DATASTORE_NAME); |
142 |
} |
143 |
} |
144 |
|
145 |
public void close() throws CloseException { |
146 |
try {
|
147 |
shp_drv.close(); |
148 |
dbf_ds.stop(); |
149 |
} catch (Exception e) { |
150 |
throw new CloseException(e.getMessage(), DATASTORE_NAME); |
151 |
} |
152 |
} |
153 |
|
154 |
public void dispose() { |
155 |
shp_drv = null;
|
156 |
} |
157 |
|
158 |
public boolean isEditable() { |
159 |
// TODO Auto-generated method stub
|
160 |
return false; |
161 |
} |
162 |
|
163 |
public IDataExplorer getExplorer() throws ReadException { |
164 |
// TODO Auto-generated method stub
|
165 |
return null; |
166 |
} |
167 |
|
168 |
public IMetadata getMetadata() throws BaseException { |
169 |
// TODO Auto-generated method stub
|
170 |
return metadata;
|
171 |
} |
172 |
|
173 |
|
174 |
public IExtent getFullExtent() {
|
175 |
return extent;
|
176 |
} |
177 |
|
178 |
|
179 |
public void setOnlyGeometry(boolean b) { |
180 |
onlyGeometry = b; |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
private IFeatureAttributeDescriptor createFeatureAttribute(DataSource dbf, int i) |
186 |
throws DriverException {
|
187 |
int fieldType = dbf.getFieldType(i);
|
188 |
DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
|
189 |
dad.setOrdinal(i); |
190 |
dad.setName(dbf.getFieldName(i)); |
191 |
dad.setSize(dbf.getFieldWidth(i)); |
192 |
|
193 |
switch (fieldType) {
|
194 |
case Types.DOUBLE: |
195 |
dad.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE); |
196 |
dad.setPrecision(6);
|
197 |
break;
|
198 |
|
199 |
case Types.VARCHAR: |
200 |
dad.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
201 |
break;
|
202 |
case Types.DATE: |
203 |
dad.setType(IFeatureAttributeDescriptor.TYPE_DATE); |
204 |
break;
|
205 |
case Types.BOOLEAN: |
206 |
dad.setType(IFeatureAttributeDescriptor.TYPE_BOOLEAN); |
207 |
break;
|
208 |
default:
|
209 |
dad.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
210 |
} |
211 |
return dad;
|
212 |
|
213 |
} |
214 |
|
215 |
|
216 |
|
217 |
} |