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