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.csv / src / main / java / org / gvsig / fmap / dal / store / simplereader / AbstractFeatureProviderLoadedOnDemand.java @ 47638
History | View | Annotate | Download (3.32 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.simplereader; |
25 |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
27 |
import org.gvsig.fmap.dal.feature.FeatureType; |
28 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
29 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
32 |
|
33 |
public abstract class AbstractFeatureProviderLoadedOnDemand extends DefaultFeatureProvider { |
34 |
|
35 |
protected boolean loading; |
36 |
protected boolean loaded; |
37 |
protected String geomName; |
38 |
|
39 |
public AbstractFeatureProviderLoadedOnDemand(FeatureType type) {
|
40 |
super(type);
|
41 |
loading = false;
|
42 |
loaded = false;
|
43 |
FeatureAttributeDescriptor geomdesc = type.getDefaultGeometryAttribute(); |
44 |
if( geomdesc!=null ) { |
45 |
geomName = geomdesc.getName(); |
46 |
} |
47 |
} |
48 |
|
49 |
protected void load() { |
50 |
if (loading || loaded || this.isNew()) { |
51 |
return;
|
52 |
} |
53 |
loading = true;
|
54 |
try {
|
55 |
doLoad(); |
56 |
} catch (Exception e) { |
57 |
} finally {
|
58 |
loading = false;
|
59 |
loaded = true;
|
60 |
} |
61 |
} |
62 |
|
63 |
protected abstract void doLoad(); |
64 |
|
65 |
@Override
|
66 |
public void set(int i, Object value) { |
67 |
this.load();
|
68 |
super.set(i, value);
|
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void set(String name, Object value) { |
73 |
this.load();
|
74 |
super.set(featureType.getIndex(name), value);
|
75 |
} |
76 |
|
77 |
@Override
|
78 |
public Object get(int i) { |
79 |
this.load();
|
80 |
return super.get(i); |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public Object get(String name) { |
85 |
this.load();
|
86 |
return super.get(name); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public Geometry getDefaultGeometry() {
|
91 |
if( geomName == null ) { |
92 |
return null; |
93 |
} |
94 |
return (Geometry) this.get(geomName); |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public Envelope getDefaultEnvelope() {
|
99 |
Geometry geom = this.getDefaultGeometry();
|
100 |
if( geom==null ) { |
101 |
return null; |
102 |
} |
103 |
try {
|
104 |
return geom.getEnvelope();
|
105 |
} catch(Exception ex) { |
106 |
// En ocasiones con geometrias incorrectas getEnvelop falla.
|
107 |
return null; |
108 |
} |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void setOID(Object oid) { |
113 |
this.loaded = false; |
114 |
super.setOID(oid);
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public FeatureProvider getCopy() {
|
119 |
this.load();
|
120 |
return super.getCopy(); |
121 |
} |
122 |
} |