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 / DefaultEditableFeatureAttributeDescriptor.java @ 44190
History | View | Annotate | Download (10.9 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 | 41483 | jjdelcerro | import java.text.DateFormat; |
27 | 40435 | jjdelcerro | import java.util.HashMap; |
28 | 44189 | jjdelcerro | import java.util.Objects; |
29 | 44084 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
30 | 40435 | jjdelcerro | |
31 | import org.cresques.cts.IProjection; |
||
32 | 40964 | jldominguez | import org.slf4j.Logger; |
33 | import org.slf4j.LoggerFactory; |
||
34 | 40435 | jjdelcerro | |
35 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
36 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
37 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
38 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
39 | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
||
40 | 42303 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
41 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.type.GeometryType; |
42 | 44077 | jjdelcerro | import org.gvsig.timesupport.Interval; |
43 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
44 | 44189 | jjdelcerro | import org.gvsig.tools.dataTypes.DataType; |
45 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
46 | |||
47 | public class DefaultEditableFeatureAttributeDescriptor extends |
||
48 | DefaultFeatureAttributeDescriptor implements
|
||
49 | EditableFeatureAttributeDescriptor { |
||
50 | 40964 | jldominguez | |
51 | private static Logger logger = LoggerFactory.getLogger( |
||
52 | DefaultEditableFeatureAttributeDescriptor.class); |
||
53 | 40435 | jjdelcerro | |
54 | 44094 | jjdelcerro | private final DefaultFeatureAttributeDescriptor source; |
55 | 40435 | jjdelcerro | private boolean hasStrongChanges; |
56 | private String originalName = null; |
||
57 | |||
58 | protected DefaultEditableFeatureAttributeDescriptor(
|
||
59 | DefaultFeatureAttributeDescriptor other) { |
||
60 | super(other);
|
||
61 | if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
||
62 | DefaultEditableFeatureAttributeDescriptor other_edi = |
||
63 | (DefaultEditableFeatureAttributeDescriptor) other; |
||
64 | originalName = other_edi.getOriginalName(); |
||
65 | this.source = other_edi.getSource();
|
||
66 | } else {
|
||
67 | this.source = other;
|
||
68 | } |
||
69 | hasStrongChanges = false;
|
||
70 | } |
||
71 | |||
72 | 44190 | jjdelcerro | public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) { |
73 | 43739 | jjdelcerro | super(type);
|
74 | 40435 | jjdelcerro | this.source = null; |
75 | 44190 | jjdelcerro | hasStrongChanges = strongChanges; |
76 | 40435 | jjdelcerro | } |
77 | |||
78 | public DefaultFeatureAttributeDescriptor getSource() {
|
||
79 | return this.source; |
||
80 | } |
||
81 | 44094 | jjdelcerro | |
82 | 40435 | jjdelcerro | public void fixAll() { |
83 | 44094 | jjdelcerro | super.fixAll();
|
84 | 40435 | jjdelcerro | } |
85 | 44094 | jjdelcerro | |
86 | 40435 | jjdelcerro | public void checkIntegrity() throws AttributeFeatureTypeIntegrityException { |
87 | AttributeFeatureTypeIntegrityException ex = |
||
88 | new AttributeFeatureTypeIntegrityException(getName());
|
||
89 | if (this.size < 0) { |
||
90 | ex.add(new AttributeFeatureTypeSizeException(this.size)); |
||
91 | } |
||
92 | |||
93 | 40964 | jldominguez | if( this.dataType.isObject() && this.objectClass == null ) { |
94 | logger.warn("Incorrect data type object, objectClass is null.");
|
||
95 | ex.add(new AttributeFeatureTypeIntegrityException(this.name)); |
||
96 | } |
||
97 | |||
98 | // TODO: Add other integrity checks...
|
||
99 | 40435 | jjdelcerro | |
100 | if (ex.size() > 0) { |
||
101 | throw ex;
|
||
102 | } |
||
103 | } |
||
104 | |||
105 | public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
||
106 | 44189 | jjdelcerro | updateStrongChanges(this.allowNull, allowNull);
|
107 | 40435 | jjdelcerro | this.allowNull = allowNull;
|
108 | return this; |
||
109 | } |
||
110 | |||
111 | public EditableFeatureAttributeDescriptor setDataType(int type) { |
||
112 | 44189 | jjdelcerro | updateStrongChanges(this.dataType, type);
|
113 | 40435 | jjdelcerro | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
114 | return this; |
||
115 | } |
||
116 | |||
117 | public EditableFeatureAttributeDescriptor setDefaultValue(
|
||
118 | Object defaultValue) {
|
||
119 | 44189 | jjdelcerro | updateStrongChanges(this.defaultValue, defaultValue);
|
120 | 40435 | jjdelcerro | this.defaultValue = defaultValue;
|
121 | return this; |
||
122 | } |
||
123 | |||
124 | public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
||
125 | 44189 | jjdelcerro | updateStrongChanges(this.evaluator, evaluator);
|
126 | 40435 | jjdelcerro | this.evaluator = evaluator;
|
127 | return this; |
||
128 | } |
||
129 | |||
130 | 41335 | jjdelcerro | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
131 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
132 | return this; |
||
133 | } |
||
134 | |||
135 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
136 | this.geometryType = type;
|
||
137 | 42303 | jjdelcerro | if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) { |
138 | this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
||
139 | } |
||
140 | 40435 | jjdelcerro | this.geomType = null; |
141 | return this; |
||
142 | } |
||
143 | |||
144 | public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) { |
||
145 | this.geometrySubType = subType;
|
||
146 | this.geomType = null; |
||
147 | return this; |
||
148 | } |
||
149 | |||
150 | public EditableFeatureAttributeDescriptor setGeometryType(
|
||
151 | GeometryType geometryType) { |
||
152 | 44189 | jjdelcerro | updateStrongChanges(this.geomType, geometryType);
|
153 | 40435 | jjdelcerro | this.geomType = geometryType;
|
154 | this.geometryType = this.geomType.getType(); |
||
155 | this.geometrySubType = this.geomType.getSubType(); |
||
156 | return this; |
||
157 | } |
||
158 | |||
159 | 42716 | jjdelcerro | @Override
|
160 | public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) { |
||
161 | this.geometryType = type;
|
||
162 | this.geometrySubType = subType;
|
||
163 | this.geomType = null; |
||
164 | return this; |
||
165 | } |
||
166 | |||
167 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
168 | boolean isPrimaryKey) {
|
||
169 | 44189 | jjdelcerro | updateStrongChanges(this.primaryKey, primaryKey);
|
170 | 40435 | jjdelcerro | this.primaryKey = isPrimaryKey;
|
171 | return this; |
||
172 | } |
||
173 | |||
174 | public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
||
175 | 44189 | jjdelcerro | updateStrongChanges(this.readOnly, readOnly);
|
176 | 40435 | jjdelcerro | this.readOnly = isReadOnly;
|
177 | return this; |
||
178 | } |
||
179 | |||
180 | public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
||
181 | int maximumOccurrences) {
|
||
182 | 44189 | jjdelcerro | updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
183 | 40435 | jjdelcerro | this.maximumOccurrences = maximumOccurrences;
|
184 | return this; |
||
185 | } |
||
186 | |||
187 | public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
||
188 | int minimumOccurrences) {
|
||
189 | 44189 | jjdelcerro | updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
190 | 40435 | jjdelcerro | this.minimumOccurrences = minimumOccurrences;
|
191 | return this; |
||
192 | } |
||
193 | |||
194 | 43967 | jjdelcerro | @Override
|
195 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setName(String name) { |
196 | 44084 | jjdelcerro | if( StringUtils.equalsIgnoreCase(this.name, name) ) { |
197 | return this; |
||
198 | } |
||
199 | 40435 | jjdelcerro | if (originalName == null) { |
200 | originalName = this.name;
|
||
201 | 43967 | jjdelcerro | if (!isComputed()) {
|
202 | hasStrongChanges = true;
|
||
203 | } |
||
204 | 40435 | jjdelcerro | } |
205 | this.name = name;
|
||
206 | 43135 | jjdelcerro | if (!isComputed()) {
|
207 | 40435 | jjdelcerro | hasStrongChanges = true;
|
208 | } |
||
209 | return this; |
||
210 | } |
||
211 | |||
212 | public String getOriginalName() { |
||
213 | return originalName;
|
||
214 | } |
||
215 | |||
216 | public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
||
217 | 44189 | jjdelcerro | updateStrongChanges(this.objectClass, theClass);
|
218 | 40435 | jjdelcerro | this.objectClass = theClass;
|
219 | return this; |
||
220 | } |
||
221 | |||
222 | public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
||
223 | 44189 | jjdelcerro | updateStrongChanges(this.precision, precision);
|
224 | 40435 | jjdelcerro | this.precision = precision;
|
225 | return this; |
||
226 | } |
||
227 | |||
228 | public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
||
229 | 44189 | jjdelcerro | updateStrongChanges(this.SRS, SRS);
|
230 | 40435 | jjdelcerro | this.SRS = SRS;
|
231 | return this; |
||
232 | } |
||
233 | |||
234 | 44077 | jjdelcerro | public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
235 | 44189 | jjdelcerro | updateStrongChanges(this.getInterval(), interval);
|
236 | 44094 | jjdelcerro | super.setInterval(interval);
|
237 | 44077 | jjdelcerro | return this; |
238 | } |
||
239 | |||
240 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setSize(int size) { |
241 | 44189 | jjdelcerro | updateStrongChanges(this.size, size);
|
242 | 40435 | jjdelcerro | this.size = size;
|
243 | return this; |
||
244 | } |
||
245 | |||
246 | public boolean hasStrongChanges() { |
||
247 | return hasStrongChanges;
|
||
248 | } |
||
249 | |||
250 | public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
||
251 | String infoName, Object value) { |
||
252 | if (this.additionalInfo == null) { |
||
253 | this.additionalInfo = new HashMap(); |
||
254 | } |
||
255 | this.additionalInfo.put(infoName, value);
|
||
256 | return this; |
||
257 | } |
||
258 | |||
259 | public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
||
260 | this.isAutomatic = isAutomatic;
|
||
261 | 43362 | jjdelcerro | if( isAutomatic ) {
|
262 | this.setHidden(true); |
||
263 | } |
||
264 | 40435 | jjdelcerro | return this; |
265 | } |
||
266 | |||
267 | 41483 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
268 | 44189 | jjdelcerro | updateStrongChanges(this.isTime, isTime);
|
269 | 43135 | jjdelcerro | this.isTime = isTime;
|
270 | return this; |
||
271 | 41483 | jjdelcerro | } |
272 | |||
273 | public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
||
274 | this.dateFormat = dateFormat;
|
||
275 | return this; |
||
276 | } |
||
277 | 41638 | jjdelcerro | |
278 | public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
||
279 | 44189 | jjdelcerro | updateStrongChanges(this.indexed, isIndexed);
|
280 | 41638 | jjdelcerro | this.indexed = isIndexed;
|
281 | return this; |
||
282 | } |
||
283 | 41483 | jjdelcerro | |
284 | 41638 | jjdelcerro | public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
285 | 44189 | jjdelcerro | updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
286 | 41638 | jjdelcerro | this.allowIndexDuplicateds = allowDuplicateds;
|
287 | return this; |
||
288 | } |
||
289 | |||
290 | public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
||
291 | 44189 | jjdelcerro | updateStrongChanges(this.isIndexAscending, ascending);
|
292 | 41638 | jjdelcerro | this.isIndexAscending = ascending;
|
293 | return this; |
||
294 | } |
||
295 | 44128 | jjdelcerro | |
296 | @Override
|
||
297 | public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
||
298 | super.setDataProfileName(dataProfile);
|
||
299 | return this; |
||
300 | } |
||
301 | 44189 | jjdelcerro | |
302 | private void updateStrongChanges(int previous, int newvalue) { |
||
303 | if( isComputed() ) {
|
||
304 | return;
|
||
305 | } |
||
306 | if( previous == newvalue ) {
|
||
307 | return;
|
||
308 | } |
||
309 | this.hasStrongChanges = true; |
||
310 | } |
||
311 | |||
312 | private void updateStrongChanges(DataType previous, int newvalue) { |
||
313 | if( isComputed() ) {
|
||
314 | return;
|
||
315 | } |
||
316 | if( previous!=null ) { |
||
317 | if( previous.getType() == newvalue ) {
|
||
318 | return;
|
||
319 | } |
||
320 | } |
||
321 | this.hasStrongChanges = true; |
||
322 | } |
||
323 | |||
324 | private void updateStrongChanges(boolean previous, boolean newvalue) { |
||
325 | if( isComputed() ) {
|
||
326 | return;
|
||
327 | } |
||
328 | if( previous == newvalue ) {
|
||
329 | return;
|
||
330 | } |
||
331 | this.hasStrongChanges = true; |
||
332 | } |
||
333 | |||
334 | private void updateStrongChanges(Object previous, Object newvalue) { |
||
335 | if( isComputed() ) {
|
||
336 | return;
|
||
337 | } |
||
338 | if( Objects.equals(newvalue, previous) ) {
|
||
339 | return;
|
||
340 | } |
||
341 | this.hasStrongChanges = true; |
||
342 | } |
||
343 | 40435 | jjdelcerro | } |