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