svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultEditableFeature.java @ 44297
History | View | Annotate | Download (10.4 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.impl; |
25 |
|
26 |
import java.util.Date; |
27 |
import java.util.Iterator; |
28 |
|
29 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
30 |
import org.gvsig.fmap.dal.feature.Feature; |
31 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
32 |
import org.gvsig.fmap.dal.feature.FeatureType; |
33 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.timesupport.Instant; |
36 |
import org.gvsig.timesupport.Interval; |
37 |
|
38 |
public class DefaultEditableFeature extends DefaultFeature implements |
39 |
EditableFeature { |
40 |
|
41 |
private DefaultFeature source;
|
42 |
|
43 |
protected DefaultEditableFeature(DefaultFeature feature) {
|
44 |
super(feature);
|
45 |
this.source = feature;
|
46 |
} |
47 |
|
48 |
protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
49 |
super(feature);
|
50 |
this.source = (DefaultFeature) feature.getSource();
|
51 |
} |
52 |
|
53 |
public DefaultEditableFeature(DefaultFeatureStore store, FeatureProvider data) {
|
54 |
// Se trata de un editable feature sobre una ya existente
|
55 |
super(store, data);
|
56 |
this.source = null; |
57 |
} |
58 |
|
59 |
public Feature getSource() {
|
60 |
return this.source; |
61 |
} |
62 |
|
63 |
public EditableFeature getEditable() {
|
64 |
return this; |
65 |
} |
66 |
|
67 |
public Feature getCopy() {
|
68 |
return new DefaultEditableFeature(this); |
69 |
} |
70 |
|
71 |
public Feature getNotEditableCopy() {
|
72 |
return new DefaultFeature(this); |
73 |
} |
74 |
|
75 |
public void setDefaultGeometry(Geometry geometry) { |
76 |
FeatureAttributeDescriptor attribute = this.getType()
|
77 |
.getAttributeDescriptor( |
78 |
this.getType().getDefaultGeometryAttributeIndex());
|
79 |
this.set(attribute, geometry);
|
80 |
} |
81 |
|
82 |
public void set(String name, Object value) { |
83 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
84 |
if ( attribute == null ) { |
85 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
86 |
} |
87 |
this.set(attribute, value);
|
88 |
} |
89 |
|
90 |
public void set(int index, Object value) { |
91 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
92 |
this.set(attribute, value);
|
93 |
} |
94 |
|
95 |
public void setArray(String name, Object[] value) { |
96 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
97 |
if ( attribute == null ) { |
98 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
99 |
} |
100 |
this.set(attribute, value);
|
101 |
} |
102 |
|
103 |
public void setArray(int index, Object[] value) { |
104 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
105 |
this.set(attribute, value);
|
106 |
} |
107 |
|
108 |
public void setBoolean(String name, boolean value) { |
109 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
110 |
if ( attribute == null ) { |
111 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
112 |
} |
113 |
this.set(attribute, Boolean.valueOf(value)); |
114 |
} |
115 |
|
116 |
public void setBoolean(int index, boolean value) { |
117 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
118 |
this.set(attribute, Boolean.valueOf(value)); |
119 |
} |
120 |
|
121 |
public void setByte(String name, byte value) { |
122 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
123 |
if ( attribute == null ) { |
124 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
125 |
} |
126 |
this.set(attribute, new Byte(value)); |
127 |
} |
128 |
|
129 |
public void setByte(int index, byte value) { |
130 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
131 |
this.set(attribute, new Byte(value)); |
132 |
} |
133 |
|
134 |
public void setDate(String name, Date value) { |
135 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
136 |
if ( attribute == null ) { |
137 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
138 |
} |
139 |
this.set(attribute, value);
|
140 |
} |
141 |
|
142 |
public void setDate(int index, Date value) { |
143 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
144 |
this.set(attribute, value);
|
145 |
} |
146 |
|
147 |
public void setDouble(String name, double value) { |
148 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
149 |
if ( attribute == null ) { |
150 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
151 |
} |
152 |
this.set(attribute, new Double(value)); |
153 |
} |
154 |
|
155 |
public void setDouble(int index, double value) { |
156 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
157 |
this.set(attribute, new Double(value)); |
158 |
} |
159 |
|
160 |
public void setFeature(String name, Feature value) { |
161 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
162 |
if ( attribute == null ) { |
163 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
164 |
} |
165 |
this.set(attribute, value);
|
166 |
} |
167 |
|
168 |
public void setFeature(int index, Feature value) { |
169 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
170 |
this.set(attribute, value);
|
171 |
} |
172 |
|
173 |
public void setFloat(String name, float value) { |
174 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
175 |
if ( attribute == null ) { |
176 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
177 |
} |
178 |
this.set(attribute, new Float(value)); |
179 |
} |
180 |
|
181 |
public void setFloat(int index, float value) { |
182 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
183 |
this.set(attribute, new Float(value)); |
184 |
} |
185 |
|
186 |
public void setGeometry(String name, Geometry value) { |
187 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
188 |
if ( attribute == null ) { |
189 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
190 |
} |
191 |
this.set(attribute, value);
|
192 |
} |
193 |
|
194 |
public void setGeometry(int index, Geometry value) { |
195 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
196 |
this.set(attribute, value);
|
197 |
} |
198 |
|
199 |
public void setInt(String name, int value) { |
200 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
201 |
if ( attribute == null ) { |
202 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
203 |
} |
204 |
this.set(attribute, new Integer(value)); |
205 |
} |
206 |
|
207 |
public void setInt(int index, int value) { |
208 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
209 |
this.set(attribute, new Integer(value)); |
210 |
} |
211 |
|
212 |
public void setLong(String name, long value) { |
213 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
214 |
if ( attribute == null ) { |
215 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
216 |
} |
217 |
this.set(attribute, new Long(value)); |
218 |
} |
219 |
|
220 |
public void setLong(int index, long value) { |
221 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
222 |
this.set(attribute, new Long(value)); |
223 |
} |
224 |
|
225 |
public void setString(String name, String value) { |
226 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
227 |
if ( attribute == null ) { |
228 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
229 |
} |
230 |
this.set(attribute, value);
|
231 |
} |
232 |
|
233 |
public void setString(int index, String value) { |
234 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
235 |
this.set(attribute, value);
|
236 |
} |
237 |
|
238 |
public void copyFrom(Feature source) { |
239 |
// iterate over the attributes and copy one by one
|
240 |
FeatureType sourceType = source.getType(); |
241 |
Iterator it = this.getType().iterator(); |
242 |
while ( it.hasNext() ) {
|
243 |
FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) it.next(); |
244 |
if( sourceType.get(attr.getName())!=null ) { |
245 |
set(attr.getIndex(), source.get(attr.getName())); |
246 |
} |
247 |
} |
248 |
} |
249 |
|
250 |
public void setInstant(String name, Instant value) { |
251 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
252 |
if ( attribute == null ) { |
253 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
254 |
} |
255 |
this.set(attribute, value);
|
256 |
} |
257 |
|
258 |
public void setInstant(int index, Instant value) { |
259 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
260 |
this.set(attribute, value);
|
261 |
} |
262 |
|
263 |
public void setInterval(String name, Interval value) { |
264 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
265 |
if ( attribute == null ) { |
266 |
throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
267 |
} |
268 |
this.set(attribute, value);
|
269 |
} |
270 |
|
271 |
public void setInterval(int index, Interval value) { |
272 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
273 |
this.set(attribute, value);
|
274 |
} |
275 |
} |