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 @ 42795
History | View | Annotate | Download (10.3 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 41805 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 40559 | jjdelcerro | * 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 | 41805 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | 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 | 41805 | jjdelcerro | EditableFeature { |
39 | 40435 | jjdelcerro | |
40 | 41805 | jjdelcerro | private DefaultFeature source;
|
41 | 40435 | jjdelcerro | |
42 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultFeature feature) {
|
43 | super(feature);
|
||
44 | this.source = feature;
|
||
45 | } |
||
46 | 40435 | jjdelcerro | |
47 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
48 | super(feature);
|
||
49 | this.source = (DefaultFeature) feature.getSource();
|
||
50 | } |
||
51 | 40435 | jjdelcerro | |
52 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
58 | 41805 | jjdelcerro | public Feature getSource() {
|
59 | return this.source; |
||
60 | } |
||
61 | 40435 | jjdelcerro | |
62 | 41805 | jjdelcerro | public EditableFeature getEditable() {
|
63 | return this; |
||
64 | } |
||
65 | 40435 | jjdelcerro | |
66 | 41805 | jjdelcerro | public Feature getCopy() {
|
67 | return new DefaultEditableFeature(this); |
||
68 | } |
||
69 | 40435 | jjdelcerro | |
70 | 41805 | jjdelcerro | public Feature getNotEditableCopy() {
|
71 | return new DefaultFeature(this); |
||
72 | } |
||
73 | 40435 | jjdelcerro | |
74 | 41805 | jjdelcerro | public void setDefaultGeometry(Geometry geometry) { |
75 | FeatureAttributeDescriptor attribute = this.getType()
|
||
76 | .getAttributeDescriptor( |
||
77 | this.getType().getDefaultGeometryAttributeIndex());
|
||
78 | this.set(attribute, geometry);
|
||
79 | } |
||
80 | 40435 | jjdelcerro | |
81 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
89 | 41805 | jjdelcerro | public void set(int index, Object value) { |
90 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
91 | this.set(attribute, value);
|
||
92 | } |
||
93 | 40435 | jjdelcerro | |
94 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
102 | 41805 | jjdelcerro | public void setArray(int index, Object[] value) { |
103 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
104 | this.set(attribute, value);
|
||
105 | } |
||
106 | 40435 | jjdelcerro | |
107 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
115 | 41805 | jjdelcerro | public void setBoolean(int index, boolean value) { |
116 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
117 | this.set(attribute, Boolean.valueOf(value)); |
||
118 | } |
||
119 | 40435 | jjdelcerro | |
120 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
128 | 41805 | jjdelcerro | public void setByte(int index, byte value) { |
129 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
130 | this.set(attribute, new Byte(value)); |
||
131 | } |
||
132 | 40435 | jjdelcerro | |
133 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
141 | 41805 | jjdelcerro | public void setDate(int index, Date value) { |
142 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
143 | this.set(attribute, value);
|
||
144 | } |
||
145 | 40435 | jjdelcerro | |
146 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
154 | 41805 | jjdelcerro | public void setDouble(int index, double value) { |
155 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
156 | this.set(attribute, new Double(value)); |
||
157 | } |
||
158 | 40435 | jjdelcerro | |
159 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
167 | 41805 | jjdelcerro | public void setFeature(int index, Feature value) { |
168 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
169 | this.set(attribute, value);
|
||
170 | } |
||
171 | 40435 | jjdelcerro | |
172 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
180 | 41805 | jjdelcerro | public void setFloat(int index, float value) { |
181 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
182 | this.set(attribute, new Float(value)); |
||
183 | } |
||
184 | 40435 | jjdelcerro | |
185 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
193 | 41805 | jjdelcerro | public void setGeometry(int index, Geometry value) { |
194 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
195 | this.set(attribute, value);
|
||
196 | } |
||
197 | 40435 | jjdelcerro | |
198 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
206 | 41805 | jjdelcerro | public void setInt(int index, int value) { |
207 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
208 | this.set(attribute, new Integer(value)); |
||
209 | } |
||
210 | 40435 | jjdelcerro | |
211 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
219 | 41805 | jjdelcerro | public void setLong(int index, long value) { |
220 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
221 | this.set(attribute, new Long(value)); |
||
222 | } |
||
223 | 40435 | jjdelcerro | |
224 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
232 | 41805 | jjdelcerro | public void setString(int index, String value) { |
233 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
234 | this.set(attribute, value);
|
||
235 | } |
||
236 | 40435 | jjdelcerro | |
237 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
246 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
254 | 41805 | jjdelcerro | public void setInstant(int index, Instant value) { |
255 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
256 | this.set(attribute, value);
|
||
257 | } |
||
258 | 40435 | jjdelcerro | |
259 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
267 | 41805 | jjdelcerro | public void setInterval(int index, Interval value) { |
268 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
269 | this.set(attribute, value);
|
||
270 | } |
||
271 | 40435 | jjdelcerro | } |