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

History | View | Annotate | Download (9.41 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.exception.AttributeFeatureTypeIntegrityException;
36
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.type.GeometryType;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.evaluator.Evaluator;
41

    
42
public class DefaultEditableFeatureAttributeDescriptor extends
43
    DefaultFeatureAttributeDescriptor implements
44
    EditableFeatureAttributeDescriptor {
45
    
46
    private static Logger logger = LoggerFactory.getLogger(
47
        DefaultEditableFeatureAttributeDescriptor.class);
48

    
49
    private DefaultFeatureAttributeDescriptor source;
50
    private boolean hasStrongChanges;
51
    private String originalName = null;
52

    
53
    protected DefaultEditableFeatureAttributeDescriptor(
54
        DefaultFeatureAttributeDescriptor other) {
55
        super(other);
56
        if (other instanceof DefaultEditableFeatureAttributeDescriptor) {
57
            DefaultEditableFeatureAttributeDescriptor other_edi =
58
                (DefaultEditableFeatureAttributeDescriptor) other;
59
            originalName = other_edi.getOriginalName();
60
            this.source = other_edi.getSource();
61
        } else {
62
            this.source = other;
63
        }
64
        hasStrongChanges = false;
65
    }
66

    
67
    public DefaultEditableFeatureAttributeDescriptor() {
68
        super();
69
        this.source = null;
70
        hasStrongChanges = false;
71
    }
72

    
73
    public DefaultFeatureAttributeDescriptor getSource() {
74
        return this.source;
75
    }
76

    
77
    public void fixAll() {
78
    }
79

    
80
    public void checkIntegrity() throws AttributeFeatureTypeIntegrityException {
81
        AttributeFeatureTypeIntegrityException ex =
82
            new AttributeFeatureTypeIntegrityException(getName());
83
        if (this.size < 0) {
84
            ex.add(new AttributeFeatureTypeSizeException(this.size));
85
        }
86

    
87
        if( this.dataType.isObject() && this.objectClass == null ) {
88
            logger.warn("Incorrect data type object, objectClass is null.");
89
            ex.add(new AttributeFeatureTypeIntegrityException(this.name));
90
        }
91
        
92
        // TODO: Add other integrity checks...
93

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

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

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

    
115
    public EditableFeatureAttributeDescriptor setDefaultValue(
116
        Object defaultValue) {
117
        this.defaultValue = defaultValue;
118
        if (!isComputed()) {
119
            hasStrongChanges = true;
120
        }
121
        return this;
122
    }
123

    
124
    public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
125
        if (this.evaluator != null && evaluator == null) {
126
            hasStrongChanges = true;
127
        }
128
        this.evaluator = evaluator;
129
        return this;
130
    }
131

    
132
    public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
133
        this.featureAttributeEmulator = featureAttributeEmulator;
134
        return this;
135
    }
136
        
137
    public EditableFeatureAttributeDescriptor setGeometryType(int type) {
138
        this.geometryType = type;
139
        if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) {
140
            this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
141
        }
142
        this.geomType = null;
143
        return this;
144
    }
145

    
146
    public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) {
147
        this.geometrySubType = subType;
148
        this.geomType = null;
149
        return this;
150
    }
151

    
152
    public EditableFeatureAttributeDescriptor setGeometryType(
153
        GeometryType geometryType) {
154
        this.geomType = geometryType;
155
        this.geometryType = this.geomType.getType();
156
        this.geometrySubType = this.geomType.getSubType();
157
        if (!isComputed()) {
158
            hasStrongChanges = true;
159
        }
160
        return this;
161
    }
162

    
163
    @Override
164
    public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) {
165
        this.geometryType = type;
166
        this.geometrySubType = subType;
167
        this.geomType = null;
168
        return this;
169
    }
170

    
171
    public EditableFeatureAttributeDescriptor setIsPrimaryKey(
172
        boolean isPrimaryKey) {
173
        this.primaryKey = isPrimaryKey;
174
        if (!isComputed()) {
175
            hasStrongChanges = true;
176
        }
177
        return this;
178
    }
179

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

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

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

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

    
222
    public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) {
223
        this.objectClass = theClass;
224
        if (!isComputed()) {
225
            hasStrongChanges = true;
226
        }
227
        return this;
228
    }
229

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

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

    
246
    public EditableFeatureAttributeDescriptor setSize(int size) {
247
        this.size = size;
248
        if (!isComputed()) {
249
            hasStrongChanges = true;
250
        }
251
        return this;
252
    }
253

    
254
    public boolean hasStrongChanges() {
255
        return hasStrongChanges;
256
    }
257

    
258
    public EditableFeatureAttributeDescriptor setAdditionalInfo(
259
        String infoName, Object value) {
260
        if (this.additionalInfo == null) {
261
            this.additionalInfo = new HashMap();
262
        }
263
        this.additionalInfo.put(infoName, value);
264
        return this;
265
    }
266

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

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

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

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