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