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