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.dbf / src / main / java / org / gvsig / fmap / dal / store / dbf / DBFFeatureProvider.java @ 42811

History | View | Annotate | Download (2.83 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.dbf;
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 DBFFeatureProvider extends DefaultFeatureProvider {
35
        protected DBFStoreProvider store;
36
        protected boolean loading;
37
        protected boolean loaded;
38

    
39
        public DBFFeatureProvider(DBFStoreProvider store, FeatureType type) {
40
                super(type);
41
                this.store = store;
42
                loading = false;
43
                loaded = false;
44
        }
45

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

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

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

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

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

    
90
        public Geometry getDefaultGeometry() {
91
                return null;
92
        }
93

    
94
        public Envelope getDefaultEnvelope() {
95
                return null;
96
        }
97

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

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

    
108

    
109

    
110

    
111
}