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 @ 42303
History | View | Annotate | Download (9.02 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 (this.evaluator != null) { |
102 |
hasStrongChanges = true;
|
103 |
} |
104 |
return this; |
105 |
} |
106 |
|
107 |
public EditableFeatureAttributeDescriptor setDataType(int type) { |
108 |
this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
109 |
if (this.evaluator != null) { |
110 |
hasStrongChanges = true;
|
111 |
} |
112 |
return this; |
113 |
} |
114 |
|
115 |
public EditableFeatureAttributeDescriptor setDefaultValue(
|
116 |
Object defaultValue) {
|
117 |
this.defaultValue = defaultValue;
|
118 |
if (this.evaluator != null) { |
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 (this.evaluator != null) { |
158 |
hasStrongChanges = true;
|
159 |
} |
160 |
return this; |
161 |
} |
162 |
|
163 |
public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
164 |
boolean isPrimaryKey) {
|
165 |
this.primaryKey = isPrimaryKey;
|
166 |
if (this.evaluator != null) { |
167 |
hasStrongChanges = true;
|
168 |
} |
169 |
return this; |
170 |
} |
171 |
|
172 |
public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
173 |
this.readOnly = isReadOnly;
|
174 |
if (this.evaluator != null) { |
175 |
hasStrongChanges = true;
|
176 |
} |
177 |
return this; |
178 |
} |
179 |
|
180 |
public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
181 |
int maximumOccurrences) {
|
182 |
this.maximumOccurrences = maximumOccurrences;
|
183 |
if (this.evaluator != null) { |
184 |
hasStrongChanges = true;
|
185 |
} |
186 |
return this; |
187 |
} |
188 |
|
189 |
public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
190 |
int minimumOccurrences) {
|
191 |
this.minimumOccurrences = minimumOccurrences;
|
192 |
if (this.evaluator != null) { |
193 |
hasStrongChanges = true;
|
194 |
} |
195 |
return this; |
196 |
} |
197 |
|
198 |
public EditableFeatureAttributeDescriptor setName(String name) { |
199 |
if (originalName == null) { |
200 |
originalName = this.name;
|
201 |
hasStrongChanges = true;
|
202 |
} |
203 |
this.name = name;
|
204 |
if (this.evaluator != null) { |
205 |
hasStrongChanges = true;
|
206 |
} |
207 |
return this; |
208 |
} |
209 |
|
210 |
public String getOriginalName() { |
211 |
return originalName;
|
212 |
} |
213 |
|
214 |
public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
215 |
this.objectClass = theClass;
|
216 |
if (this.evaluator != null) { |
217 |
hasStrongChanges = true;
|
218 |
} |
219 |
return this; |
220 |
} |
221 |
|
222 |
public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
223 |
this.precision = precision;
|
224 |
if (this.evaluator != null) { |
225 |
hasStrongChanges = true;
|
226 |
} |
227 |
return this; |
228 |
} |
229 |
|
230 |
public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
231 |
this.SRS = SRS;
|
232 |
if (this.evaluator != null) { |
233 |
hasStrongChanges = true;
|
234 |
} |
235 |
return this; |
236 |
} |
237 |
|
238 |
public EditableFeatureAttributeDescriptor setSize(int size) { |
239 |
this.size = size;
|
240 |
if (this.evaluator != null) { |
241 |
hasStrongChanges = true;
|
242 |
} |
243 |
return this; |
244 |
} |
245 |
|
246 |
public boolean hasStrongChanges() { |
247 |
return hasStrongChanges;
|
248 |
} |
249 |
|
250 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
251 |
String infoName, Object value) { |
252 |
if (this.additionalInfo == null) { |
253 |
this.additionalInfo = new HashMap(); |
254 |
} |
255 |
this.additionalInfo.put(infoName, value);
|
256 |
return this; |
257 |
} |
258 |
|
259 |
public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
260 |
this.isAutomatic = isAutomatic;
|
261 |
return this; |
262 |
} |
263 |
|
264 |
public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
265 |
this.isTime = isTime;
|
266 |
if( this.evaluator != null ) { |
267 |
hasStrongChanges=true;
|
268 |
} |
269 |
return this; |
270 |
} |
271 |
|
272 |
public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
273 |
this.dateFormat = dateFormat;
|
274 |
return this; |
275 |
} |
276 |
|
277 |
public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
278 |
this.indexed = isIndexed;
|
279 |
return this; |
280 |
} |
281 |
|
282 |
public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
283 |
this.allowIndexDuplicateds = allowDuplicateds;
|
284 |
return this; |
285 |
} |
286 |
|
287 |
public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
288 |
this.isIndexAscending = ascending;
|
289 |
return this; |
290 |
} |
291 |
|
292 |
} |