svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / DefaultFeatureProvider.java @ 41058
History | View | Annotate | Download (5.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.feature.spi; |
25 |
|
26 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
27 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
28 |
import org.gvsig.fmap.dal.feature.FeatureType; |
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.primitive.Envelope; |
31 |
|
32 |
/**
|
33 |
* Default implementation for {@link FeatureProvider}
|
34 |
*
|
35 |
*/
|
36 |
public class DefaultFeatureProvider implements FeatureProvider { |
37 |
|
38 |
protected FeatureType featureType;
|
39 |
protected boolean[] nulls; |
40 |
protected Object[] values; |
41 |
protected Geometry defaultGeometry;
|
42 |
protected Envelope envelope;
|
43 |
private Object oid; |
44 |
private boolean isNew=false; |
45 |
|
46 |
public DefaultFeatureProvider(FeatureType type) {
|
47 |
if (type instanceof EditableFeatureType) { |
48 |
throw new IllegalArgumentException("type can't by editable."); |
49 |
} |
50 |
this.featureType = type;
|
51 |
this.values = new Object[featureType.size()]; |
52 |
this.nulls = new boolean[featureType.size()]; |
53 |
|
54 |
this.envelope = null; |
55 |
this.defaultGeometry = null; |
56 |
this.oid = null; |
57 |
} |
58 |
|
59 |
public DefaultFeatureProvider(FeatureType type, Object oid) { |
60 |
this(type);
|
61 |
this.oid = oid;
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
*
|
67 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(int,
|
68 |
* java.lang.Object)
|
69 |
*/
|
70 |
public void set(int i, Object value) { |
71 |
if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
72 |
defaultGeometry = (Geometry) value; |
73 |
envelope = null;
|
74 |
} |
75 |
if (value == null) { |
76 |
nulls[i] = true;
|
77 |
values[i] = featureType.getAttributeDescriptor(i).getDefaultValue(); |
78 |
} else {
|
79 |
values[i] = value; |
80 |
nulls[i] = false;
|
81 |
} |
82 |
} |
83 |
|
84 |
/*
|
85 |
* (non-Javadoc)
|
86 |
*
|
87 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
88 |
* java.lang.Object)
|
89 |
*/
|
90 |
public void set(String name, Object value) { |
91 |
set(featureType.getIndex(name), value); |
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
*
|
97 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
98 |
*/
|
99 |
public Object get(int i) { |
100 |
return values[i];
|
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
*
|
106 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
107 |
*/
|
108 |
public Object get(String name) { |
109 |
FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name); |
110 |
return values[featureAttributeDescriptor.getIndex()];
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
*
|
116 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
117 |
*/
|
118 |
public FeatureType getType() {
|
119 |
return featureType;
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
*
|
125 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
126 |
*/
|
127 |
public FeatureProvider getCopy() {
|
128 |
DefaultFeatureProvider data = new DefaultFeatureProvider(
|
129 |
this.getType());
|
130 |
return getCopy(data);
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Copy values from current instance to <code>data</code>
|
135 |
*/
|
136 |
protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
137 |
data.oid = this.oid;
|
138 |
System.arraycopy(this.values, 0, data.values, 0, this.values.length); |
139 |
data.defaultGeometry = this.defaultGeometry;
|
140 |
data.envelope = this.envelope;
|
141 |
data.isNew=this.isNew;
|
142 |
return data;
|
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
*
|
148 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
149 |
*/
|
150 |
public Envelope getDefaultEnvelope() {
|
151 |
if (envelope == null && getDefaultGeometry() != null) { |
152 |
envelope = getDefaultGeometry().getEnvelope(); |
153 |
} |
154 |
return envelope;
|
155 |
} |
156 |
|
157 |
/*
|
158 |
* (non-Javadoc)
|
159 |
*
|
160 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
161 |
*/
|
162 |
public Geometry getDefaultGeometry() {
|
163 |
return this.defaultGeometry; |
164 |
} |
165 |
|
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
*
|
169 |
* @see
|
170 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org
|
171 |
* .gvsig.fmap.geom.primitive.Envelope)
|
172 |
*/
|
173 |
public void setDefaultEnvelope(Envelope envelope) { |
174 |
this.envelope = envelope;
|
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
*
|
180 |
* @see
|
181 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultGeometry(org
|
182 |
* .gvsig.fmap.geom.Geometry)
|
183 |
*/
|
184 |
public void setDefaultGeometry(Geometry geom) { |
185 |
int i = featureType.getDefaultGeometryAttributeIndex();
|
186 |
defaultGeometry = geom; |
187 |
envelope = null;
|
188 |
values[i] = geom; |
189 |
} |
190 |
|
191 |
/*
|
192 |
* (non-Javadoc)
|
193 |
*
|
194 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(int)
|
195 |
*/
|
196 |
public boolean isNull(int i) { |
197 |
return nulls[i];
|
198 |
} |
199 |
|
200 |
/*
|
201 |
* (non-Javadoc)
|
202 |
*
|
203 |
* @see
|
204 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String)
|
205 |
*/
|
206 |
public boolean isNull(String name) { |
207 |
int i = featureType.getIndex(name);
|
208 |
return isNull(i);
|
209 |
} |
210 |
|
211 |
/*
|
212 |
* (non-Javadoc)
|
213 |
*
|
214 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID()
|
215 |
*/
|
216 |
public Object getOID() { |
217 |
return this.oid; |
218 |
} |
219 |
|
220 |
/*
|
221 |
* (non-Javadoc)
|
222 |
*
|
223 |
* @see
|
224 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object)
|
225 |
*/
|
226 |
public void setOID(Object oid) { |
227 |
this.oid = oid;
|
228 |
} |
229 |
|
230 |
/*
|
231 |
* (non-Javadoc)
|
232 |
*
|
233 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew()
|
234 |
*/
|
235 |
public boolean isNew(){ |
236 |
return isNew;
|
237 |
} |
238 |
|
239 |
/*
|
240 |
* (non-Javadoc)
|
241 |
*
|
242 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean)
|
243 |
*/
|
244 |
public void setNew(boolean isNew){ |
245 |
this.isNew=isNew;
|
246 |
} |
247 |
} |