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

History | View | Annotate | Download (9.54 KB)

1
/**
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
package org.gvsig.fmap.dal.feature.impl;
25

    
26
import java.text.DateFormat;
27
import java.util.HashMap;
28

    
29
import org.cresques.cts.IProjection;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
34
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException;
37
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException;
38
import org.gvsig.fmap.geom.Geometry;
39
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
    
47
    private static Logger logger = LoggerFactory.getLogger(
48
        DefaultEditableFeatureAttributeDescriptor.class);
49

    
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
    public DefaultEditableFeatureAttributeDescriptor(FeatureType type) {
69
        super(type);
70
        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
        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

    
95
        if (ex.size() > 0) {
96
            throw ex;
97
        }
98
    }
99

    
100
    public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) {
101
        this.allowNull = allowNull;
102
        if (!isComputed()) {
103
            hasStrongChanges = true;
104
        }
105
        return this;
106
    }
107

    
108
    public EditableFeatureAttributeDescriptor setDataType(int type) {
109
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
110
        if (!isComputed()) {
111
            hasStrongChanges = true;
112
        }
113
        return this;
114
    }
115

    
116
    public EditableFeatureAttributeDescriptor setDefaultValue(
117
        Object defaultValue) {
118
        this.defaultValue = defaultValue;
119
        if (!isComputed()) {
120
            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
    public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
134
        this.featureAttributeEmulator = featureAttributeEmulator;
135
        return this;
136
    }
137
        
138
    public EditableFeatureAttributeDescriptor setGeometryType(int type) {
139
        this.geometryType = type;
140
        if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) {
141
            this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
142
        }
143
        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
        if (!isComputed()) {
159
            hasStrongChanges = true;
160
        }
161
        return this;
162
    }
163

    
164
    @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
    public EditableFeatureAttributeDescriptor setIsPrimaryKey(
173
        boolean isPrimaryKey) {
174
        this.primaryKey = isPrimaryKey;
175
        if (!isComputed()) {
176
            hasStrongChanges = true;
177
        }
178
        return this;
179
    }
180

    
181
    public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) {
182
        this.readOnly = isReadOnly;
183
        if (!isComputed()) {
184
            hasStrongChanges = true;
185
        }
186
        return this;
187
    }
188

    
189
    public EditableFeatureAttributeDescriptor setMaximumOccurrences(
190
        int maximumOccurrences) {
191
        this.maximumOccurrences = maximumOccurrences;
192
        if (!isComputed()) {
193
            hasStrongChanges = true;
194
        }
195
        return this;
196
    }
197

    
198
    public EditableFeatureAttributeDescriptor setMinimumOccurrences(
199
        int minimumOccurrences) {
200
        this.minimumOccurrences = minimumOccurrences;
201
        if (!isComputed()) {
202
            hasStrongChanges = true;
203
        }
204
        return this;
205
    }
206

    
207
    @Override
208
    public EditableFeatureAttributeDescriptor setName(String name) {
209
        if (originalName == null) {
210
            originalName = this.name;
211
            if (!isComputed()) {
212
                hasStrongChanges = true;
213
            }
214
        }
215
        this.name = name;
216
        if (!isComputed()) {
217
            hasStrongChanges = true;
218
        }
219
        return this;
220
    }
221
    
222
    public String getOriginalName() {
223
        return originalName;
224
    }
225

    
226
    public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) {
227
        this.objectClass = theClass;
228
        if (!isComputed()) {
229
            hasStrongChanges = true;
230
        }
231
        return this;
232
    }
233

    
234
    public EditableFeatureAttributeDescriptor setPrecision(int precision) {
235
        this.precision = precision;
236
        if (!isComputed()) {
237
            hasStrongChanges = true;
238
        }
239
        return this;
240
    }
241

    
242
    public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
243
        this.SRS = SRS;
244
        if (!isComputed()) {
245
            hasStrongChanges = true;
246
        }
247
        return this;
248
    }
249

    
250
    public EditableFeatureAttributeDescriptor setSize(int size) {
251
        this.size = size;
252
        if (!isComputed()) {
253
            hasStrongChanges = true;
254
        }
255
        return this;
256
    }
257

    
258
    public boolean hasStrongChanges() {
259
        return hasStrongChanges;
260
    }
261

    
262
    public EditableFeatureAttributeDescriptor setAdditionalInfo(
263
        String infoName, Object value) {
264
        if (this.additionalInfo == null) {
265
            this.additionalInfo = new HashMap();
266
        }
267
        this.additionalInfo.put(infoName, value);
268
        return this;
269
    }
270

    
271
    public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) {
272
        this.isAutomatic = isAutomatic;
273
        if( isAutomatic ) {
274
            this.setHidden(true);
275
        }
276
        return this;
277
    }
278
    
279
    public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) {
280
        this.isTime = isTime;
281
        if (!isComputed()) {
282
            hasStrongChanges = true;
283
        }
284
        return this;
285
    }
286

    
287
    public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) {
288
        this.dateFormat = dateFormat;
289
        return this;
290
    }
291

    
292
    public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) {
293
        this.indexed = isIndexed;
294
        if (!isComputed()) {
295
            hasStrongChanges = true;
296
        }
297
        return this;
298
    }
299
    
300
    public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) {
301
        this.allowIndexDuplicateds = allowDuplicateds;
302
        if (!isComputed()) {
303
            hasStrongChanges = true;
304
        }
305
        return this;
306
    }
307

    
308
    public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) {
309
        this.isIndexAscending = ascending;
310
        if (!isComputed()) {
311
            hasStrongChanges = true;
312
        }
313
        return this;
314
    }
315
    
316
}