Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / main / java / org / gvsig / fmap / dal / store / shp / SHPFeatureProvider.java @ 42811

History | View | Annotate | Download (2.88 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.shp;
25

    
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.exception.ReadRuntimeException;
28
import org.gvsig.fmap.dal.feature.FeatureType;
29
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
30
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.primitive.Envelope;
33

    
34
public class SHPFeatureProvider extends DefaultFeatureProvider {
35
        protected SHPStoreProvider store;
36
        protected boolean loading;
37
        protected boolean loaded;
38

    
39

    
40
        public SHPFeatureProvider(SHPStoreProvider store, FeatureType type) {
41
                super(type);
42
                this.store = store;
43
                loading = false;
44
                loaded = false;
45
        }
46

    
47
        protected void load() {
48
                if (loading || loaded || this.isNew()) {
49
                        return;
50
                }
51
                loading = true;
52
                try {
53
                        this.store.loadFeatureProviderByIndex(this);
54
                } catch (DataException e) {
55
                    throw new ReadRuntimeException(getNameForMessages(), this.getOID(), e);
56
                } finally {
57
                        loading = false;
58
                        loaded = true;
59
                }
60
        }
61
        
62
        protected String getNameForMessages() {
63
            // Solo con proposito de mostrar en mensajes de error.
64
            try {
65
                return this.store.getName();
66
            } catch(Exception ex) {
67
                return "unknown";
68
            }
69
        }
70

    
71
        public void set(int i, Object value) {
72
                this.load();
73
                super.set(i, value);
74
        }
75

    
76
        public void set(String name, Object value) {
77
                this.load();
78
                super.set(featureType.getIndex(name), value);
79
        }
80

    
81
        public Object get(int i) {
82
                this.load();
83
                return super.get(i);
84
        }
85

    
86
        public Object get(String name) {
87
                this.load();
88
                return super.get(name);
89
        }
90

    
91
        public Geometry getDefaultGeometry() {
92
                this.load();
93
                return this.defaultGeometry;
94
        }
95

    
96
        public Envelope getDefaultEnvelope() {
97
                return this.envelope;
98
        }
99

    
100
        public void setOID(Object oid) {
101
                this.loaded = false;
102
                super.setOID(oid);
103
        }
104

    
105
        public FeatureProvider getCopy() {
106
                this.load();
107
                return super.getCopy();
108
        }
109

    
110
}