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
/**
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
    public EditableFeatureAttributeDescriptor setName(String name) {
208
        if (originalName == null) {
209
            originalName = this.name;
210
            hasStrongChanges = true;
211
        }
212
        this.name = name;
213
        if (!isComputed()) {
214
            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
        if (!isComputed()) {
226
            hasStrongChanges = true;
227
        }
228
        return this;
229
    }
230

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

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

    
247
    public EditableFeatureAttributeDescriptor setSize(int size) {
248
        this.size = size;
249
        if (!isComputed()) {
250
            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
        if( isAutomatic ) {
271
            this.setHidden(true);
272
        }
273
        return this;
274
    }
275
    
276
    public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) {
277
        this.isTime = isTime;
278
        if (!isComputed()) {
279
            hasStrongChanges = true;
280
        }
281
        return this;
282
    }
283

    
284
    public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) {
285
        this.dateFormat = dateFormat;
286
        return this;
287
    }
288

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

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