Statistics
| Revision:

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 @ 43739

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