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 @ 43628
History | View | Annotate | Download (9.19 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 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
36 | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
||
37 | 42303 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
38 | 40435 | jjdelcerro | 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 | 40964 | jldominguez | |
46 | private static Logger logger = LoggerFactory.getLogger( |
||
47 | DefaultEditableFeatureAttributeDescriptor.class); |
||
48 | 40435 | jjdelcerro | |
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 | 40964 | jldominguez | 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 | 40435 | jjdelcerro | |
94 | if (ex.size() > 0) { |
||
95 | throw ex;
|
||
96 | } |
||
97 | } |
||
98 | |||
99 | public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
||
100 | this.allowNull = allowNull;
|
||
101 | 43135 | jjdelcerro | if (!isComputed()) {
|
102 | 40435 | jjdelcerro | hasStrongChanges = true;
|
103 | } |
||
104 | return this; |
||
105 | } |
||
106 | |||
107 | public EditableFeatureAttributeDescriptor setDataType(int type) { |
||
108 | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
||
109 | 43135 | jjdelcerro | if (!isComputed()) {
|
110 | 40435 | jjdelcerro | hasStrongChanges = true;
|
111 | } |
||
112 | return this; |
||
113 | } |
||
114 | |||
115 | public EditableFeatureAttributeDescriptor setDefaultValue(
|
||
116 | Object defaultValue) {
|
||
117 | this.defaultValue = defaultValue;
|
||
118 | 43135 | jjdelcerro | if (!isComputed()) {
|
119 | 40435 | jjdelcerro | 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 | 41335 | jjdelcerro | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
133 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
134 | return this; |
||
135 | } |
||
136 | |||
137 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
138 | this.geometryType = type;
|
||
139 | 42303 | jjdelcerro | if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) { |
140 | this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
||
141 | } |
||
142 | 40435 | jjdelcerro | 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 | 43135 | jjdelcerro | if (!isComputed()) {
|
158 | 40435 | jjdelcerro | hasStrongChanges = true;
|
159 | } |
||
160 | return this; |
||
161 | } |
||
162 | |||
163 | 42716 | jjdelcerro | @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 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
172 | boolean isPrimaryKey) {
|
||
173 | this.primaryKey = isPrimaryKey;
|
||
174 | 43135 | jjdelcerro | if (!isComputed()) {
|
175 | 40435 | jjdelcerro | hasStrongChanges = true;
|
176 | } |
||
177 | return this; |
||
178 | } |
||
179 | |||
180 | public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
||
181 | this.readOnly = isReadOnly;
|
||
182 | 43135 | jjdelcerro | if (!isComputed()) {
|
183 | 40435 | jjdelcerro | hasStrongChanges = true;
|
184 | } |
||
185 | return this; |
||
186 | } |
||
187 | |||
188 | public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
||
189 | int maximumOccurrences) {
|
||
190 | this.maximumOccurrences = maximumOccurrences;
|
||
191 | 43135 | jjdelcerro | if (!isComputed()) {
|
192 | 40435 | jjdelcerro | hasStrongChanges = true;
|
193 | } |
||
194 | return this; |
||
195 | } |
||
196 | |||
197 | public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
||
198 | int minimumOccurrences) {
|
||
199 | this.minimumOccurrences = minimumOccurrences;
|
||
200 | 43135 | jjdelcerro | if (!isComputed()) {
|
201 | 40435 | jjdelcerro | 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 | 43135 | jjdelcerro | if (!isComputed()) {
|
213 | 40435 | jjdelcerro | 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 | 43135 | jjdelcerro | if (!isComputed()) {
|
225 | 40435 | jjdelcerro | hasStrongChanges = true;
|
226 | } |
||
227 | return this; |
||
228 | } |
||
229 | |||
230 | public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
||
231 | this.precision = precision;
|
||
232 | 43135 | jjdelcerro | if (!isComputed()) {
|
233 | 40435 | jjdelcerro | hasStrongChanges = true;
|
234 | } |
||
235 | return this; |
||
236 | } |
||
237 | |||
238 | public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
||
239 | this.SRS = SRS;
|
||
240 | 43135 | jjdelcerro | if (!isComputed()) {
|
241 | 40435 | jjdelcerro | hasStrongChanges = true;
|
242 | } |
||
243 | return this; |
||
244 | } |
||
245 | |||
246 | public EditableFeatureAttributeDescriptor setSize(int size) { |
||
247 | this.size = size;
|
||
248 | 43135 | jjdelcerro | if (!isComputed()) {
|
249 | 40435 | jjdelcerro | 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 | 43362 | jjdelcerro | if( isAutomatic ) {
|
270 | this.setHidden(true); |
||
271 | } |
||
272 | 40435 | jjdelcerro | return this; |
273 | } |
||
274 | |||
275 | 41483 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
276 | 43135 | jjdelcerro | this.isTime = isTime;
|
277 | if (!isComputed()) {
|
||
278 | hasStrongChanges = true;
|
||
279 | } |
||
280 | return this; |
||
281 | 41483 | jjdelcerro | } |
282 | |||
283 | public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
||
284 | this.dateFormat = dateFormat;
|
||
285 | return this; |
||
286 | } |
||
287 | 41638 | jjdelcerro | |
288 | public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
||
289 | this.indexed = isIndexed;
|
||
290 | return this; |
||
291 | } |
||
292 | 41483 | jjdelcerro | |
293 | 41638 | jjdelcerro | public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
294 | this.allowIndexDuplicateds = allowDuplicateds;
|
||
295 | return this; |
||
296 | } |
||
297 | |||
298 | public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
||
299 | this.isIndexAscending = ascending;
|
||
300 | return this; |
||
301 | } |
||
302 | 41483 | jjdelcerro | |
303 | 40435 | jjdelcerro | } |