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