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 @ 43983
History | View | Annotate | Download (10.4 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 | 43562 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
33 | 40435 | jjdelcerro | 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 | 41805 | jjdelcerro | EditableFeature { |
40 | 40435 | jjdelcerro | |
41 | 41805 | jjdelcerro | private DefaultFeature source;
|
42 | 40435 | jjdelcerro | |
43 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultFeature feature) {
|
44 | super(feature);
|
||
45 | this.source = feature;
|
||
46 | } |
||
47 | 40435 | jjdelcerro | |
48 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
49 | super(feature);
|
||
50 | this.source = (DefaultFeature) feature.getSource();
|
||
51 | } |
||
52 | 40435 | jjdelcerro | |
53 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
59 | 41805 | jjdelcerro | public Feature getSource() {
|
60 | return this.source; |
||
61 | } |
||
62 | 40435 | jjdelcerro | |
63 | 41805 | jjdelcerro | public EditableFeature getEditable() {
|
64 | return this; |
||
65 | } |
||
66 | 40435 | jjdelcerro | |
67 | 41805 | jjdelcerro | public Feature getCopy() {
|
68 | return new DefaultEditableFeature(this); |
||
69 | } |
||
70 | 40435 | jjdelcerro | |
71 | 41805 | jjdelcerro | public Feature getNotEditableCopy() {
|
72 | return new DefaultFeature(this); |
||
73 | } |
||
74 | 40435 | jjdelcerro | |
75 | 41805 | jjdelcerro | public void setDefaultGeometry(Geometry geometry) { |
76 | FeatureAttributeDescriptor attribute = this.getType()
|
||
77 | .getAttributeDescriptor( |
||
78 | this.getType().getDefaultGeometryAttributeIndex());
|
||
79 | this.set(attribute, geometry);
|
||
80 | } |
||
81 | 40435 | jjdelcerro | |
82 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
90 | 41805 | jjdelcerro | public void set(int index, Object value) { |
91 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
92 | this.set(attribute, value);
|
||
93 | } |
||
94 | 40435 | jjdelcerro | |
95 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
103 | 41805 | jjdelcerro | public void setArray(int index, Object[] value) { |
104 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
105 | this.set(attribute, value);
|
||
106 | } |
||
107 | 40435 | jjdelcerro | |
108 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
116 | 41805 | jjdelcerro | public void setBoolean(int index, boolean value) { |
117 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
118 | this.set(attribute, Boolean.valueOf(value)); |
||
119 | } |
||
120 | 40435 | jjdelcerro | |
121 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
129 | 41805 | jjdelcerro | public void setByte(int index, byte value) { |
130 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
131 | this.set(attribute, new Byte(value)); |
||
132 | } |
||
133 | 40435 | jjdelcerro | |
134 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
142 | 41805 | jjdelcerro | public void setDate(int index, Date value) { |
143 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
144 | this.set(attribute, value);
|
||
145 | } |
||
146 | 40435 | jjdelcerro | |
147 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
155 | 41805 | jjdelcerro | public void setDouble(int index, double value) { |
156 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
157 | this.set(attribute, new Double(value)); |
||
158 | } |
||
159 | 40435 | jjdelcerro | |
160 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
168 | 41805 | jjdelcerro | public void setFeature(int index, Feature value) { |
169 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
170 | this.set(attribute, value);
|
||
171 | } |
||
172 | 40435 | jjdelcerro | |
173 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
181 | 41805 | jjdelcerro | public void setFloat(int index, float value) { |
182 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
183 | this.set(attribute, new Float(value)); |
||
184 | } |
||
185 | 40435 | jjdelcerro | |
186 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
194 | 41805 | jjdelcerro | public void setGeometry(int index, Geometry value) { |
195 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
196 | this.set(attribute, value);
|
||
197 | } |
||
198 | 40435 | jjdelcerro | |
199 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
207 | 41805 | jjdelcerro | public void setInt(int index, int value) { |
208 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
209 | this.set(attribute, new Integer(value)); |
||
210 | } |
||
211 | 40435 | jjdelcerro | |
212 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
220 | 41805 | jjdelcerro | public void setLong(int index, long value) { |
221 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
222 | this.set(attribute, new Long(value)); |
||
223 | } |
||
224 | 40435 | jjdelcerro | |
225 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
233 | 41805 | jjdelcerro | public void setString(int index, String value) { |
234 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
235 | this.set(attribute, value);
|
||
236 | } |
||
237 | 40435 | jjdelcerro | |
238 | 41805 | jjdelcerro | public void copyFrom(Feature source) { |
239 | // iterate over the attributes and copy one by one
|
||
240 | 43562 | jjdelcerro | FeatureType sourceType = source.getType(); |
241 | 41805 | jjdelcerro | Iterator it = this.getType().iterator(); |
242 | while ( it.hasNext() ) {
|
||
243 | FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) it.next(); |
||
244 | 43562 | jjdelcerro | if( sourceType.get(attr.getName())!=null ) { |
245 | set(attr.getIndex(), source.get(attr.getName())); |
||
246 | } |
||
247 | 41805 | jjdelcerro | } |
248 | } |
||
249 | 40435 | jjdelcerro | |
250 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
258 | 41805 | jjdelcerro | public void setInstant(int index, Instant value) { |
259 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
260 | this.set(attribute, value);
|
||
261 | } |
||
262 | 40435 | jjdelcerro | |
263 | 41805 | jjdelcerro | 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 | 40435 | jjdelcerro | |
271 | 41805 | jjdelcerro | public void setInterval(int index, Interval value) { |
272 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
273 | this.set(attribute, value);
|
||
274 | } |
||
275 | 40435 | jjdelcerro | } |