Revision 42290 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/DefaultEditableFeatureType.java
DefaultEditableFeatureType.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.fmap.dal.feature.impl; |
25 | 24 |
|
... | ... | |
40 | 39 |
import org.gvsig.tools.evaluator.Evaluator; |
41 | 40 |
|
42 | 41 |
public class DefaultEditableFeatureType extends DefaultFeatureType implements |
43 |
EditableFeatureType {
|
|
42 |
EditableFeatureType {
|
|
44 | 43 |
|
45 |
/**
|
|
46 |
*
|
|
47 |
*/
|
|
48 |
private static final long serialVersionUID = -713976880396024389L;
|
|
44 |
/**
|
|
45 |
*
|
|
46 |
*/
|
|
47 |
private static final long serialVersionUID = -713976880396024389L;
|
|
49 | 48 |
|
50 |
private boolean hasStrongChanges;
|
|
51 |
private DefaultFeatureType source;
|
|
49 |
private boolean hasStrongChanges;
|
|
50 |
private DefaultFeatureType source;
|
|
52 | 51 |
|
53 |
public DefaultEditableFeatureType() {
|
|
54 |
super();
|
|
55 |
this.hasStrongChanges = false;
|
|
56 |
this.source = null;
|
|
57 |
}
|
|
52 |
public DefaultEditableFeatureType() {
|
|
53 |
super();
|
|
54 |
this.hasStrongChanges = false;
|
|
55 |
this.source = null;
|
|
56 |
}
|
|
58 | 57 |
|
59 |
public DefaultEditableFeatureType(String id) {
|
|
60 |
super(id);
|
|
61 |
this.hasStrongChanges = false;
|
|
62 |
this.source = null;
|
|
63 |
}
|
|
58 |
public DefaultEditableFeatureType(String id) {
|
|
59 |
super(id);
|
|
60 |
this.hasStrongChanges = false;
|
|
61 |
this.source = null;
|
|
62 |
}
|
|
64 | 63 |
|
65 |
protected DefaultEditableFeatureType(DefaultEditableFeatureType other) {
|
|
66 |
super(other);
|
|
67 |
this.source = (DefaultFeatureType) other.getSource();
|
|
68 |
}
|
|
64 |
protected DefaultEditableFeatureType(DefaultEditableFeatureType other) {
|
|
65 |
super(other);
|
|
66 |
this.source = (DefaultFeatureType) other.getSource();
|
|
67 |
}
|
|
69 | 68 |
|
70 |
protected DefaultEditableFeatureType(DefaultFeatureType other) {
|
|
71 |
super(other);
|
|
72 |
this.source = other;
|
|
73 |
}
|
|
69 |
protected DefaultEditableFeatureType(DefaultFeatureType other) {
|
|
70 |
super(other);
|
|
71 |
this.source = other;
|
|
72 |
}
|
|
74 | 73 |
|
75 |
protected void intitalizeAddAttibute(DefaultFeatureAttributeDescriptor attr) {
|
|
76 |
super.add(new DefaultEditableFeatureAttributeDescriptor(attr));
|
|
77 |
}
|
|
74 |
protected void intitalizeAddAttibute(DefaultFeatureAttributeDescriptor attr) {
|
|
75 |
super.add(new DefaultEditableFeatureAttributeDescriptor(attr));
|
|
76 |
}
|
|
78 | 77 |
|
78 |
public boolean hasStrongChanges() { |
|
79 |
if (hasStrongChanges) { |
|
80 |
return true; |
|
81 |
} |
|
82 |
Iterator iter = this.iterator(); |
|
83 |
DefaultEditableFeatureAttributeDescriptor attr; |
|
84 |
while (iter.hasNext()) { |
|
85 |
attr = (DefaultEditableFeatureAttributeDescriptor) iter.next(); |
|
86 |
if (attr.hasStrongChanges()) { |
|
87 |
return true; |
|
88 |
} |
|
89 |
} |
|
90 |
return false; |
|
91 |
} |
|
79 | 92 |
|
80 |
public boolean hasStrongChanges() { |
|
81 |
if (hasStrongChanges) { |
|
82 |
return true; |
|
83 |
} |
|
84 |
Iterator iter = this.iterator(); |
|
85 |
DefaultEditableFeatureAttributeDescriptor attr; |
|
86 |
while (iter.hasNext()) { |
|
87 |
attr = (DefaultEditableFeatureAttributeDescriptor) iter.next(); |
|
88 |
if (attr.hasStrongChanges()) { |
|
89 |
return true; |
|
90 |
} |
|
91 |
} |
|
92 |
return false; |
|
93 |
} |
|
93 |
public FeatureType getCopy() { |
|
94 |
return new DefaultEditableFeatureType(this); |
|
95 |
} |
|
94 | 96 |
|
95 |
public FeatureType getCopy() {
|
|
96 |
return new DefaultEditableFeatureType(this);
|
|
97 |
}
|
|
97 |
public EditableFeatureType getEditable() {
|
|
98 |
throw new UnsupportedOperationException();
|
|
99 |
}
|
|
98 | 100 |
|
99 |
public EditableFeatureType getEditable() { |
|
100 |
throw new UnsupportedOperationException(); |
|
101 |
} |
|
101 |
public boolean addAll(DefaultFeatureType other) { |
|
102 |
Iterator iter = other.iterator(); |
|
103 |
DefaultFeatureAttributeDescriptor attr; |
|
104 |
DefaultEditableFeatureAttributeDescriptor editableAttr; |
|
105 |
while (iter.hasNext()) { |
|
106 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
|
107 |
if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
108 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
109 |
attr); |
|
110 |
} else { |
|
111 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
112 |
attr); |
|
113 |
} |
|
114 |
super.add(editableAttr); |
|
115 |
} |
|
116 |
this.pk = null; |
|
117 |
this.fixAll(); |
|
118 |
return true; |
|
119 |
} |
|
102 | 120 |
|
103 |
public boolean addAll(DefaultFeatureType other) { |
|
104 |
Iterator iter = other.iterator(); |
|
105 |
DefaultFeatureAttributeDescriptor attr; |
|
106 |
DefaultEditableFeatureAttributeDescriptor editableAttr; |
|
107 |
while (iter.hasNext()) { |
|
108 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
|
109 |
if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
110 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
111 |
attr); |
|
112 |
} else { |
|
113 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
114 |
attr); |
|
115 |
} |
|
116 |
super.add(editableAttr); |
|
117 |
} |
|
118 |
this.pk = null; |
|
119 |
this.fixAll(); |
|
120 |
return true; |
|
121 |
} |
|
121 |
public EditableFeatureAttributeDescriptor addLike( |
|
122 |
FeatureAttributeDescriptor other) { |
|
123 |
DefaultEditableFeatureAttributeDescriptor editableAttr; |
|
124 |
if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
125 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
126 |
(DefaultFeatureAttributeDescriptor) other); |
|
127 |
} else { |
|
128 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
129 |
(DefaultFeatureAttributeDescriptor) other); |
|
130 |
} |
|
131 |
super.add(editableAttr); |
|
132 |
this.fixAll(); |
|
133 |
return editableAttr; |
|
122 | 134 |
|
123 |
public EditableFeatureAttributeDescriptor addLike( |
|
124 |
FeatureAttributeDescriptor other) { |
|
125 |
DefaultEditableFeatureAttributeDescriptor editableAttr; |
|
126 |
if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
127 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
128 |
(DefaultFeatureAttributeDescriptor) other); |
|
129 |
} else { |
|
130 |
editableAttr = new DefaultEditableFeatureAttributeDescriptor( |
|
131 |
(DefaultFeatureAttributeDescriptor) other); |
|
132 |
} |
|
133 |
super.add(editableAttr); |
|
134 |
this.fixAll(); |
|
135 |
return editableAttr; |
|
135 |
} |
|
136 | 136 |
|
137 |
} |
|
137 |
public FeatureType getSource() { |
|
138 |
return source; |
|
139 |
} |
|
138 | 140 |
|
139 |
public FeatureType getSource() { |
|
140 |
return source; |
|
141 |
} |
|
141 |
private long getCRC() { |
|
142 |
StringBuffer buffer = new StringBuffer(); |
|
143 |
for (int i = 0; i < this.size(); i++) { |
|
144 |
FeatureAttributeDescriptor x = this.getAttributeDescriptor(i); |
|
145 |
buffer.append(x.getName()); |
|
146 |
buffer.append(x.getDataTypeName()); |
|
147 |
buffer.append(x.getSize()); |
|
148 |
} |
|
149 |
CRC32 crc = new CRC32(); |
|
150 |
byte[] data = buffer.toString().getBytes(); |
|
151 |
crc.update(data); |
|
152 |
return crc.getValue(); |
|
153 |
} |
|
142 | 154 |
|
143 |
private long getCRC() { |
|
144 |
StringBuffer buffer = new StringBuffer(); |
|
145 |
for( int i=0; i< this.size(); i++) { |
|
146 |
FeatureAttributeDescriptor x = this.getAttributeDescriptor(i); |
|
147 |
buffer.append(x.getName()); |
|
148 |
buffer.append(x.getDataTypeName()); |
|
149 |
buffer.append(x.getSize()); |
|
150 |
} |
|
151 |
CRC32 crc = new CRC32(); |
|
152 |
byte[] data = buffer.toString().getBytes(); |
|
153 |
crc.update(data); |
|
154 |
return crc.getValue(); |
|
155 |
public FeatureType getNotEditableCopy() { |
|
156 |
this.fixAll(); |
|
157 |
DefaultFeatureType copy = new DefaultFeatureType(this, false); |
|
158 |
Iterator iter = this.iterator(); |
|
159 |
DefaultFeatureAttributeDescriptor attr; |
|
160 |
while (iter.hasNext()) { |
|
161 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
|
162 |
copy.add(new DefaultFeatureAttributeDescriptor(attr)); |
|
155 | 163 |
} |
156 |
|
|
164 |
return copy; |
|
165 |
} |
|
157 | 166 |
|
158 |
public FeatureType getNotEditableCopy() { |
|
159 |
this.fixAll(); |
|
160 |
DefaultFeatureType copy = new DefaultFeatureType(this, false); |
|
161 |
Iterator iter = this.iterator(); |
|
162 |
DefaultFeatureAttributeDescriptor attr; |
|
163 |
while (iter.hasNext()) { |
|
164 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
|
165 |
copy.add(new DefaultFeatureAttributeDescriptor(attr)); |
|
166 |
} |
|
167 |
return copy; |
|
168 |
} |
|
167 |
public EditableFeatureAttributeDescriptor add(String name, int type) { |
|
168 |
return this.add(name, type, true); |
|
169 |
} |
|
169 | 170 |
|
170 |
public EditableFeatureAttributeDescriptor add(String name, int type) { |
|
171 |
return this.add(name,type,true); |
|
172 |
} |
|
173 |
|
|
174 | 171 |
private EditableFeatureAttributeDescriptor add(String name, int type, boolean updateHasStrongChanges) { |
175 |
DefaultEditableFeatureAttributeDescriptor attr = new DefaultEditableFeatureAttributeDescriptor(); |
|
176 |
Iterator iter = this.iterator(); |
|
177 |
while (iter.hasNext()) { |
|
178 |
EditableFeatureAttributeDescriptor descriptor = (EditableFeatureAttributeDescriptor) iter.next(); |
|
179 |
if(descriptor.getName().equalsIgnoreCase(name)){ |
|
180 |
throw new RuntimeException( |
|
181 |
MessageFormat.format("Name descriptor {0} duplicated.",new String[]{name}) |
|
182 |
); |
|
183 |
} |
|
184 |
|
|
185 |
} |
|
186 |
attr.setName(name); |
|
187 |
switch (type) { |
|
188 |
case DataTypes.BOOLEAN: |
|
189 |
case DataTypes.BYTE: |
|
190 |
case DataTypes.BYTEARRAY: |
|
191 |
case DataTypes.CHAR: |
|
192 |
case DataTypes.DATE: |
|
193 |
case DataTypes.DOUBLE: |
|
194 |
case DataTypes.FLOAT: |
|
195 |
case DataTypes.GEOMETRY: |
|
196 |
case DataTypes.INT: |
|
197 |
case DataTypes.LONG: |
|
198 |
case DataTypes.OBJECT: |
|
199 |
case DataTypes.STRING: |
|
200 |
case DataTypes.TIME: |
|
201 |
case DataTypes.TIMESTAMP: |
|
202 |
break; |
|
172 |
DefaultEditableFeatureAttributeDescriptor attr = new DefaultEditableFeatureAttributeDescriptor(); |
|
173 |
Iterator iter = this.iterator(); |
|
174 |
while (iter.hasNext()) { |
|
175 |
EditableFeatureAttributeDescriptor descriptor = (EditableFeatureAttributeDescriptor) iter.next(); |
|
176 |
if (descriptor.getName().equalsIgnoreCase(name)) { |
|
177 |
throw new RuntimeException( |
|
178 |
MessageFormat.format("Name descriptor {0} duplicated.", new String[]{name}) |
|
179 |
); |
|
180 |
} |
|
203 | 181 |
|
204 |
default: |
|
205 |
throw new UnsupportedDataTypeException(name, type); |
|
206 |
} |
|
207 |
attr.setDataType(type); |
|
208 |
attr.setIndex(this.size()); |
|
209 |
super.add(attr); |
|
210 |
if (!hasStrongChanges && updateHasStrongChanges){ |
|
211 |
hasStrongChanges = true; |
|
212 |
} |
|
213 |
this.pk = null; |
|
214 |
return attr; |
|
215 |
} |
|
182 |
} |
|
183 |
attr.setName(name); |
|
184 |
switch (type) { |
|
185 |
case DataTypes.BOOLEAN: |
|
186 |
case DataTypes.BYTE: |
|
187 |
case DataTypes.BYTEARRAY: |
|
188 |
case DataTypes.CHAR: |
|
189 |
case DataTypes.DATE: |
|
190 |
case DataTypes.DOUBLE: |
|
191 |
case DataTypes.FLOAT: |
|
192 |
case DataTypes.GEOMETRY: |
|
193 |
case DataTypes.INT: |
|
194 |
case DataTypes.LONG: |
|
195 |
case DataTypes.OBJECT: |
|
196 |
case DataTypes.STRING: |
|
197 |
case DataTypes.TIME: |
|
198 |
case DataTypes.TIMESTAMP: |
|
199 |
break; |
|
216 | 200 |
|
217 |
public EditableFeatureAttributeDescriptor add(String name, int type, |
|
218 |
int size) { |
|
219 |
return this.add(name, type,true).setSize(size); |
|
220 |
} |
|
201 |
default: |
|
202 |
throw new UnsupportedDataTypeException(name, type); |
|
203 |
} |
|
204 |
attr.setDataType(type); |
|
205 |
attr.setIndex(this.size()); |
|
206 |
super.add(attr); |
|
207 |
if (!hasStrongChanges && updateHasStrongChanges) { |
|
208 |
hasStrongChanges = true; |
|
209 |
} |
|
210 |
this.pk = null; |
|
211 |
return attr; |
|
212 |
} |
|
221 | 213 |
|
222 |
public EditableFeatureAttributeDescriptor add(String name, int type, |
|
223 |
Evaluator evaluator) { |
|
224 |
if (evaluator == null){ |
|
225 |
throw new IllegalArgumentException(); |
|
226 |
} |
|
227 |
return this.add(name, type, false).setEvaluator(evaluator); |
|
228 |
} |
|
214 |
public EditableFeatureAttributeDescriptor add(String name, int type, |
|
215 |
int size) { |
|
216 |
return this.add(name, type, true).setSize(size); |
|
217 |
} |
|
229 | 218 |
|
230 |
public EditableFeatureAttributeDescriptor add(String name, int type,
|
|
231 |
FeatureAttributeEmulator emulator) {
|
|
232 |
if (emulator == null){
|
|
233 |
throw new IllegalArgumentException();
|
|
234 |
}
|
|
235 |
return this.add(name, type, false).setFeatureAttributeEmulator(emulator);
|
|
236 |
}
|
|
219 |
public EditableFeatureAttributeDescriptor add(String name, int type,
|
|
220 |
Evaluator evaluator) {
|
|
221 |
if (evaluator == null) {
|
|
222 |
throw new IllegalArgumentException();
|
|
223 |
}
|
|
224 |
return this.add(name, type, false).setEvaluator(evaluator);
|
|
225 |
}
|
|
237 | 226 |
|
238 |
public Object remove(String name) { |
|
239 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this |
|
240 |
.get(name); |
|
241 |
if (attr == null) { |
|
242 |
return null; |
|
243 |
} |
|
244 |
if (attr.getEvaluator() == null) { |
|
245 |
hasStrongChanges = true; |
|
246 |
} |
|
247 |
super.remove(attr); |
|
248 |
this.pk = null; |
|
249 |
this.fixAll(); |
|
250 |
return attr; |
|
251 |
} |
|
227 |
public EditableFeatureAttributeDescriptor add(String name, int type, |
|
228 |
FeatureAttributeEmulator emulator) { |
|
229 |
if (emulator == null) { |
|
230 |
throw new IllegalArgumentException(); |
|
231 |
} |
|
232 |
return this.add(name, type, false).setFeatureAttributeEmulator(emulator); |
|
233 |
} |
|
252 | 234 |
|
253 |
protected void fixAll() { |
|
254 |
int i = 0; |
|
255 |
Iterator iter = super.iterator(); |
|
256 |
DefaultFeatureAttributeDescriptor attr; |
|
235 |
public Object remove(String name) { |
|
236 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this |
|
237 |
.get(name); |
|
238 |
if (attr == null) { |
|
239 |
return null; |
|
240 |
} |
|
241 |
if (attr.getEvaluator() == null) { |
|
242 |
hasStrongChanges = true; |
|
243 |
} |
|
244 |
super.remove(attr); |
|
245 |
this.pk = null; |
|
246 |
this.fixAll(); |
|
247 |
return attr; |
|
248 |
} |
|
257 | 249 |
|
258 |
while (iter.hasNext()) { |
|
259 |
attr = (DefaultFeatureAttributeDescriptor) iter |
|
260 |
.next(); |
|
261 |
attr.setIndex(i++); |
|
262 |
if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
263 |
((DefaultEditableFeatureAttributeDescriptor) attr).fixAll(); |
|
264 |
} |
|
265 |
if( attr.getEvaluator()!=null ) { |
|
266 |
this.hasEvaluators = true; |
|
267 |
} |
|
268 |
if( attr.getFeatureAttributeEmulator()!=null ) { |
|
269 |
this.hasEmulators = true; |
|
270 |
} |
|
271 |
if( this.defaultGeometryAttributeName == null && attr.getType() == DataTypes.GEOMETRY ) { |
|
272 |
this.defaultGeometryAttributeName = attr.getName(); |
|
273 |
} |
|
274 |
} |
|
275 |
if (this.defaultGeometryAttributeName != null) { |
|
276 |
this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
|
277 |
} |
|
278 |
this.internalID = Long.toHexString(this.getCRC()); |
|
279 |
} |
|
250 |
protected void fixAll() { |
|
251 |
int i = 0; |
|
252 |
Iterator iter = super.iterator(); |
|
253 |
DefaultFeatureAttributeDescriptor attr; |
|
280 | 254 |
|
281 |
public void checkIntegrity() throws DataListException { |
|
282 |
Iterator iter = super.iterator(); |
|
283 |
FeatureTypeIntegrityException ex = null; |
|
255 |
while (iter.hasNext()) { |
|
256 |
attr = (DefaultFeatureAttributeDescriptor) iter |
|
257 |
.next(); |
|
258 |
attr.setIndex(i++); |
|
259 |
if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
260 |
((DefaultEditableFeatureAttributeDescriptor) attr).fixAll(); |
|
261 |
} |
|
262 |
if (attr.getEvaluator() != null) { |
|
263 |
this.hasEvaluators = true; |
|
264 |
} |
|
265 |
if (attr.getFeatureAttributeEmulator() != null) { |
|
266 |
this.hasEmulators = true; |
|
267 |
} |
|
268 |
if (this.defaultGeometryAttributeName == null && attr.getType() == DataTypes.GEOMETRY) { |
|
269 |
this.defaultGeometryAttributeName = attr.getName(); |
|
270 |
} |
|
271 |
} |
|
272 |
if (this.defaultGeometryAttributeName != null) { |
|
273 |
this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
|
274 |
} |
|
275 |
this.internalID = Long.toHexString(this.getCRC()); |
|
276 |
} |
|
284 | 277 |
|
285 |
while (iter.hasNext()) { |
|
286 |
DefaultEditableFeatureAttributeDescriptor attr = (DefaultEditableFeatureAttributeDescriptor) iter |
|
287 |
.next(); |
|
288 |
try { |
|
289 |
attr.checkIntegrity(); |
|
290 |
} catch (Exception e) { |
|
291 |
if (ex == null) { |
|
292 |
ex = new FeatureTypeIntegrityException(this.getId()); |
|
293 |
} |
|
294 |
ex.add(e); |
|
295 |
} |
|
296 |
} |
|
297 |
if (ex != null) { |
|
298 |
throw ex; |
|
299 |
} |
|
300 |
} |
|
278 |
public void checkIntegrity() throws DataListException { |
|
279 |
Iterator iter = super.iterator(); |
|
280 |
FeatureTypeIntegrityException ex = null; |
|
301 | 281 |
|
302 |
public boolean remove(EditableFeatureAttributeDescriptor attribute) { |
|
303 |
if (attribute.getEvaluator() != null) { |
|
304 |
hasStrongChanges = true; |
|
305 |
} |
|
306 |
if (!super.remove(attribute)) { |
|
307 |
return false; |
|
308 |
} |
|
309 |
this.fixAll(); |
|
310 |
return true; |
|
311 |
} |
|
282 |
while (iter.hasNext()) { |
|
283 |
DefaultEditableFeatureAttributeDescriptor attr = (DefaultEditableFeatureAttributeDescriptor) iter |
|
284 |
.next(); |
|
285 |
try { |
|
286 |
attr.checkIntegrity(); |
|
287 |
} catch (Exception e) { |
|
288 |
if (ex == null) { |
|
289 |
ex = new FeatureTypeIntegrityException(this.getId()); |
|
290 |
} |
|
291 |
ex.add(e); |
|
292 |
} |
|
293 |
} |
|
294 |
if (ex != null) { |
|
295 |
throw ex; |
|
296 |
} |
|
297 |
} |
|
312 | 298 |
|
313 |
public void setDefaultGeometryAttributeName(String name) { |
|
314 |
if (name == null || name.length() == 0) { |
|
315 |
this.defaultGeometryAttributeName = null; |
|
316 |
this.defaultGeometryAttributeIndex = -1; |
|
317 |
return; |
|
318 |
} |
|
319 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this |
|
320 |
.get(name); |
|
321 |
if (attr == null) { |
|
322 |
throw new IllegalArgumentException("Attribute '" + name |
|
323 |
+ "' not found."); |
|
324 |
} |
|
325 |
if (attr.getType() != DataTypes.GEOMETRY) { |
|
326 |
throw new IllegalArgumentException("Attribute '" + name |
|
327 |
+ "' is not a geometry."); |
|
328 |
} |
|
329 |
this.defaultGeometryAttributeName = name; |
|
330 |
this.defaultGeometryAttributeIndex = attr.getIndex(); |
|
331 |
} |
|
299 |
public boolean remove(EditableFeatureAttributeDescriptor attribute) { |
|
300 |
if (attribute.getEvaluator() != null) { |
|
301 |
hasStrongChanges = true; |
|
302 |
} |
|
303 |
if (!super.remove(attribute)) { |
|
304 |
return false; |
|
305 |
} |
|
306 |
this.fixAll(); |
|
307 |
return true; |
|
308 |
} |
|
332 | 309 |
|
333 |
public void setHasOID(boolean hasOID) { |
|
334 |
this.hasOID = hasOID; |
|
335 |
} |
|
310 |
public void setDefaultGeometryAttributeName(String name) { |
|
311 |
if (name == null || name.length() == 0) { |
|
312 |
this.defaultGeometryAttributeName = null; |
|
313 |
this.defaultGeometryAttributeIndex = -1; |
|
314 |
return; |
|
315 |
} |
|
316 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this |
|
317 |
.get(name); |
|
318 |
if (attr == null) { |
|
319 |
throw new IllegalArgumentException("Attribute '" + name |
|
320 |
+ "' not found."); |
|
321 |
} |
|
322 |
if (attr.getType() != DataTypes.GEOMETRY) { |
|
323 |
throw new IllegalArgumentException("Attribute '" + name |
|
324 |
+ "' is not a geometry."); |
|
325 |
} |
|
326 |
this.defaultGeometryAttributeName = name; |
|
327 |
this.defaultGeometryAttributeIndex = attr.getIndex(); |
|
328 |
} |
|
336 | 329 |
|
337 |
protected Iterator getIterator(Iterator iter) {
|
|
338 |
return new EditableDelegatedIterator(iter, this);
|
|
339 |
}
|
|
330 |
public void setHasOID(boolean hasOID) {
|
|
331 |
this.hasOID = hasOID;
|
|
332 |
}
|
|
340 | 333 |
|
334 |
protected Iterator getIterator(Iterator iter) { |
|
335 |
return new EditableDelegatedIterator(iter, this); |
|
336 |
} |
|
337 |
|
|
341 | 338 |
public EditableFeatureAttributeDescriptor getEditableAttributeDescriptor(String name) { |
342 | 339 |
return (EditableFeatureAttributeDescriptor) this.getAttributeDescriptor(name); |
343 | 340 |
} |
344 | 341 |
|
345 | 342 |
public EditableFeatureAttributeDescriptor getEditableAttributeDescriptor(int index) { |
346 |
return (EditableFeatureAttributeDescriptor) this.getAttributeDescriptor(index); |
|
343 |
return (EditableFeatureAttributeDescriptor) this.getAttributeDescriptor(index);
|
|
347 | 344 |
} |
348 | 345 |
|
349 |
protected class EditableDelegatedIterator extends DelegatedIterator {
|
|
346 |
protected class EditableDelegatedIterator extends DelegatedIterator {
|
|
350 | 347 |
|
351 |
private DefaultEditableFeatureType fType;
|
|
348 |
private DefaultEditableFeatureType fType;
|
|
352 | 349 |
|
353 |
public EditableDelegatedIterator(Iterator iter,
|
|
354 |
DefaultEditableFeatureType fType) {
|
|
355 |
super(iter);
|
|
356 |
this.fType = fType;
|
|
357 |
}
|
|
350 |
public EditableDelegatedIterator(Iterator iter,
|
|
351 |
DefaultEditableFeatureType fType) {
|
|
352 |
super(iter);
|
|
353 |
this.fType = fType;
|
|
354 |
}
|
|
358 | 355 |
|
359 |
public void remove() {
|
|
360 |
this.iterator.remove();
|
|
361 |
this.fType.fixAll();
|
|
362 |
}
|
|
356 |
public void remove() {
|
|
357 |
this.iterator.remove();
|
|
358 |
this.fType.fixAll();
|
|
359 |
}
|
|
363 | 360 |
|
364 |
}
|
|
361 |
}
|
|
365 | 362 |
|
366 |
protected void setAllowAutomaticValues(boolean value) {
|
|
367 |
this.allowAtomaticValues = value;
|
|
368 |
}
|
|
363 |
protected void setAllowAutomaticValues(boolean value) {
|
|
364 |
this.allowAtomaticValues = value;
|
|
365 |
}
|
|
369 | 366 |
|
370 | 367 |
public void setDefaultTimeAttributeName(String name) { |
371 | 368 |
if (name == null || name.length() == 0) { |
... | ... | |
379 | 376 |
+ "' not found."); |
380 | 377 |
} |
381 | 378 |
|
382 |
this.defaultTimeAttributeIndex = attr.getIndex();
|
|
379 |
this.defaultTimeAttributeIndex = attr.getIndex(); |
|
383 | 380 |
} |
384 | 381 |
} |
Also available in: Unified diff