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 / DefaultFeatureType.java @ 44500
History | View | Annotate | Download (36 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 | import java.lang.ref.WeakReference; |
||
27 | import java.util.ArrayList; |
||
28 | 41342 | jjdelcerro | import java.util.Arrays; |
29 | 40435 | jjdelcerro | import java.util.Collections; |
30 | 44498 | omartinez | import java.util.Date; |
31 | 43981 | omartinez | import java.util.HashSet; |
32 | 40435 | jjdelcerro | import java.util.Iterator; |
33 | 43998 | jjdelcerro | import java.util.LinkedHashSet; |
34 | 40435 | jjdelcerro | import java.util.List; |
35 | 43981 | omartinez | import java.util.Set; |
36 | 44262 | jjdelcerro | import java.util.function.Predicate; |
37 | 43610 | jjdelcerro | import java.util.zip.CRC32; |
38 | 43358 | jjdelcerro | import org.apache.commons.lang3.ArrayUtils; |
39 | 43377 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
40 | 40435 | jjdelcerro | |
41 | import org.cresques.cts.IProjection; |
||
42 | |||
43 | import org.gvsig.fmap.dal.DataTypes; |
||
44 | import org.gvsig.fmap.dal.exception.DataException; |
||
45 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
46 | import org.gvsig.fmap.dal.feature.Feature; |
||
47 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
48 | 41342 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
49 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureRules; |
50 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
51 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
52 | 44190 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
53 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.DynClass; |
54 | import org.gvsig.tools.dynobject.DynField; |
||
55 | import org.gvsig.tools.dynobject.DynMethod; |
||
56 | import org.gvsig.tools.dynobject.DynObject; |
||
57 | import org.gvsig.tools.dynobject.DynObjectValueItem; |
||
58 | import org.gvsig.tools.dynobject.DynStruct; |
||
59 | 44253 | jjdelcerro | import org.gvsig.tools.dynobject.DynStruct_v2; |
60 | import org.gvsig.tools.dynobject.Tags; |
||
61 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynMethodException; |
62 | import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
||
63 | 44253 | jjdelcerro | import org.gvsig.tools.dynobject.impl.DefaultTags; |
64 | 44498 | omartinez | import org.gvsig.tools.i18n.I18nManager; |
65 | 44190 | jjdelcerro | import org.gvsig.tools.persistence.PersistenceManager; |
66 | import org.gvsig.tools.persistence.Persistent; |
||
67 | import org.gvsig.tools.persistence.PersistentState; |
||
68 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
69 | 40435 | jjdelcerro | |
70 | 44253 | jjdelcerro | public class DefaultFeatureType |
71 | extends ArrayList<FeatureAttributeDescriptor> |
||
72 | implements
|
||
73 | FeatureType, |
||
74 | Persistent, |
||
75 | DynClass, |
||
76 | DynStruct_v2, |
||
77 | org.gvsig.tools.lang.Cloneable { |
||
78 | 40435 | jjdelcerro | |
79 | 44253 | jjdelcerro | /**
|
80 | *
|
||
81 | */
|
||
82 | private static final long serialVersionUID = -7988721447349282215L; |
||
83 | 40435 | jjdelcerro | |
84 | 44262 | jjdelcerro | public static final RecentUsedsAttributesImpl RECENTS_USEDS = new RecentUsedsAttributesImpl(); |
85 | |||
86 | 44253 | jjdelcerro | private DefaultFeatureRules rules;
|
87 | protected boolean hasEvaluators; |
||
88 | protected boolean hasEmulators; |
||
89 | protected String defaultGeometryAttributeName; |
||
90 | protected String defaultTimeAttributeName; |
||
91 | protected int defaultGeometryAttributeIndex; |
||
92 | protected int defaultTimeAttributeIndex; |
||
93 | private String id; |
||
94 | protected boolean hasOID; |
||
95 | protected boolean allowAtomaticValues; |
||
96 | protected FeatureAttributeDescriptor[] pk = null; |
||
97 | protected String internalID = null; |
||
98 | 40435 | jjdelcerro | |
99 | 44253 | jjdelcerro | private List srsList = null; |
100 | private WeakReference storeRef; |
||
101 | private boolean requiredFields; |
||
102 | 40435 | jjdelcerro | |
103 | 44253 | jjdelcerro | private String description; |
104 | private String label; |
||
105 | private Tags tags;
|
||
106 | 40435 | jjdelcerro | |
107 | 44253 | jjdelcerro | public DefaultFeatureType() {
|
108 | // Usado en la persistencia.
|
||
109 | this.internalID = Integer.toHexString((int) (Math.random() * 100000)).toUpperCase(); |
||
110 | this.id = id = "default"; |
||
111 | this.rules = new DefaultFeatureRules(); |
||
112 | this.hasEvaluators = false; |
||
113 | this.hasEmulators = false; |
||
114 | this.defaultGeometryAttributeName = null; |
||
115 | this.defaultTimeAttributeName = null; |
||
116 | this.defaultGeometryAttributeIndex = -1; |
||
117 | this.defaultTimeAttributeIndex = -1; |
||
118 | this.allowAtomaticValues = false; |
||
119 | this.tags = new DefaultTags(); |
||
120 | } |
||
121 | 40435 | jjdelcerro | |
122 | 44253 | jjdelcerro | protected DefaultFeatureType(FeatureStore store, String id) { |
123 | this();
|
||
124 | if (StringUtils.isEmpty(id)) {
|
||
125 | id = "default";
|
||
126 | } |
||
127 | this.id = id;
|
||
128 | setStore(store); |
||
129 | } |
||
130 | 40435 | jjdelcerro | |
131 | 44253 | jjdelcerro | protected DefaultFeatureType(FeatureStore store) {
|
132 | this(store, (String) null); |
||
133 | } |
||
134 | 43555 | fdiaz | |
135 | 44253 | jjdelcerro | protected DefaultFeatureType(DefaultFeatureType other) {
|
136 | this(other.getStore(), (String) null); |
||
137 | 44318 | jjdelcerro | copyFrom(other, true);
|
138 | 44253 | jjdelcerro | } |
139 | 40435 | jjdelcerro | |
140 | 44253 | jjdelcerro | protected DefaultFeatureType(DefaultFeatureType other,
|
141 | boolean copyAttributes) {
|
||
142 | this(other.getStore(), (String) null); |
||
143 | 44318 | jjdelcerro | this.copyFrom(other, copyAttributes);
|
144 | 44253 | jjdelcerro | } |
145 | 40435 | jjdelcerro | |
146 | 44318 | jjdelcerro | @Override
|
147 | public void copyFrom(FeatureType other) { |
||
148 | String internalIDSaved = this.internalID; |
||
149 | String idSaved = this.id; |
||
150 | copyFrom((DefaultFeatureType) other, true);
|
||
151 | this.id = idSaved;
|
||
152 | this.internalID = internalIDSaved;
|
||
153 | } |
||
154 | |||
155 | protected void copyFrom(DefaultFeatureType other, boolean copyAttributes) { |
||
156 | 44253 | jjdelcerro | this.id = other.getId();
|
157 | if (copyAttributes) {
|
||
158 | Iterator iter = other.iterator();
|
||
159 | DefaultFeatureAttributeDescriptor attr; |
||
160 | while (iter.hasNext()) {
|
||
161 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
162 | 44318 | jjdelcerro | DefaultFeatureAttributeDescriptor copy = this.getCopyAttributeDescriptor(attr);
|
163 | super.add(copy);
|
||
164 | 44253 | jjdelcerro | } |
165 | 44261 | jjdelcerro | this.pk = null; |
166 | 44253 | jjdelcerro | } |
167 | this.defaultGeometryAttributeName = other.defaultGeometryAttributeName;
|
||
168 | this.defaultTimeAttributeName = other.defaultTimeAttributeName;
|
||
169 | this.hasEvaluators = other.hasEvaluators;
|
||
170 | this.hasEmulators = other.hasEmulators;
|
||
171 | this.rules = (DefaultFeatureRules) other.rules.getCopy();
|
||
172 | this.defaultGeometryAttributeIndex = other.defaultGeometryAttributeIndex;
|
||
173 | this.defaultTimeAttributeIndex = other.defaultTimeAttributeIndex;
|
||
174 | this.hasOID = other.hasOID;
|
||
175 | this.id = other.id; // XXX ???? copiar o no esto???? |
||
176 | this.internalID = other.internalID;
|
||
177 | this.label = other.label;
|
||
178 | this.description = other.description;
|
||
179 | try {
|
||
180 | this.tags = (Tags) other.tags.clone();
|
||
181 | } catch (CloneNotSupportedException ex) { |
||
182 | |||
183 | } |
||
184 | } |
||
185 | 44318 | jjdelcerro | |
186 | protected DefaultFeatureAttributeDescriptor getCopyAttributeDescriptor(DefaultFeatureAttributeDescriptor src) {
|
||
187 | DefaultFeatureAttributeDescriptor copy = new DefaultFeatureAttributeDescriptor(src);
|
||
188 | copy.setFeatureType(this);
|
||
189 | return copy;
|
||
190 | 44253 | jjdelcerro | } |
191 | 40435 | jjdelcerro | |
192 | 44318 | jjdelcerro | @Override
|
193 | 44253 | jjdelcerro | public String getId() { |
194 | return this.id; |
||
195 | } |
||
196 | 40435 | jjdelcerro | |
197 | 44318 | jjdelcerro | @Override
|
198 | 44253 | jjdelcerro | public Object get(String name) { |
199 | FeatureAttributeDescriptor attr; |
||
200 | Iterator iter = this.iterator(); |
||
201 | while (iter.hasNext()) {
|
||
202 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
203 | if (attr.getName().equalsIgnoreCase(name)) {
|
||
204 | return attr;
|
||
205 | } |
||
206 | } |
||
207 | return null; |
||
208 | } |
||
209 | 40435 | jjdelcerro | |
210 | 44318 | jjdelcerro | @Override
|
211 | 44253 | jjdelcerro | public FeatureAttributeDescriptor getAttributeDescriptor(String name) { |
212 | FeatureAttributeDescriptor attr; |
||
213 | Iterator iter = this.iterator(); |
||
214 | while (iter.hasNext()) {
|
||
215 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
216 | if (attr.getName().equalsIgnoreCase(name)) {
|
||
217 | return attr;
|
||
218 | } |
||
219 | 42700 | jjdelcerro | } |
220 | 44253 | jjdelcerro | return null; |
221 | } |
||
222 | 40435 | jjdelcerro | |
223 | 44318 | jjdelcerro | @Override
|
224 | 44253 | jjdelcerro | public FeatureAttributeDescriptor getAttributeDescriptor(int index) { |
225 | return (FeatureAttributeDescriptor) super.get(index); |
||
226 | } |
||
227 | 40435 | jjdelcerro | |
228 | 44318 | jjdelcerro | @Override
|
229 | 44253 | jjdelcerro | public FeatureType getCopy() {
|
230 | return new DefaultFeatureType(this); |
||
231 | } |
||
232 | 40435 | jjdelcerro | |
233 | 44318 | jjdelcerro | @Override
|
234 | 44253 | jjdelcerro | public Object clone() { |
235 | return this.getCopy(); |
||
236 | } |
||
237 | 44077 | jjdelcerro | |
238 | 44253 | jjdelcerro | public int getDefaultGeometryAttributeIndex() { |
239 | return this.defaultGeometryAttributeIndex; |
||
240 | } |
||
241 | 44077 | jjdelcerro | |
242 | 44253 | jjdelcerro | public String getDefaultGeometryAttributeName() { |
243 | return this.defaultGeometryAttributeName; |
||
244 | } |
||
245 | 40435 | jjdelcerro | |
246 | 44253 | jjdelcerro | public int getDefaultTimeAttributeIndex() { |
247 | return this.defaultTimeAttributeIndex; |
||
248 | } |
||
249 | 40435 | jjdelcerro | |
250 | 44253 | jjdelcerro | public String getDefaultTimeAttributeName() { |
251 | return this.defaultTimeAttributeName; |
||
252 | } |
||
253 | 40435 | jjdelcerro | |
254 | 44253 | jjdelcerro | public EditableFeatureType getEditable() {
|
255 | return new DefaultEditableFeatureType(this); |
||
256 | } |
||
257 | 40435 | jjdelcerro | |
258 | 44253 | jjdelcerro | public int getIndex(String name) { |
259 | FeatureAttributeDescriptor attr; |
||
260 | Iterator iter = this.iterator(); |
||
261 | while (iter.hasNext()) {
|
||
262 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
263 | if (attr.getName().equalsIgnoreCase(name)) {
|
||
264 | return attr.getIndex();
|
||
265 | } |
||
266 | 43998 | jjdelcerro | } |
267 | 44253 | jjdelcerro | return -1; |
268 | } |
||
269 | 41342 | jjdelcerro | |
270 | 44253 | jjdelcerro | public FeatureRules getRules() {
|
271 | return this.rules; |
||
272 | } |
||
273 | 40435 | jjdelcerro | |
274 | 44253 | jjdelcerro | public boolean hasEvaluators() { |
275 | return this.hasEvaluators; |
||
276 | } |
||
277 | 40435 | jjdelcerro | |
278 | 44253 | jjdelcerro | public boolean hasEmulators() { |
279 | return this.hasEmulators; |
||
280 | } |
||
281 | 40435 | jjdelcerro | |
282 | 44253 | jjdelcerro | public boolean hasRequiredFields() { |
283 | return this.requiredFields; |
||
284 | } |
||
285 | |||
286 | public List getSRSs() { |
||
287 | if (this.srsList == null) { |
||
288 | ArrayList tmp = new ArrayList(); |
||
289 | Iterator iter = iterator();
|
||
290 | Iterator tmpIter;
|
||
291 | boolean allreadyHave;
|
||
292 | IProjection tmpSRS; |
||
293 | FeatureAttributeDescriptor attr; |
||
294 | while (iter.hasNext()) {
|
||
295 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
296 | if (attr.getDataType().getType() == DataTypes.GEOMETRY
|
||
297 | && attr.getSRS() != null) {
|
||
298 | allreadyHave = false;
|
||
299 | tmpIter = tmp.iterator(); |
||
300 | while (tmpIter.hasNext()) {
|
||
301 | tmpSRS = (IProjection) tmpIter.next(); |
||
302 | if (tmpSRS.getAbrev().equals(attr.getSRS().getAbrev())) {
|
||
303 | allreadyHave = true;
|
||
304 | break;
|
||
305 | } |
||
306 | } |
||
307 | if (!allreadyHave) {
|
||
308 | tmp.add(attr.getSRS()); |
||
309 | } |
||
310 | 41212 | jjdelcerro | } |
311 | 44253 | jjdelcerro | } |
312 | this.srsList = Collections.unmodifiableList(tmp); |
||
313 | } |
||
314 | return this.srsList; |
||
315 | } |
||
316 | 40435 | jjdelcerro | |
317 | 44253 | jjdelcerro | public IProjection getDefaultSRS() {
|
318 | if (this.getDefaultGeometryAttributeIndex() < 0) { |
||
319 | return null; |
||
320 | } |
||
321 | return this.getAttributeDescriptor( |
||
322 | this.getDefaultGeometryAttributeIndex()).getSRS();
|
||
323 | } |
||
324 | |||
325 | public void validateFeature(Feature feature, int mode) throws DataException { |
||
326 | DefaultFeatureRules rules = (DefaultFeatureRules) this.getRules();
|
||
327 | rules.validate(feature, mode); |
||
328 | } |
||
329 | |||
330 | 44374 | jjdelcerro | public FeatureType getSubtype() throws DataException { |
331 | return new SubtypeFeatureType(this, null, null, true); |
||
332 | } |
||
333 | |||
334 | 44253 | jjdelcerro | public FeatureType getSubtype(String[] names) throws DataException { |
335 | 44374 | jjdelcerro | return this.getSubtype(names, null, true); |
336 | 44253 | jjdelcerro | } |
337 | 41212 | jjdelcerro | |
338 | 44253 | jjdelcerro | public FeatureType getSubtype(String[] names, String[] constantsNames) throws DataException { |
339 | 44374 | jjdelcerro | return this.getSubtype(names, constantsNames, true); |
340 | } |
||
341 | |||
342 | public FeatureType getSubtype(String[] names, String[] constantsNames, boolean includePk) throws DataException { |
||
343 | 44253 | jjdelcerro | if (ArrayUtils.isEmpty(names) && ArrayUtils.isEmpty(constantsNames)) {
|
344 | return (FeatureType) this.clone(); |
||
345 | } |
||
346 | 44374 | jjdelcerro | return new SubtypeFeatureType(this, names, constantsNames,includePk); |
347 | 44253 | jjdelcerro | } |
348 | 43998 | jjdelcerro | |
349 | 44253 | jjdelcerro | public boolean isSubtypeOf(FeatureType featureType) { |
350 | return false; |
||
351 | } |
||
352 | |||
353 | 44149 | jjdelcerro | @Override
|
354 | public List<FeatureAttributeDescriptor> toList() { |
||
355 | return Collections.unmodifiableList(this); |
||
356 | } |
||
357 | 40435 | jjdelcerro | |
358 | 44253 | jjdelcerro | @Override
|
359 | public Tags getTags() {
|
||
360 | return this.tags; |
||
361 | } |
||
362 | 40435 | jjdelcerro | |
363 | 44253 | jjdelcerro | @Override
|
364 | public String getLabel() { |
||
365 | return this.label; |
||
366 | } |
||
367 | |||
368 | @Override
|
||
369 | public void setLabel(String label) { |
||
370 | this.label = label;
|
||
371 | } |
||
372 | |||
373 | @Override
|
||
374 | public DynField addDynField(String name, int type) { |
||
375 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
376 | } |
||
377 | |||
378 | class SubtypeFeatureType extends DefaultFeatureType { |
||
379 | |||
380 | /**
|
||
381 | *
|
||
382 | */
|
||
383 | private static final long serialVersionUID = 6913732960073922540L; |
||
384 | WeakReference parent;
|
||
385 | |||
386 | 44374 | jjdelcerro | SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames, boolean includePk) |
387 | 44253 | jjdelcerro | throws DataException {
|
388 | super(parent, false); |
||
389 | DefaultFeatureAttributeDescriptor attrcopy; |
||
390 | Set<String> attrnames = new LinkedHashSet<>(); |
||
391 | Set<String> requiredAttrnames = new HashSet<>(); |
||
392 | |||
393 | if (ArrayUtils.isEmpty(names)) {
|
||
394 | for (FeatureAttributeDescriptor attrdesc : parent) {
|
||
395 | 44376 | jjdelcerro | attrnames.add(attrdesc.getName().toLowerCase()); |
396 | 44253 | jjdelcerro | } |
397 | 44376 | jjdelcerro | } else {
|
398 | 44253 | jjdelcerro | attrnames.addAll(Arrays.asList(names));
|
399 | requiredAttrnames.addAll(Arrays.asList(names));
|
||
400 | } |
||
401 | // Add required fields for emulated fields
|
||
402 | if (parent.hasEmulators) {
|
||
403 | 44376 | jjdelcerro | // Ojo, este bucle falla cuando hay un campo calculado que depende
|
404 | // de otro campo calculado.
|
||
405 | 44253 | jjdelcerro | for (FeatureAttributeDescriptor attrdesc : parent) {
|
406 | FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator(); |
||
407 | 44376 | jjdelcerro | if (emulator != null && attrnames.contains(attrdesc.getName().toLowerCase())) { |
408 | String theNames[] = emulator.getRequiredFieldNames(); |
||
409 | if (names != null) { |
||
410 | for (String name : theNames) { |
||
411 | name = name.toLowerCase(); |
||
412 | attrnames.add(name); |
||
413 | requiredAttrnames.add(name); |
||
414 | } |
||
415 | 43998 | jjdelcerro | } |
416 | } |
||
417 | 44253 | jjdelcerro | } |
418 | } |
||
419 | // Add missing pk fiels
|
||
420 | 44374 | jjdelcerro | if (includePk && !parent.hasOID()) {
|
421 | 44253 | jjdelcerro | for (FeatureAttributeDescriptor attrdesc : parent) {
|
422 | if (attrdesc.isPrimaryKey()) {
|
||
423 | 44376 | jjdelcerro | String name = attrdesc.getName().toLowerCase();
|
424 | attrnames.add(name); |
||
425 | requiredAttrnames.add(name); |
||
426 | 43998 | jjdelcerro | } |
427 | 44253 | jjdelcerro | } |
428 | } |
||
429 | 41212 | jjdelcerro | |
430 | 44253 | jjdelcerro | // Copy attributes
|
431 | int i = 0; |
||
432 | for (String name : attrnames) { |
||
433 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) parent.get(name); |
||
434 | if (attr == null) { |
||
435 | throw new SubtypeFeatureTypeNameException(name, parent.getId()); |
||
436 | } |
||
437 | attrcopy = new DefaultFeatureAttributeDescriptor(attr);
|
||
438 | this.add(attrcopy);
|
||
439 | attrcopy.index = i++; |
||
440 | } |
||
441 | |||
442 | 44376 | jjdelcerro | // Set the constants attributes.
|
443 | 44253 | jjdelcerro | if (!ArrayUtils.isEmpty(constantsNames)) {
|
444 | for (String name : constantsNames) { |
||
445 | if (!requiredAttrnames.contains(name)) {
|
||
446 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
|
||
447 | attr.setConstantValue(true);
|
||
448 | 41342 | jjdelcerro | } |
449 | } |
||
450 | 44253 | jjdelcerro | } |
451 | 40435 | jjdelcerro | |
452 | 44253 | jjdelcerro | this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
453 | if (this.defaultGeometryAttributeIndex < 0) { |
||
454 | this.defaultGeometryAttributeName = null; |
||
455 | } |
||
456 | this.defaultTimeAttributeIndex = this.getIndex(this.defaultTimeAttributeName); |
||
457 | if (this.defaultTimeAttributeIndex < 0) { |
||
458 | this.defaultTimeAttributeName = null; |
||
459 | } |
||
460 | this.parent = new WeakReference(parent); |
||
461 | } |
||
462 | 40435 | jjdelcerro | |
463 | 44374 | jjdelcerro | public FeatureType getSubtype(String[] names, boolean includePk) throws DataException { |
464 | 44253 | jjdelcerro | return new SubtypeFeatureType((DefaultFeatureType) this.parent |
465 | 44374 | jjdelcerro | .get(), names, null, includePk);
|
466 | 44253 | jjdelcerro | } |
467 | 40435 | jjdelcerro | |
468 | 44253 | jjdelcerro | public boolean isSubtypeOf(FeatureType featureType) { |
469 | if (featureType == null) { |
||
470 | return false; |
||
471 | } |
||
472 | FeatureType parent = (FeatureType) this.parent.get();
|
||
473 | return featureType.equals(parent);
|
||
474 | } |
||
475 | 40435 | jjdelcerro | |
476 | 44253 | jjdelcerro | public EditableFeatureType getEditable() {
|
477 | throw new UnsupportedOperationException(); |
||
478 | } |
||
479 | } |
||
480 | 40435 | jjdelcerro | |
481 | 44253 | jjdelcerro | public class SubtypeFeatureTypeNameException extends DataException { |
482 | 40435 | jjdelcerro | |
483 | 44253 | jjdelcerro | /**
|
484 | *
|
||
485 | */
|
||
486 | private static final long serialVersionUID = -4414242486723260101L; |
||
487 | private final static String MESSAGE_FORMAT = "Attribute name '%(name)' not found in type (%(type))."; |
||
488 | private final static String MESSAGE_KEY = "_SubtypeFeatureTypeNameException"; |
||
489 | 40435 | jjdelcerro | |
490 | 44253 | jjdelcerro | public SubtypeFeatureTypeNameException(String name, String type) { |
491 | super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
||
492 | setValue("name", name);
|
||
493 | setValue("type", type);
|
||
494 | } |
||
495 | } |
||
496 | 40435 | jjdelcerro | |
497 | 44253 | jjdelcerro | public boolean hasOID() { |
498 | return hasOID;
|
||
499 | } |
||
500 | 40435 | jjdelcerro | |
501 | 44253 | jjdelcerro | public String toString() { |
502 | StringBuffer s = new StringBuffer(); |
||
503 | s.append(this.getId());
|
||
504 | s.append(":[");
|
||
505 | String attName;
|
||
506 | for (int i = 0; i < size(); i++) { |
||
507 | attName = ((FeatureAttributeDescriptor) get(i)).getName().toString(); |
||
508 | s.append(attName); |
||
509 | if (i < size() - 1) { |
||
510 | s.append(',');
|
||
511 | } |
||
512 | } |
||
513 | s.append(']');
|
||
514 | return s.toString();
|
||
515 | } |
||
516 | 40435 | jjdelcerro | |
517 | 44253 | jjdelcerro | public Iterator<FeatureAttributeDescriptor> iterator() { |
518 | return getIterator(super.iterator()); |
||
519 | } |
||
520 | 40435 | jjdelcerro | |
521 | 44253 | jjdelcerro | protected Iterator getIterator(Iterator iter) { |
522 | return new DelegatedIterator(iter); |
||
523 | } |
||
524 | 40435 | jjdelcerro | |
525 | 44253 | jjdelcerro | protected class DelegatedIterator implements Iterator { |
526 | 40435 | jjdelcerro | |
527 | 44253 | jjdelcerro | protected Iterator iterator; |
528 | 40435 | jjdelcerro | |
529 | 44253 | jjdelcerro | public DelegatedIterator(Iterator iter) { |
530 | this.iterator = iter;
|
||
531 | } |
||
532 | 40435 | jjdelcerro | |
533 | 44253 | jjdelcerro | public boolean hasNext() { |
534 | return iterator.hasNext();
|
||
535 | } |
||
536 | 40435 | jjdelcerro | |
537 | 44253 | jjdelcerro | public Object next() { |
538 | return iterator.next();
|
||
539 | } |
||
540 | 40435 | jjdelcerro | |
541 | 44253 | jjdelcerro | public void remove() { |
542 | throw new UnsupportedOperationException(); |
||
543 | } |
||
544 | 40435 | jjdelcerro | |
545 | 44253 | jjdelcerro | } |
546 | 40435 | jjdelcerro | |
547 | 44253 | jjdelcerro | public boolean allowAutomaticValues() { |
548 | return this.allowAtomaticValues; |
||
549 | } |
||
550 | |||
551 | public FeatureAttributeDescriptor[] getAttributeDescriptors() { |
||
552 | return (FeatureAttributeDescriptor[]) super |
||
553 | .toArray(new FeatureAttributeDescriptor[super.size()]); |
||
554 | } |
||
555 | |||
556 | 44435 | jjdelcerro | @Override
|
557 | public boolean hasPrimaryKey() { |
||
558 | if( pk!=null ) { |
||
559 | return pk.length>0; |
||
560 | } |
||
561 | for (FeatureAttributeDescriptor attr : this) { |
||
562 | if( attr.isPrimaryKey() ) {
|
||
563 | return true; |
||
564 | } |
||
565 | } |
||
566 | return false; |
||
567 | } |
||
568 | |||
569 | @Override
|
||
570 | public boolean supportReferences() { |
||
571 | return this.hasOID() || this.hasPrimaryKey(); |
||
572 | } |
||
573 | |||
574 | @Override
|
||
575 | 44253 | jjdelcerro | public FeatureAttributeDescriptor[] getPrimaryKey() { |
576 | if (pk == null) { |
||
577 | List pks = new ArrayList(); |
||
578 | Iterator iter = super.iterator(); |
||
579 | FeatureAttributeDescriptor attr; |
||
580 | while (iter.hasNext()) {
|
||
581 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
582 | if (attr.isPrimaryKey()) {
|
||
583 | pks.add(attr); |
||
584 | } |
||
585 | } |
||
586 | if (pks.isEmpty()) {
|
||
587 | 43358 | jjdelcerro | pk = new FeatureAttributeDescriptor[0]; |
588 | } else {
|
||
589 | 44253 | jjdelcerro | pk = (FeatureAttributeDescriptor[]) pks.toArray(new FeatureAttributeDescriptor[pks.size()]); |
590 | 43358 | jjdelcerro | } |
591 | 44253 | jjdelcerro | } |
592 | return pk;
|
||
593 | } |
||
594 | 40435 | jjdelcerro | |
595 | 44253 | jjdelcerro | public FeatureAttributeDescriptor getDefaultGeometryAttribute() {
|
596 | if (this.defaultGeometryAttributeIndex < 0) { |
||
597 | return null; |
||
598 | } |
||
599 | return (FeatureAttributeDescriptor) super |
||
600 | .get(this.defaultGeometryAttributeIndex);
|
||
601 | } |
||
602 | 40435 | jjdelcerro | |
603 | 44253 | jjdelcerro | public boolean equals(Object o) { |
604 | if (this == o) { |
||
605 | return true; |
||
606 | } |
||
607 | if (!(o instanceof DefaultFeatureType)) { |
||
608 | return false; |
||
609 | } |
||
610 | DefaultFeatureType other = (DefaultFeatureType) o; |
||
611 | if (!this.id.equals(other.id)) { |
||
612 | return false; |
||
613 | } |
||
614 | if (this.size() != other.size()) { |
||
615 | return false; |
||
616 | } |
||
617 | FeatureAttributeDescriptor attr, attrOther; |
||
618 | Iterator iter, iterOther;
|
||
619 | iter = this.iterator();
|
||
620 | iterOther = other.iterator(); |
||
621 | while (iter.hasNext()) {
|
||
622 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
623 | attrOther = (FeatureAttributeDescriptor) iterOther.next(); |
||
624 | if (!attr.equals(attrOther)) {
|
||
625 | 44077 | jjdelcerro | return false; |
626 | } |
||
627 | 44253 | jjdelcerro | } |
628 | 40435 | jjdelcerro | |
629 | 44253 | jjdelcerro | if (!StringUtils.equals(defaultGeometryAttributeName, other.defaultGeometryAttributeName)) {
|
630 | return false; |
||
631 | } |
||
632 | if (!StringUtils.equals(defaultTimeAttributeName, other.defaultTimeAttributeName)) {
|
||
633 | return false; |
||
634 | } |
||
635 | return true; |
||
636 | 40435 | jjdelcerro | |
637 | 44253 | jjdelcerro | } |
638 | 40435 | jjdelcerro | |
639 | 44253 | jjdelcerro | /**
|
640 | * Start of DynClass interface implementation READONLY
|
||
641 | */
|
||
642 | public DynField addDynField(String name) { |
||
643 | throw new UnsupportedOperationException(); |
||
644 | } |
||
645 | 40435 | jjdelcerro | |
646 | 44253 | jjdelcerro | public DynField getDeclaredDynField(String name) { |
647 | return (DynField) getAttributeDescriptor(name);
|
||
648 | } |
||
649 | 40435 | jjdelcerro | |
650 | 44253 | jjdelcerro | public DynField[] getDeclaredDynFields() { |
651 | return (DynField[]) getAttributeDescriptors(); |
||
652 | } |
||
653 | 40435 | jjdelcerro | |
654 | 44253 | jjdelcerro | public String getDescription() { |
655 | return this.description; |
||
656 | } |
||
657 | 40435 | jjdelcerro | |
658 | 44253 | jjdelcerro | public DynField getDynField(String name) { |
659 | return (DynField) getAttributeDescriptor(name);
|
||
660 | } |
||
661 | 40435 | jjdelcerro | |
662 | 44253 | jjdelcerro | public DynField[] getDynFields() { |
663 | return (DynField[]) getAttributeDescriptors(); |
||
664 | } |
||
665 | 40435 | jjdelcerro | |
666 | 44253 | jjdelcerro | public String getName() { |
667 | return this.id + "_" + internalID; |
||
668 | } |
||
669 | 40435 | jjdelcerro | |
670 | 44253 | jjdelcerro | public void removeDynField(String name) { |
671 | throw new UnsupportedOperationException(); |
||
672 | 40435 | jjdelcerro | |
673 | 44253 | jjdelcerro | } |
674 | 40435 | jjdelcerro | |
675 | 44253 | jjdelcerro | public void addDynMethod(DynMethod dynMethod) { |
676 | throw new UnsupportedOperationException(); |
||
677 | 40435 | jjdelcerro | |
678 | 44253 | jjdelcerro | } |
679 | 40435 | jjdelcerro | |
680 | 44253 | jjdelcerro | public void extend(DynClass dynClass) { |
681 | throw new UnsupportedOperationException(); |
||
682 | 40435 | jjdelcerro | |
683 | 44253 | jjdelcerro | } |
684 | 40435 | jjdelcerro | |
685 | 44253 | jjdelcerro | public void extend(String dynClassName) { |
686 | throw new UnsupportedOperationException(); |
||
687 | 40435 | jjdelcerro | |
688 | 44253 | jjdelcerro | } |
689 | 40435 | jjdelcerro | |
690 | 44253 | jjdelcerro | public void extend(String namespace, String dynClassName) { |
691 | throw new UnsupportedOperationException(); |
||
692 | 40435 | jjdelcerro | |
693 | 44253 | jjdelcerro | } |
694 | 40435 | jjdelcerro | |
695 | 44253 | jjdelcerro | public DynMethod getDeclaredDynMethod(String name) |
696 | throws DynMethodException {
|
||
697 | return null; |
||
698 | } |
||
699 | 40435 | jjdelcerro | |
700 | 44253 | jjdelcerro | public DynMethod[] getDeclaredDynMethods() throws DynMethodException { |
701 | return null; |
||
702 | } |
||
703 | 40435 | jjdelcerro | |
704 | 44253 | jjdelcerro | public DynMethod getDynMethod(String name) throws DynMethodException { |
705 | return null; |
||
706 | } |
||
707 | 40435 | jjdelcerro | |
708 | 44253 | jjdelcerro | public DynMethod getDynMethod(int code) throws DynMethodException { |
709 | return null; |
||
710 | } |
||
711 | 40435 | jjdelcerro | |
712 | 44253 | jjdelcerro | public DynMethod[] getDynMethods() throws DynMethodException { |
713 | return null; |
||
714 | } |
||
715 | 40435 | jjdelcerro | |
716 | 44253 | jjdelcerro | public DynClass[] getSuperDynClasses() { |
717 | return null; |
||
718 | } |
||
719 | 40435 | jjdelcerro | |
720 | 44253 | jjdelcerro | public boolean isInstance(DynObject dynObject) { |
721 | if (dynObject.getDynClass().getName() == getName()) {
|
||
722 | return true; |
||
723 | } |
||
724 | return false; |
||
725 | } |
||
726 | 40435 | jjdelcerro | |
727 | 44253 | jjdelcerro | public DynObject newInstance() {
|
728 | 40435 | jjdelcerro | |
729 | 44253 | jjdelcerro | throw new UnsupportedOperationException(); |
730 | } |
||
731 | 40435 | jjdelcerro | |
732 | 44253 | jjdelcerro | public void removeDynMethod(String name) { |
733 | throw new UnsupportedOperationException(); |
||
734 | 40435 | jjdelcerro | |
735 | 44253 | jjdelcerro | } |
736 | 40435 | jjdelcerro | |
737 | 44253 | jjdelcerro | public DynField addDynFieldChoice(String name, int type, |
738 | Object defaultValue, DynObjectValueItem[] values, |
||
739 | boolean mandatory, boolean persistent) { |
||
740 | throw new UnsupportedOperationException(); |
||
741 | } |
||
742 | 40435 | jjdelcerro | |
743 | 44253 | jjdelcerro | public DynField addDynFieldRange(String name, int type, |
744 | Object defaultValue, Object min, Object max, boolean mandatory, |
||
745 | boolean persistent) {
|
||
746 | throw new UnsupportedOperationException(); |
||
747 | } |
||
748 | 40435 | jjdelcerro | |
749 | 44253 | jjdelcerro | public DynField addDynFieldSingle(String name, int type, |
750 | Object defaultValue, boolean mandatory, boolean persistent) { |
||
751 | throw new UnsupportedOperationException(); |
||
752 | } |
||
753 | 40435 | jjdelcerro | |
754 | 44253 | jjdelcerro | public void validate(DynObject object) throws DynObjectValidateException { |
755 | //FIXME: not sure it's the correct code
|
||
756 | if (object instanceof Feature) { |
||
757 | Feature fea = (Feature) object; |
||
758 | if (fea.getType().equals(this)) { |
||
759 | return;
|
||
760 | } |
||
761 | } |
||
762 | throw new DynObjectValidateException(this.id); |
||
763 | } |
||
764 | 40435 | jjdelcerro | |
765 | 44253 | jjdelcerro | public DynField addDynFieldLong(String name) { |
766 | throw new UnsupportedOperationException(); |
||
767 | } |
||
768 | 40435 | jjdelcerro | |
769 | 44253 | jjdelcerro | public DynField addDynFieldChoice(String name, int type, |
770 | Object defaultValue, DynObjectValueItem[] values) { |
||
771 | throw new UnsupportedOperationException(); |
||
772 | } |
||
773 | 40435 | jjdelcerro | |
774 | 44253 | jjdelcerro | public DynField addDynFieldRange(String name, int type, |
775 | Object defaultValue, Object min, Object max) { |
||
776 | throw new UnsupportedOperationException(); |
||
777 | } |
||
778 | 40435 | jjdelcerro | |
779 | 44253 | jjdelcerro | public DynField addDynFieldSingle(String name, int type, Object defaultValue) { |
780 | throw new UnsupportedOperationException(); |
||
781 | } |
||
782 | 40435 | jjdelcerro | |
783 | 44253 | jjdelcerro | public DynField addDynFieldString(String name) { |
784 | throw new UnsupportedOperationException(); |
||
785 | } |
||
786 | 43555 | fdiaz | |
787 | 44253 | jjdelcerro | public DynField addDynFieldInt(String name) { |
788 | throw new UnsupportedOperationException(); |
||
789 | } |
||
790 | 43555 | fdiaz | |
791 | 44253 | jjdelcerro | public DynField addDynFieldDouble(String name) { |
792 | throw new UnsupportedOperationException(); |
||
793 | } |
||
794 | 43555 | fdiaz | |
795 | 44253 | jjdelcerro | public DynField addDynFieldFloat(String name) { |
796 | throw new UnsupportedOperationException(); |
||
797 | } |
||
798 | 40435 | jjdelcerro | |
799 | 44253 | jjdelcerro | public DynField addDynFieldBoolean(String name) { |
800 | throw new UnsupportedOperationException(); |
||
801 | } |
||
802 | 40435 | jjdelcerro | |
803 | 44253 | jjdelcerro | public DynField addDynFieldList(String name) { |
804 | throw new UnsupportedOperationException(); |
||
805 | } |
||
806 | 40435 | jjdelcerro | |
807 | 44253 | jjdelcerro | public DynField addDynFieldMap(String name) { |
808 | throw new UnsupportedOperationException(); |
||
809 | } |
||
810 | 40435 | jjdelcerro | |
811 | 44253 | jjdelcerro | public DynField addDynFieldObject(String name) { |
812 | throw new UnsupportedOperationException(); |
||
813 | } |
||
814 | 40435 | jjdelcerro | |
815 | 44253 | jjdelcerro | public DynField addDynFieldSet(String name) { |
816 | throw new UnsupportedOperationException(); |
||
817 | } |
||
818 | 40435 | jjdelcerro | |
819 | 44253 | jjdelcerro | public DynField addDynFieldArray(String name) { |
820 | throw new UnsupportedOperationException(); |
||
821 | } |
||
822 | 40435 | jjdelcerro | |
823 | 44253 | jjdelcerro | public DynField addDynFieldDate(String name) { |
824 | throw new UnsupportedOperationException(); |
||
825 | } |
||
826 | 40435 | jjdelcerro | |
827 | 44253 | jjdelcerro | public void extend(DynStruct struct) { |
828 | throw new UnsupportedOperationException(); |
||
829 | } |
||
830 | 40435 | jjdelcerro | |
831 | 44253 | jjdelcerro | public String getFullName() { |
832 | 40435 | jjdelcerro | // TODO: usar el DynClassName
|
833 | 44253 | jjdelcerro | return this.id; |
834 | } |
||
835 | 40435 | jjdelcerro | |
836 | 44253 | jjdelcerro | public String getNamespace() { |
837 | return "DALFeature"; |
||
838 | } |
||
839 | 40435 | jjdelcerro | |
840 | 44253 | jjdelcerro | public DynStruct[] getSuperDynStructs() { |
841 | return null; |
||
842 | } |
||
843 | 40435 | jjdelcerro | |
844 | 44253 | jjdelcerro | public void setDescription(String description) { |
845 | this.description = description;
|
||
846 | } |
||
847 | 40435 | jjdelcerro | |
848 | 44253 | jjdelcerro | public void setNamespace(String namespace) { |
849 | throw new UnsupportedOperationException(); |
||
850 | } |
||
851 | 40435 | jjdelcerro | |
852 | 44253 | jjdelcerro | public DynField addDynFieldFile(String name) { |
853 | throw new UnsupportedOperationException(); |
||
854 | } |
||
855 | 40435 | jjdelcerro | |
856 | 44253 | jjdelcerro | public DynField addDynFieldFolder(String name) { |
857 | throw new UnsupportedOperationException(); |
||
858 | } |
||
859 | 40435 | jjdelcerro | |
860 | 44253 | jjdelcerro | public DynField addDynFieldURL(String name) { |
861 | throw new UnsupportedOperationException(); |
||
862 | } |
||
863 | 40435 | jjdelcerro | |
864 | 44253 | jjdelcerro | public DynField addDynFieldURI(String name) { |
865 | throw new UnsupportedOperationException(); |
||
866 | } |
||
867 | 40435 | jjdelcerro | |
868 | public boolean isExtendable(DynStruct dynStruct) { |
||
869 | return false; |
||
870 | } |
||
871 | |||
872 | 44253 | jjdelcerro | public void extend(DynStruct[] structs) { |
873 | // TODO Auto-generated method stub
|
||
874 | 43555 | fdiaz | |
875 | 44253 | jjdelcerro | } |
876 | 40435 | jjdelcerro | |
877 | 44253 | jjdelcerro | public void remove(DynStruct superDynStruct) { |
878 | // TODO Auto-generated method stub
|
||
879 | 43555 | fdiaz | |
880 | 44253 | jjdelcerro | } |
881 | 40435 | jjdelcerro | |
882 | 44253 | jjdelcerro | public void removeAll(DynStruct[] superDynStruct) { |
883 | // TODO Auto-generated method stub
|
||
884 | 43555 | fdiaz | |
885 | 44253 | jjdelcerro | } |
886 | 40435 | jjdelcerro | |
887 | 44253 | jjdelcerro | public FeatureAttributeDescriptor getDefaultTimeAttribute() {
|
888 | if (this.defaultTimeAttributeIndex < 0) { |
||
889 | return null; |
||
890 | } |
||
891 | return (FeatureAttributeDescriptor) super |
||
892 | .get(this.defaultTimeAttributeIndex);
|
||
893 | } |
||
894 | 43610 | jjdelcerro | |
895 | public void setDefaultTimeAttributeName(String name) { |
||
896 | if (name == null || name.length() == 0) { |
||
897 | this.defaultTimeAttributeIndex = -1; |
||
898 | return;
|
||
899 | } |
||
900 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
|
||
901 | if (attr == null) { |
||
902 | throw new IllegalArgumentException("Attribute '" + name + "' not found."); |
||
903 | } |
||
904 | 44253 | jjdelcerro | if (attr.getIndex() < 0) { |
905 | 43610 | jjdelcerro | fixAll(); |
906 | } |
||
907 | this.defaultTimeAttributeIndex = attr.getIndex();
|
||
908 | } |
||
909 | 44253 | jjdelcerro | |
910 | 43610 | jjdelcerro | protected void fixAll() { |
911 | int i = 0; |
||
912 | Iterator iter = super.iterator(); |
||
913 | DefaultFeatureAttributeDescriptor attr; |
||
914 | |||
915 | while (iter.hasNext()) {
|
||
916 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
917 | 44253 | jjdelcerro | if (attr.getOder() < 1) { |
918 | attr.setOrder(i * 10);
|
||
919 | 44202 | jjdelcerro | } |
920 | 43610 | jjdelcerro | attr.setIndex(i++); |
921 | 44094 | jjdelcerro | attr.fixAll(); |
922 | 43610 | jjdelcerro | if (attr.getEvaluator() != null) { |
923 | this.hasEvaluators = true; |
||
924 | } |
||
925 | if (attr.getFeatureAttributeEmulator() != null) { |
||
926 | this.hasEmulators = true; |
||
927 | 43998 | jjdelcerro | String[] x = attr.getFeatureAttributeEmulator().getRequiredFieldNames(); |
928 | 44253 | jjdelcerro | if (!ArrayUtils.isEmpty(x)) {
|
929 | 43998 | jjdelcerro | this.requiredFields = true; |
930 | } |
||
931 | 43610 | jjdelcerro | } |
932 | 44253 | jjdelcerro | switch (attr.getType()) {
|
933 | 44090 | jjdelcerro | case DataTypes.GEOMETRY:
|
934 | 44253 | jjdelcerro | if (this.defaultGeometryAttributeName == null) { |
935 | 44090 | jjdelcerro | this.defaultGeometryAttributeName = attr.getName();
|
936 | } |
||
937 | break;
|
||
938 | case DataTypes.INSTANT:
|
||
939 | case DataTypes.INTERVAL:
|
||
940 | case DataTypes.DATE:
|
||
941 | 44253 | jjdelcerro | if (this.defaultTimeAttributeName == null && attr.isTime()) { |
942 | 44090 | jjdelcerro | this.defaultTimeAttributeName = attr.getName();
|
943 | } |
||
944 | break;
|
||
945 | 43610 | jjdelcerro | } |
946 | } |
||
947 | if (this.defaultGeometryAttributeName != null) { |
||
948 | this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
||
949 | } |
||
950 | 44077 | jjdelcerro | if (this.defaultTimeAttributeName != null) { |
951 | this.defaultTimeAttributeIndex = this.getIndex(this.defaultTimeAttributeName); |
||
952 | } |
||
953 | 43610 | jjdelcerro | this.internalID = Long.toHexString(this.getCRC()); |
954 | 44253 | jjdelcerro | |
955 | 43610 | jjdelcerro | } |
956 | 44253 | jjdelcerro | |
957 | 43610 | jjdelcerro | protected long getCRC() { |
958 | StringBuffer buffer = new StringBuffer(); |
||
959 | for (int i = 0; i < this.size(); i++) { |
||
960 | FeatureAttributeDescriptor x = this.getAttributeDescriptor(i);
|
||
961 | buffer.append(x.getName()); |
||
962 | buffer.append(x.getDataTypeName()); |
||
963 | buffer.append(x.getSize()); |
||
964 | } |
||
965 | CRC32 crc = new CRC32(); |
||
966 | byte[] data = buffer.toString().getBytes(); |
||
967 | crc.update(data); |
||
968 | return crc.getValue();
|
||
969 | } |
||
970 | 43739 | jjdelcerro | |
971 | @Override
|
||
972 | public FeatureStore getStore() {
|
||
973 | 44253 | jjdelcerro | if (this.storeRef == null) { |
974 | 43739 | jjdelcerro | return null; |
975 | } |
||
976 | return (FeatureStore) this.storeRef.get(); |
||
977 | } |
||
978 | 44253 | jjdelcerro | |
979 | 44190 | jjdelcerro | public void setStore(FeatureStore store) { |
980 | 44253 | jjdelcerro | if (store == null) { |
981 | this.storeRef = null; |
||
982 | 44190 | jjdelcerro | } else {
|
983 | this.storeRef = new WeakReference(store); |
||
984 | } |
||
985 | } |
||
986 | 43739 | jjdelcerro | |
987 | 44190 | jjdelcerro | @Override
|
988 | 44262 | jjdelcerro | public List<FeatureAttributeDescriptor> getFilteredAttributes( |
989 | Predicate<FeatureAttributeDescriptor> filter,
|
||
990 | int max
|
||
991 | ) { |
||
992 | List<FeatureAttributeDescriptor> attrs = new ArrayList<>(); |
||
993 | for (FeatureAttributeDescriptor attribute : this) { |
||
994 | if (filter.test(attribute)) {
|
||
995 | attrs.add(attribute); |
||
996 | } |
||
997 | } |
||
998 | return attrs;
|
||
999 | } |
||
1000 | |||
1001 | @Override
|
||
1002 | public List<FeatureAttributeDescriptor> getRecentUseds() { |
||
1003 | return RECENTS_USEDS.getAttributes(this); |
||
1004 | } |
||
1005 | |||
1006 | @Override
|
||
1007 | 44190 | jjdelcerro | public void loadFromState(PersistentState state) |
1008 | throws PersistenceException {
|
||
1009 | |||
1010 | // FIXME: rules
|
||
1011 | hasEvaluators = state.getBoolean("hasEvaluators");
|
||
1012 | hasEmulators = state.getBoolean("hasEmulators");
|
||
1013 | defaultGeometryAttributeName = state.getString("defaultGeometryAttributeName");
|
||
1014 | defaultTimeAttributeName = state.getString("defaultTimeAttributeName");
|
||
1015 | defaultGeometryAttributeIndex = state.getInt("defaultGeometryAttributeIndex");
|
||
1016 | defaultTimeAttributeIndex = state.getInt("defaultTimeAttributeIndex");
|
||
1017 | id = state.getString("id");
|
||
1018 | hasOID = state.getBoolean("hasOID");
|
||
1019 | allowAtomaticValues = state.getBoolean("allowAtomaticValues");
|
||
1020 | |||
1021 | requiredFields = state.getBoolean("requiredFields");
|
||
1022 | internalID = state.getString("internalID");
|
||
1023 | 44262 | jjdelcerro | tags = (Tags) state.get("tags");
|
1024 | if( tags == null ) { |
||
1025 | this.tags = new DefaultTags(); |
||
1026 | } |
||
1027 | 44253 | jjdelcerro | |
1028 | 44190 | jjdelcerro | List<FeatureAttributeDescriptor> elements = state.getList("elements"); |
1029 | for (FeatureAttributeDescriptor element : elements) {
|
||
1030 | 44253 | jjdelcerro | ((DefaultFeatureAttributeDescriptor) element).setFeatureType(this);
|
1031 | 44190 | jjdelcerro | super.add(element);
|
1032 | } |
||
1033 | 44261 | jjdelcerro | this.pk = null; |
1034 | 44190 | jjdelcerro | this.fixAll();
|
1035 | } |
||
1036 | |||
1037 | @Override
|
||
1038 | public void saveToState(PersistentState state) throws PersistenceException { |
||
1039 | |||
1040 | // FIXME: rules
|
||
1041 | state.set("hasEvaluators", hasEvaluators);
|
||
1042 | state.set("hasEmulators", hasEmulators);
|
||
1043 | state.set("defaultGeometryAttributeName", defaultGeometryAttributeName);
|
||
1044 | state.set("defaultTimeAttributeName", defaultTimeAttributeName);
|
||
1045 | state.set("defaultGeometryAttributeIndex", defaultGeometryAttributeIndex);
|
||
1046 | state.set("defaultTimeAttributeIndex", defaultTimeAttributeIndex);
|
||
1047 | state.set("id", id);
|
||
1048 | state.set("hasOID", hasOID);
|
||
1049 | state.set("allowAtomaticValues", allowAtomaticValues);
|
||
1050 | |||
1051 | state.set("requiredFields", requiredFields);
|
||
1052 | state.set("internalID", internalID);
|
||
1053 | 44253 | jjdelcerro | |
1054 | 44190 | jjdelcerro | List<FeatureAttributeDescriptor> elements = new ArrayList<>(); |
1055 | elements.addAll(this);
|
||
1056 | state.set("elements", elements);
|
||
1057 | 44262 | jjdelcerro | state.set("tags", tags);
|
1058 | 44253 | jjdelcerro | |
1059 | 44190 | jjdelcerro | } |
1060 | 44253 | jjdelcerro | |
1061 | 44190 | jjdelcerro | private static final String FEATTYPE_PERSISTENCE_DEFINITION_NAME = "FeatureType"; |
1062 | |||
1063 | public static void registerPersistenceDefinition() { |
||
1064 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
1065 | 44253 | jjdelcerro | |
1066 | 44190 | jjdelcerro | if (manager.getDefinition(FEATTYPE_PERSISTENCE_DEFINITION_NAME)
|
1067 | == null) {
|
||
1068 | DynStruct definition = manager.addDefinition(DefaultFeatureType.class, |
||
1069 | FEATTYPE_PERSISTENCE_DEFINITION_NAME, |
||
1070 | FEATTYPE_PERSISTENCE_DEFINITION_NAME |
||
1071 | 44253 | jjdelcerro | + " persistent definition",
|
1072 | 44190 | jjdelcerro | null,
|
1073 | null
|
||
1074 | ); |
||
1075 | // definition.addDynFieldObject("rules");
|
||
1076 | definition.addDynFieldBoolean("hasEvaluators");
|
||
1077 | definition.addDynFieldBoolean("hasEmulators");
|
||
1078 | definition.addDynFieldString("defaultGeometryAttributeName");
|
||
1079 | definition.addDynFieldString("defaultTimeAttributeName");
|
||
1080 | definition.addDynFieldInt("defaultGeometryAttributeIndex");
|
||
1081 | definition.addDynFieldInt("defaultTimeAttributeIndex");
|
||
1082 | definition.addDynFieldString("id");
|
||
1083 | definition.addDynFieldBoolean("hasOID");
|
||
1084 | definition.addDynFieldBoolean("allowAtomaticValues");
|
||
1085 | 44253 | jjdelcerro | |
1086 | 44190 | jjdelcerro | definition.addDynFieldBoolean("requiredFields");
|
1087 | 44253 | jjdelcerro | definition.addDynFieldString("internalID");
|
1088 | 44190 | jjdelcerro | |
1089 | definition.addDynFieldList("elements")
|
||
1090 | 44253 | jjdelcerro | .setClassOfItems(FeatureAttributeDescriptor.class); |
1091 | 44262 | jjdelcerro | |
1092 | definition.addDynFieldObject("tags")
|
||
1093 | .setClassOfValue(Tags.class); |
||
1094 | |||
1095 | 44190 | jjdelcerro | } |
1096 | } |
||
1097 | |||
1098 | 44439 | jjdelcerro | @Override
|
1099 | public FeatureStore getAsFeatureStore() {
|
||
1100 | FeatureStore store = FeatureTypeToStoreProviderAdapter.createFeatureStore(this);
|
||
1101 | return store;
|
||
1102 | } |
||
1103 | 44498 | omartinez | |
1104 | |||
1105 | public String getNewFieldName() { |
||
1106 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
1107 | String prefix = i18n.getTranslation("_Field"); |
||
1108 | String fieldName;
|
||
1109 | for (int i = 1; i < 1000; i++) { |
||
1110 | fieldName = prefix +"-"+i;
|
||
1111 | if( this.get(fieldName)==null ) { |
||
1112 | return fieldName;
|
||
1113 | } |
||
1114 | } |
||
1115 | fieldName = prefix + "-" + (new Date()).getTime(); |
||
1116 | return fieldName;
|
||
1117 | } |
||
1118 | 44500 | omartinez | |
1119 | public FeatureType getOriginalFeatureType() {
|
||
1120 | DefaultFeatureStore store = (DefaultFeatureStore) this.getStore();
|
||
1121 | if (store==null) { |
||
1122 | return null; |
||
1123 | } |
||
1124 | return store.getOriginalFeatureType(this); |
||
1125 | } |
||
1126 | 44253 | jjdelcerro | } |