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