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 @ 44036
History | View | Annotate | Download (9.54 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
25 | |||
26 | 41483 | jjdelcerro | import java.text.DateFormat; |
27 | 40435 | jjdelcerro | import java.util.HashMap; |
28 | |||
29 | import org.cresques.cts.IProjection; |
||
30 | 40964 | jldominguez | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; |
||
32 | 40435 | jjdelcerro | |
33 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
34 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
35 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
36 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
37 | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
||
38 | 42303 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
39 | 40435 | jjdelcerro | 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 | 40964 | jldominguez | |
47 | private static Logger logger = LoggerFactory.getLogger( |
||
48 | DefaultEditableFeatureAttributeDescriptor.class); |
||
49 | 40435 | jjdelcerro | |
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 | 43739 | jjdelcerro | public DefaultEditableFeatureAttributeDescriptor(FeatureType type) {
|
69 | super(type);
|
||
70 | 40435 | jjdelcerro | 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 | 40964 | jldominguez | 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 | 40435 | jjdelcerro | |
95 | if (ex.size() > 0) { |
||
96 | throw ex;
|
||
97 | } |
||
98 | } |
||
99 | |||
100 | public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
||
101 | this.allowNull = allowNull;
|
||
102 | 43135 | jjdelcerro | if (!isComputed()) {
|
103 | 40435 | jjdelcerro | hasStrongChanges = true;
|
104 | } |
||
105 | return this; |
||
106 | } |
||
107 | |||
108 | public EditableFeatureAttributeDescriptor setDataType(int type) { |
||
109 | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
||
110 | 43135 | jjdelcerro | if (!isComputed()) {
|
111 | 40435 | jjdelcerro | hasStrongChanges = true;
|
112 | } |
||
113 | return this; |
||
114 | } |
||
115 | |||
116 | public EditableFeatureAttributeDescriptor setDefaultValue(
|
||
117 | Object defaultValue) {
|
||
118 | this.defaultValue = defaultValue;
|
||
119 | 43135 | jjdelcerro | if (!isComputed()) {
|
120 | 40435 | jjdelcerro | 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 | 41335 | jjdelcerro | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
134 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
135 | return this; |
||
136 | } |
||
137 | |||
138 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
139 | this.geometryType = type;
|
||
140 | 42303 | jjdelcerro | if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) { |
141 | this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
||
142 | } |
||
143 | 40435 | jjdelcerro | 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 | 43135 | jjdelcerro | if (!isComputed()) {
|
159 | 40435 | jjdelcerro | hasStrongChanges = true;
|
160 | } |
||
161 | return this; |
||
162 | } |
||
163 | |||
164 | 42716 | jjdelcerro | @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 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
173 | boolean isPrimaryKey) {
|
||
174 | this.primaryKey = isPrimaryKey;
|
||
175 | 43135 | jjdelcerro | if (!isComputed()) {
|
176 | 40435 | jjdelcerro | hasStrongChanges = true;
|
177 | } |
||
178 | return this; |
||
179 | } |
||
180 | |||
181 | public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
||
182 | this.readOnly = isReadOnly;
|
||
183 | 43135 | jjdelcerro | if (!isComputed()) {
|
184 | 40435 | jjdelcerro | hasStrongChanges = true;
|
185 | } |
||
186 | return this; |
||
187 | } |
||
188 | |||
189 | public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
||
190 | int maximumOccurrences) {
|
||
191 | this.maximumOccurrences = maximumOccurrences;
|
||
192 | 43135 | jjdelcerro | if (!isComputed()) {
|
193 | 40435 | jjdelcerro | hasStrongChanges = true;
|
194 | } |
||
195 | return this; |
||
196 | } |
||
197 | |||
198 | public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
||
199 | int minimumOccurrences) {
|
||
200 | this.minimumOccurrences = minimumOccurrences;
|
||
201 | 43135 | jjdelcerro | if (!isComputed()) {
|
202 | 40435 | jjdelcerro | hasStrongChanges = true;
|
203 | } |
||
204 | return this; |
||
205 | } |
||
206 | |||
207 | 43967 | jjdelcerro | @Override
|
208 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setName(String name) { |
209 | if (originalName == null) { |
||
210 | originalName = this.name;
|
||
211 | 43967 | jjdelcerro | if (!isComputed()) {
|
212 | hasStrongChanges = true;
|
||
213 | } |
||
214 | 40435 | jjdelcerro | } |
215 | this.name = name;
|
||
216 | 43135 | jjdelcerro | if (!isComputed()) {
|
217 | 40435 | jjdelcerro | hasStrongChanges = true;
|
218 | } |
||
219 | return this; |
||
220 | } |
||
221 | |||
222 | public String getOriginalName() { |
||
223 | return originalName;
|
||
224 | } |
||
225 | |||
226 | public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
||
227 | this.objectClass = theClass;
|
||
228 | 43135 | jjdelcerro | if (!isComputed()) {
|
229 | 40435 | jjdelcerro | hasStrongChanges = true;
|
230 | } |
||
231 | return this; |
||
232 | } |
||
233 | |||
234 | public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
||
235 | this.precision = precision;
|
||
236 | 43135 | jjdelcerro | if (!isComputed()) {
|
237 | 40435 | jjdelcerro | hasStrongChanges = true;
|
238 | } |
||
239 | return this; |
||
240 | } |
||
241 | |||
242 | public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
||
243 | this.SRS = SRS;
|
||
244 | 43135 | jjdelcerro | if (!isComputed()) {
|
245 | 40435 | jjdelcerro | hasStrongChanges = true;
|
246 | } |
||
247 | return this; |
||
248 | } |
||
249 | |||
250 | public EditableFeatureAttributeDescriptor setSize(int size) { |
||
251 | this.size = size;
|
||
252 | 43135 | jjdelcerro | if (!isComputed()) {
|
253 | 40435 | jjdelcerro | hasStrongChanges = true;
|
254 | } |
||
255 | return this; |
||
256 | } |
||
257 | |||
258 | public boolean hasStrongChanges() { |
||
259 | return hasStrongChanges;
|
||
260 | } |
||
261 | |||
262 | public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
||
263 | String infoName, Object value) { |
||
264 | if (this.additionalInfo == null) { |
||
265 | this.additionalInfo = new HashMap(); |
||
266 | } |
||
267 | this.additionalInfo.put(infoName, value);
|
||
268 | return this; |
||
269 | } |
||
270 | |||
271 | public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
||
272 | this.isAutomatic = isAutomatic;
|
||
273 | 43362 | jjdelcerro | if( isAutomatic ) {
|
274 | this.setHidden(true); |
||
275 | } |
||
276 | 40435 | jjdelcerro | return this; |
277 | } |
||
278 | |||
279 | 41483 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
280 | 43135 | jjdelcerro | this.isTime = isTime;
|
281 | if (!isComputed()) {
|
||
282 | hasStrongChanges = true;
|
||
283 | } |
||
284 | return this; |
||
285 | 41483 | jjdelcerro | } |
286 | |||
287 | public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
||
288 | this.dateFormat = dateFormat;
|
||
289 | return this; |
||
290 | } |
||
291 | 41638 | jjdelcerro | |
292 | public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
||
293 | this.indexed = isIndexed;
|
||
294 | 43638 | jjdelcerro | if (!isComputed()) {
|
295 | hasStrongChanges = true;
|
||
296 | } |
||
297 | 41638 | jjdelcerro | return this; |
298 | } |
||
299 | 41483 | jjdelcerro | |
300 | 41638 | jjdelcerro | public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
301 | this.allowIndexDuplicateds = allowDuplicateds;
|
||
302 | 43638 | jjdelcerro | if (!isComputed()) {
|
303 | hasStrongChanges = true;
|
||
304 | } |
||
305 | 41638 | jjdelcerro | return this; |
306 | } |
||
307 | |||
308 | public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
||
309 | this.isIndexAscending = ascending;
|
||
310 | 43638 | jjdelcerro | if (!isComputed()) {
|
311 | hasStrongChanges = true;
|
||
312 | } |
||
313 | 41638 | jjdelcerro | return this; |
314 | } |
||
315 | 41483 | jjdelcerro | |
316 | 40435 | jjdelcerro | } |