svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-file / org / gvsig / data / datastores / vectorial / file / shp_inst / InstSHPStore.java @ 22037
History | View | Annotate | Download (1.97 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.shp_inst; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import org.apache.log4j.Logger; |
7 |
import org.gvsig.data.CloseException; |
8 |
import org.gvsig.data.DataCollection; |
9 |
import org.gvsig.data.DataStoreParameters; |
10 |
import org.gvsig.data.InitializeException; |
11 |
import org.gvsig.data.OpenException; |
12 |
import org.gvsig.data.ReadException; |
13 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore; |
14 |
import org.gvsig.data.vectorial.Feature; |
15 |
import org.gvsig.data.vectorial.FeatureType; |
16 |
|
17 |
/**
|
18 |
* This data store creates an array of fully instantiated features when it is opened. Should be by far the fastest
|
19 |
* and the most memory-consuming
|
20 |
*
|
21 |
* @author jldominguez
|
22 |
*
|
23 |
*/
|
24 |
public class InstSHPStore extends SHPStore { |
25 |
|
26 |
private static Logger logger = Logger.getLogger(InstSHPStore.class); |
27 |
|
28 |
public static String DATASTORE_NAME = "InstSHPStore"; |
29 |
|
30 |
static {
|
31 |
InstSHPRegister.selfRegister(); |
32 |
} |
33 |
|
34 |
private Feature[] features; |
35 |
private int theSize = 0; |
36 |
|
37 |
public void init(DataStoreParameters p) throws InitializeException { |
38 |
super.init(p);
|
39 |
theSize = dbf.getRecordCount(); |
40 |
} |
41 |
|
42 |
public void doOpen() throws OpenException { |
43 |
super.doOpen();
|
44 |
|
45 |
|
46 |
// ----------------- get all features: ----------------------
|
47 |
features = new Feature[theSize];
|
48 |
|
49 |
try {
|
50 |
for (int i=0; i<theSize; i++) |
51 |
features[i] = super.getFeatureByPosition(featureType, (long) i); |
52 |
} catch (ReadException ex) {
|
53 |
logger.error("While getting all features: " + ex.getMessage());
|
54 |
} |
55 |
logger.debug("Created array in memory with: " + theSize + " features."); |
56 |
// ------------------------
|
57 |
|
58 |
try {
|
59 |
super.doClose();
|
60 |
} catch (CloseException e) {
|
61 |
logger.error("While closing after loading: " + e.getMessage());
|
62 |
throw new OpenException("hile closing after loading.", e); |
63 |
} |
64 |
} |
65 |
|
66 |
|
67 |
protected Feature getFeatureByPosition(FeatureType featureType,
|
68 |
long position) throws ReadException { |
69 |
return features[(int) position]; |
70 |
} |
71 |
|
72 |
protected long getFeatureCount() { |
73 |
return theSize;
|
74 |
} |
75 |
|
76 |
} |