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 @ 44149
History | View | Annotate | Download (26.3 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.lang.ref.WeakReference; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Arrays; |
29 |
import java.util.Collections; |
30 |
import java.util.HashSet; |
31 |
import java.util.Iterator; |
32 |
import java.util.LinkedHashSet; |
33 |
import java.util.List; |
34 |
import java.util.Set; |
35 |
import java.util.zip.CRC32; |
36 |
import org.apache.commons.lang3.ArrayUtils; |
37 |
import org.apache.commons.lang3.StringUtils; |
38 |
|
39 |
import org.cresques.cts.IProjection; |
40 |
|
41 |
import org.gvsig.fmap.dal.DataTypes; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
44 |
import org.gvsig.fmap.dal.feature.Feature; |
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
46 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
47 |
import org.gvsig.fmap.dal.feature.FeatureRules; |
48 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 |
import org.gvsig.fmap.dal.feature.FeatureType; |
50 |
import org.gvsig.tools.dynobject.DynClass; |
51 |
import org.gvsig.tools.dynobject.DynField; |
52 |
import org.gvsig.tools.dynobject.DynMethod; |
53 |
import org.gvsig.tools.dynobject.DynObject; |
54 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
55 |
import org.gvsig.tools.dynobject.DynStruct; |
56 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
57 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
58 |
|
59 |
public class DefaultFeatureType extends ArrayList<FeatureAttributeDescriptor> implements FeatureType, |
60 |
DynClass, org.gvsig.tools.lang.Cloneable { |
61 |
|
62 |
/**
|
63 |
*
|
64 |
*/
|
65 |
private static final long serialVersionUID = -7988721447349282215L; |
66 |
|
67 |
private DefaultFeatureRules rules;
|
68 |
protected boolean hasEvaluators; |
69 |
protected boolean hasEmulators; |
70 |
protected String defaultGeometryAttributeName; |
71 |
protected String defaultTimeAttributeName; |
72 |
protected int defaultGeometryAttributeIndex; |
73 |
protected int defaultTimeAttributeIndex; |
74 |
private String id; |
75 |
protected boolean hasOID; |
76 |
protected boolean allowAtomaticValues; |
77 |
protected FeatureAttributeDescriptor[] pk = null; |
78 |
protected String internalID = null; |
79 |
|
80 |
private List srsList = null; |
81 |
private WeakReference storeRef; |
82 |
private boolean requiredFields; |
83 |
|
84 |
protected DefaultFeatureType(FeatureStore store, String id) { |
85 |
if (StringUtils.isEmpty(id)) {
|
86 |
id = "default";
|
87 |
} |
88 |
if( store == null ) { |
89 |
this.storeRef = null; |
90 |
} else {
|
91 |
this.storeRef = new WeakReference(store); |
92 |
} |
93 |
this.internalID = Integer.toHexString((int) (Math.random() * 100000)).toUpperCase(); |
94 |
this.id = id;
|
95 |
this.rules = new DefaultFeatureRules(); |
96 |
this.hasEvaluators = false; |
97 |
this.hasEmulators = false; |
98 |
this.defaultGeometryAttributeName = null; |
99 |
this.defaultTimeAttributeName = null; |
100 |
this.defaultGeometryAttributeIndex = -1; |
101 |
this.defaultTimeAttributeIndex = -1; |
102 |
this.allowAtomaticValues = false; |
103 |
} |
104 |
|
105 |
protected DefaultFeatureType(FeatureStore store) {
|
106 |
this(store, (String)null); |
107 |
} |
108 |
|
109 |
protected DefaultFeatureType(DefaultFeatureType other) {
|
110 |
this(other.getStore(), (String)null); |
111 |
initialize(other, true);
|
112 |
} |
113 |
|
114 |
protected DefaultFeatureType(DefaultFeatureType other,
|
115 |
boolean copyAttributes) {
|
116 |
this(other.getStore(), (String)null); |
117 |
initialize(other, copyAttributes); |
118 |
} |
119 |
|
120 |
protected void initialize(DefaultFeatureType other, boolean copyAttributes) { |
121 |
this.id = other.getId();
|
122 |
if (copyAttributes) {
|
123 |
Iterator iter = other.iterator();
|
124 |
DefaultFeatureAttributeDescriptor attr; |
125 |
while (iter.hasNext()) {
|
126 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
127 |
this.intitalizeAddAttibute(attr);
|
128 |
} |
129 |
if( other.pk!=null ) { |
130 |
this.pk = new FeatureAttributeDescriptor[other.pk.length]; |
131 |
for( int i=0; i<other.pk.length; i++ ) { |
132 |
this.pk[i] = other.pk[i].getCopy();
|
133 |
} |
134 |
} |
135 |
} |
136 |
this.defaultGeometryAttributeName = other.defaultGeometryAttributeName;
|
137 |
this.defaultTimeAttributeName = other.defaultTimeAttributeName;
|
138 |
this.hasEvaluators = other.hasEvaluators;
|
139 |
this.hasEmulators = other.hasEmulators;
|
140 |
this.rules = (DefaultFeatureRules) other.rules.getCopy();
|
141 |
this.defaultGeometryAttributeIndex = other.defaultGeometryAttributeIndex;
|
142 |
this.defaultTimeAttributeIndex = other.defaultTimeAttributeIndex;
|
143 |
this.hasOID = other.hasOID;
|
144 |
this.id = other.id; // XXX ???? copiar o no esto???? |
145 |
this.internalID = other.internalID;
|
146 |
} |
147 |
|
148 |
protected void intitalizeAddAttibute(DefaultFeatureAttributeDescriptor attr) { |
149 |
super.add(attr.getCopy());
|
150 |
} |
151 |
|
152 |
public String getId() { |
153 |
return this.id; |
154 |
} |
155 |
|
156 |
public Object get(String name) { |
157 |
FeatureAttributeDescriptor attr; |
158 |
Iterator iter = this.iterator(); |
159 |
while (iter.hasNext()) {
|
160 |
attr = (FeatureAttributeDescriptor) iter.next(); |
161 |
if (attr.getName().equalsIgnoreCase(name)) {
|
162 |
return attr;
|
163 |
} |
164 |
} |
165 |
return null; |
166 |
} |
167 |
|
168 |
public FeatureAttributeDescriptor getAttributeDescriptor(String name) { |
169 |
FeatureAttributeDescriptor attr; |
170 |
Iterator iter = this.iterator(); |
171 |
while (iter.hasNext()) {
|
172 |
attr = (FeatureAttributeDescriptor) iter.next(); |
173 |
if (attr.getName().equalsIgnoreCase(name)) {
|
174 |
return attr;
|
175 |
} |
176 |
} |
177 |
return null; |
178 |
} |
179 |
|
180 |
public FeatureAttributeDescriptor getAttributeDescriptor(int index) { |
181 |
return (FeatureAttributeDescriptor) super.get(index); |
182 |
} |
183 |
|
184 |
public FeatureType getCopy() {
|
185 |
return new DefaultFeatureType(this); |
186 |
} |
187 |
|
188 |
public Object clone() { |
189 |
return this.getCopy(); |
190 |
} |
191 |
|
192 |
public int getDefaultGeometryAttributeIndex() { |
193 |
return this.defaultGeometryAttributeIndex; |
194 |
} |
195 |
|
196 |
public String getDefaultGeometryAttributeName() { |
197 |
return this.defaultGeometryAttributeName; |
198 |
} |
199 |
|
200 |
public int getDefaultTimeAttributeIndex() { |
201 |
return this.defaultTimeAttributeIndex; |
202 |
} |
203 |
|
204 |
public String getDefaultTimeAttributeName() { |
205 |
return this.defaultTimeAttributeName; |
206 |
} |
207 |
|
208 |
public EditableFeatureType getEditable() {
|
209 |
return new DefaultEditableFeatureType(this); |
210 |
} |
211 |
|
212 |
public int getIndex(String name) { |
213 |
FeatureAttributeDescriptor attr; |
214 |
Iterator iter = this.iterator(); |
215 |
while (iter.hasNext()) {
|
216 |
attr = (FeatureAttributeDescriptor) iter.next(); |
217 |
if (attr.getName().equalsIgnoreCase(name)) {
|
218 |
return attr.getIndex();
|
219 |
} |
220 |
} |
221 |
return -1; |
222 |
} |
223 |
|
224 |
public FeatureRules getRules() {
|
225 |
return this.rules; |
226 |
} |
227 |
|
228 |
public boolean hasEvaluators() { |
229 |
return this.hasEvaluators; |
230 |
} |
231 |
|
232 |
public boolean hasEmulators() { |
233 |
return this.hasEmulators; |
234 |
} |
235 |
|
236 |
public boolean hasRequiredFields() { |
237 |
return this.requiredFields; |
238 |
} |
239 |
|
240 |
public List getSRSs() { |
241 |
if (this.srsList == null) { |
242 |
ArrayList tmp = new ArrayList(); |
243 |
Iterator iter = iterator();
|
244 |
Iterator tmpIter;
|
245 |
boolean allreadyHave;
|
246 |
IProjection tmpSRS; |
247 |
FeatureAttributeDescriptor attr; |
248 |
while (iter.hasNext()){
|
249 |
attr = (FeatureAttributeDescriptor) iter.next(); |
250 |
if (attr.getDataType().getType() == DataTypes.GEOMETRY
|
251 |
&& attr.getSRS() != null) {
|
252 |
allreadyHave = false;
|
253 |
tmpIter = tmp.iterator(); |
254 |
while (tmpIter.hasNext()) {
|
255 |
tmpSRS = (IProjection) tmpIter.next(); |
256 |
if (tmpSRS.getAbrev().equals(attr.getSRS().getAbrev())) {
|
257 |
allreadyHave = true;
|
258 |
break;
|
259 |
} |
260 |
} |
261 |
if (!allreadyHave) {
|
262 |
tmp.add(attr.getSRS()); |
263 |
} |
264 |
} |
265 |
} |
266 |
this.srsList = Collections.unmodifiableList(tmp); |
267 |
} |
268 |
return this.srsList; |
269 |
} |
270 |
|
271 |
public IProjection getDefaultSRS() {
|
272 |
if (this.getDefaultGeometryAttributeIndex() < 0) { |
273 |
return null; |
274 |
} |
275 |
return this.getAttributeDescriptor( |
276 |
this.getDefaultGeometryAttributeIndex()).getSRS();
|
277 |
} |
278 |
|
279 |
public void validateFeature(Feature feature, int mode) throws DataException { |
280 |
DefaultFeatureRules rules = (DefaultFeatureRules) this.getRules();
|
281 |
rules.validate(feature,mode); |
282 |
} |
283 |
|
284 |
public FeatureType getSubtype(String[] names) throws DataException { |
285 |
if( names==null || names.length <1) { |
286 |
return (FeatureType) this.clone(); |
287 |
} |
288 |
return new SubtypeFeatureType(this, names, null); |
289 |
} |
290 |
|
291 |
public FeatureType getSubtype(String[] names, String[] constantsNames) throws DataException { |
292 |
if( ArrayUtils.isEmpty(names) && ArrayUtils.isEmpty(constantsNames) ) {
|
293 |
return (FeatureType) this.clone(); |
294 |
} |
295 |
return new SubtypeFeatureType(this, names,constantsNames); |
296 |
} |
297 |
|
298 |
public FeatureType getSubtype() throws DataException { |
299 |
return new SubtypeFeatureType(this, null,null); |
300 |
} |
301 |
|
302 |
public boolean isSubtypeOf(FeatureType featureType) { |
303 |
return false; |
304 |
} |
305 |
|
306 |
@Override
|
307 |
public List<FeatureAttributeDescriptor> toList() { |
308 |
return Collections.unmodifiableList(this); |
309 |
} |
310 |
|
311 |
class SubtypeFeatureType extends DefaultFeatureType { |
312 |
/**
|
313 |
*
|
314 |
*/
|
315 |
private static final long serialVersionUID = 6913732960073922540L; |
316 |
WeakReference parent;
|
317 |
|
318 |
SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames) |
319 |
throws DataException {
|
320 |
super(parent, false); |
321 |
DefaultFeatureAttributeDescriptor attrcopy; |
322 |
Set<String> attrnames = new LinkedHashSet<>(); |
323 |
Set<String> requiredAttrnames = new HashSet<>(); |
324 |
|
325 |
if ( ArrayUtils.isEmpty(names) ) {
|
326 |
for (FeatureAttributeDescriptor attrdesc : parent) {
|
327 |
attrnames.add(attrdesc.getName()); |
328 |
} |
329 |
} else {
|
330 |
attrnames.addAll(Arrays.asList(names));
|
331 |
requiredAttrnames.addAll(Arrays.asList(names));
|
332 |
} |
333 |
// Add required fields for emulated fields
|
334 |
if ( parent.hasEmulators ) {
|
335 |
for (FeatureAttributeDescriptor attrdesc : parent) {
|
336 |
FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator(); |
337 |
if ( emulator != null ) { |
338 |
String ss[] = emulator.getRequiredFieldNames(); |
339 |
if ( ss != null ) { |
340 |
attrnames.addAll(Arrays.asList(ss));
|
341 |
requiredAttrnames.addAll(Arrays.asList(ss));
|
342 |
} |
343 |
} |
344 |
} |
345 |
} |
346 |
// Add missing pk fiels
|
347 |
if ( !parent.hasOID() ) {
|
348 |
for (FeatureAttributeDescriptor attrdesc : parent) {
|
349 |
if ( attrdesc.isPrimaryKey() ) {
|
350 |
attrnames.add(attrdesc.getName()); |
351 |
requiredAttrnames.add(attrdesc.getName()); |
352 |
} |
353 |
} |
354 |
} |
355 |
|
356 |
// Copy attributes
|
357 |
int i = 0; |
358 |
for (String name : attrnames) { |
359 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) parent.get(name); |
360 |
if ( attr == null ) { |
361 |
throw new SubtypeFeatureTypeNameException(name, parent.getId()); |
362 |
} |
363 |
attrcopy = new DefaultFeatureAttributeDescriptor(attr);
|
364 |
this.add(attrcopy);
|
365 |
attrcopy.index = i++; |
366 |
} |
367 |
|
368 |
// Set the consttants attributes.
|
369 |
if ( !ArrayUtils.isEmpty(constantsNames) ) {
|
370 |
for (String name : constantsNames) { |
371 |
if ( !requiredAttrnames.contains(name) ) {
|
372 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
|
373 |
attr.setConstantValue(true);
|
374 |
} |
375 |
} |
376 |
} |
377 |
|
378 |
this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
379 |
if ( this.defaultGeometryAttributeIndex < 0 ) { |
380 |
this.defaultGeometryAttributeName = null; |
381 |
} |
382 |
this.defaultTimeAttributeIndex = this.getIndex(this.defaultTimeAttributeName); |
383 |
if ( this.defaultTimeAttributeIndex < 0 ) { |
384 |
this.defaultTimeAttributeName = null; |
385 |
} |
386 |
this.parent = new WeakReference(parent); |
387 |
} |
388 |
|
389 |
public FeatureType getSubtype(String[] names) throws DataException { |
390 |
return new SubtypeFeatureType((DefaultFeatureType) this.parent |
391 |
.get(), names, null);
|
392 |
} |
393 |
|
394 |
public boolean isSubtypeOf(FeatureType featureType) { |
395 |
if (featureType == null) { |
396 |
return false; |
397 |
} |
398 |
FeatureType parent = (FeatureType) this.parent.get();
|
399 |
return featureType.equals(parent);
|
400 |
} |
401 |
|
402 |
public EditableFeatureType getEditable() {
|
403 |
throw new UnsupportedOperationException(); |
404 |
} |
405 |
} |
406 |
|
407 |
public class SubtypeFeatureTypeNameException extends DataException { |
408 |
|
409 |
/**
|
410 |
*
|
411 |
*/
|
412 |
private static final long serialVersionUID = -4414242486723260101L; |
413 |
private final static String MESSAGE_FORMAT = "Attribute name '%(name)' not found in type (%(type))."; |
414 |
private final static String MESSAGE_KEY = "_SubtypeFeatureTypeNameException"; |
415 |
|
416 |
public SubtypeFeatureTypeNameException(String name, String type) { |
417 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
418 |
setValue("name", name);
|
419 |
setValue("type", type);
|
420 |
} |
421 |
} |
422 |
|
423 |
public boolean hasOID() { |
424 |
return hasOID;
|
425 |
} |
426 |
public String toString(){ |
427 |
StringBuffer s = new StringBuffer(); |
428 |
s.append(this.getId());
|
429 |
s.append(":[");
|
430 |
String attName;
|
431 |
for (int i = 0; i < size(); i++) { |
432 |
attName =((FeatureAttributeDescriptor)get(i)).getName().toString(); |
433 |
s.append(attName); |
434 |
if (i < size() - 1) { |
435 |
s.append(',');
|
436 |
} |
437 |
} |
438 |
s.append(']');
|
439 |
return s.toString();
|
440 |
} |
441 |
|
442 |
public Iterator<FeatureAttributeDescriptor> iterator() { |
443 |
return getIterator(super.iterator()); |
444 |
} |
445 |
|
446 |
protected Iterator getIterator(Iterator iter) { |
447 |
return new DelegatedIterator(iter); |
448 |
} |
449 |
|
450 |
protected class DelegatedIterator implements Iterator { |
451 |
|
452 |
protected Iterator iterator; |
453 |
|
454 |
public DelegatedIterator(Iterator iter) { |
455 |
this.iterator = iter;
|
456 |
} |
457 |
|
458 |
public boolean hasNext() { |
459 |
return iterator.hasNext();
|
460 |
} |
461 |
|
462 |
public Object next() { |
463 |
return iterator.next();
|
464 |
} |
465 |
|
466 |
public void remove() { |
467 |
throw new UnsupportedOperationException(); |
468 |
} |
469 |
|
470 |
} |
471 |
|
472 |
public boolean allowAutomaticValues() { |
473 |
return this.allowAtomaticValues; |
474 |
} |
475 |
|
476 |
public FeatureAttributeDescriptor[] getAttributeDescriptors() { |
477 |
return (FeatureAttributeDescriptor[]) super |
478 |
.toArray(new FeatureAttributeDescriptor[super.size()]); |
479 |
} |
480 |
|
481 |
public FeatureAttributeDescriptor[] getPrimaryKey() { |
482 |
if (pk == null) { |
483 |
List pks = new ArrayList(); |
484 |
Iterator iter = super.iterator(); |
485 |
FeatureAttributeDescriptor attr; |
486 |
while (iter.hasNext()){
|
487 |
attr = (FeatureAttributeDescriptor) iter.next(); |
488 |
if (attr.isPrimaryKey()){
|
489 |
pks.add(attr); |
490 |
} |
491 |
} |
492 |
if( pks.isEmpty() ) {
|
493 |
pk = new FeatureAttributeDescriptor[0]; |
494 |
} else {
|
495 |
pk = (FeatureAttributeDescriptor[])pks.toArray(new FeatureAttributeDescriptor[pks.size()]); |
496 |
} |
497 |
} |
498 |
return pk;
|
499 |
} |
500 |
|
501 |
public FeatureAttributeDescriptor getDefaultGeometryAttribute() {
|
502 |
if (this.defaultGeometryAttributeIndex < 0) { |
503 |
return null; |
504 |
} |
505 |
return (FeatureAttributeDescriptor) super |
506 |
.get(this.defaultGeometryAttributeIndex);
|
507 |
} |
508 |
|
509 |
|
510 |
|
511 |
public boolean equals(Object o) { |
512 |
if (this == o) { |
513 |
return true; |
514 |
} |
515 |
if (!(o instanceof DefaultFeatureType)) { |
516 |
return false; |
517 |
} |
518 |
DefaultFeatureType other = (DefaultFeatureType) o; |
519 |
if (!this.id.equals(other.id)) { |
520 |
return false; |
521 |
} |
522 |
if (this.size() != other.size()) { |
523 |
return false; |
524 |
} |
525 |
FeatureAttributeDescriptor attr,attrOther; |
526 |
Iterator iter,iterOther;
|
527 |
iter = this.iterator();
|
528 |
iterOther = other.iterator(); |
529 |
while (iter.hasNext()) {
|
530 |
attr = (FeatureAttributeDescriptor) iter.next(); |
531 |
attrOther = (FeatureAttributeDescriptor) iterOther.next(); |
532 |
if (!attr.equals(attrOther)) {
|
533 |
return false; |
534 |
} |
535 |
} |
536 |
|
537 |
if( !StringUtils.equals(defaultGeometryAttributeName, other.defaultGeometryAttributeName)) {
|
538 |
return false; |
539 |
} |
540 |
if( !StringUtils.equals(defaultTimeAttributeName, other.defaultTimeAttributeName)) {
|
541 |
return false; |
542 |
} |
543 |
return true; |
544 |
|
545 |
} |
546 |
|
547 |
/**
|
548 |
* Start of DynClass interface implementation
|
549 |
* READONLY
|
550 |
*/
|
551 |
|
552 |
public DynField addDynField(String name) { |
553 |
throw new UnsupportedOperationException(); |
554 |
} |
555 |
|
556 |
public DynField getDeclaredDynField(String name) { |
557 |
return (DynField) getAttributeDescriptor(name);
|
558 |
} |
559 |
|
560 |
public DynField[] getDeclaredDynFields() { |
561 |
return (DynField[]) getAttributeDescriptors(); |
562 |
} |
563 |
|
564 |
public String getDescription() { |
565 |
return null; |
566 |
} |
567 |
|
568 |
public DynField getDynField(String name) { |
569 |
return (DynField) getAttributeDescriptor(name);
|
570 |
} |
571 |
|
572 |
public DynField[] getDynFields() { |
573 |
return (DynField[]) getAttributeDescriptors(); |
574 |
} |
575 |
|
576 |
public String getName() { |
577 |
return this.id + "_" + internalID; |
578 |
} |
579 |
|
580 |
public void removeDynField(String name) { |
581 |
throw new UnsupportedOperationException(); |
582 |
|
583 |
} |
584 |
|
585 |
public void addDynMethod(DynMethod dynMethod) { |
586 |
throw new UnsupportedOperationException(); |
587 |
|
588 |
} |
589 |
|
590 |
public void extend(DynClass dynClass) { |
591 |
throw new UnsupportedOperationException(); |
592 |
|
593 |
} |
594 |
|
595 |
public void extend(String dynClassName) { |
596 |
throw new UnsupportedOperationException(); |
597 |
|
598 |
} |
599 |
|
600 |
public void extend(String namespace, String dynClassName) { |
601 |
throw new UnsupportedOperationException(); |
602 |
|
603 |
} |
604 |
|
605 |
public DynMethod getDeclaredDynMethod(String name) |
606 |
throws DynMethodException {
|
607 |
return null; |
608 |
} |
609 |
|
610 |
public DynMethod[] getDeclaredDynMethods() throws DynMethodException { |
611 |
return null; |
612 |
} |
613 |
|
614 |
public DynMethod getDynMethod(String name) throws DynMethodException { |
615 |
return null; |
616 |
} |
617 |
|
618 |
public DynMethod getDynMethod(int code) throws DynMethodException { |
619 |
return null; |
620 |
} |
621 |
|
622 |
public DynMethod[] getDynMethods() throws DynMethodException { |
623 |
return null; |
624 |
} |
625 |
|
626 |
public DynClass[] getSuperDynClasses() { |
627 |
return null; |
628 |
} |
629 |
|
630 |
public boolean isInstance(DynObject dynObject) { |
631 |
if (dynObject.getDynClass().getName() == getName()) {
|
632 |
return true; |
633 |
} |
634 |
return false; |
635 |
} |
636 |
|
637 |
public DynObject newInstance() {
|
638 |
|
639 |
throw new UnsupportedOperationException(); |
640 |
} |
641 |
|
642 |
public void removeDynMethod(String name) { |
643 |
throw new UnsupportedOperationException(); |
644 |
|
645 |
} |
646 |
|
647 |
public DynField addDynFieldChoice(String name, int type, |
648 |
Object defaultValue, DynObjectValueItem[] values, |
649 |
boolean mandatory, boolean persistent) { |
650 |
throw new UnsupportedOperationException(); |
651 |
} |
652 |
|
653 |
public DynField addDynFieldRange(String name, int type, |
654 |
Object defaultValue, Object min, Object max, boolean mandatory, |
655 |
boolean persistent) {
|
656 |
throw new UnsupportedOperationException(); |
657 |
} |
658 |
|
659 |
public DynField addDynFieldSingle(String name, int type, |
660 |
Object defaultValue, boolean mandatory, boolean persistent) { |
661 |
throw new UnsupportedOperationException(); |
662 |
} |
663 |
|
664 |
public void validate(DynObject object) throws DynObjectValidateException { |
665 |
//FIXME: not sure it's the correct code
|
666 |
if (object instanceof Feature) { |
667 |
Feature fea = (Feature) object; |
668 |
if (fea.getType().equals(this)) { |
669 |
return;
|
670 |
} |
671 |
} |
672 |
throw new DynObjectValidateException(this.id); |
673 |
} |
674 |
|
675 |
public DynField addDynFieldLong(String name) { |
676 |
throw new UnsupportedOperationException(); |
677 |
} |
678 |
|
679 |
public DynField addDynFieldChoice(String name, int type, |
680 |
Object defaultValue, DynObjectValueItem[] values) { |
681 |
throw new UnsupportedOperationException(); |
682 |
} |
683 |
|
684 |
public DynField addDynFieldRange(String name, int type, |
685 |
Object defaultValue, Object min, Object max) { |
686 |
throw new UnsupportedOperationException(); |
687 |
} |
688 |
|
689 |
public DynField addDynFieldSingle(String name, int type, Object defaultValue) { |
690 |
throw new UnsupportedOperationException(); |
691 |
} |
692 |
|
693 |
public DynField addDynFieldString(String name) { |
694 |
throw new UnsupportedOperationException(); |
695 |
} |
696 |
|
697 |
public DynField addDynFieldInt(String name) { |
698 |
throw new UnsupportedOperationException(); |
699 |
} |
700 |
|
701 |
public DynField addDynFieldDouble(String name) { |
702 |
throw new UnsupportedOperationException(); |
703 |
} |
704 |
|
705 |
public DynField addDynFieldFloat(String name) { |
706 |
throw new UnsupportedOperationException(); |
707 |
} |
708 |
|
709 |
public DynField addDynFieldBoolean(String name) { |
710 |
throw new UnsupportedOperationException(); |
711 |
} |
712 |
|
713 |
public DynField addDynFieldList(String name) { |
714 |
throw new UnsupportedOperationException(); |
715 |
} |
716 |
|
717 |
public DynField addDynFieldMap(String name) { |
718 |
throw new UnsupportedOperationException(); |
719 |
} |
720 |
|
721 |
public DynField addDynFieldObject(String name) { |
722 |
throw new UnsupportedOperationException(); |
723 |
} |
724 |
|
725 |
public DynField addDynFieldSet(String name) { |
726 |
throw new UnsupportedOperationException(); |
727 |
} |
728 |
|
729 |
public DynField addDynFieldArray(String name) { |
730 |
throw new UnsupportedOperationException(); |
731 |
} |
732 |
|
733 |
public DynField addDynFieldDate(String name) { |
734 |
throw new UnsupportedOperationException(); |
735 |
} |
736 |
|
737 |
public void extend(DynStruct struct) { |
738 |
throw new UnsupportedOperationException(); |
739 |
} |
740 |
|
741 |
public String getFullName() { |
742 |
// TODO: usar el DynClassName
|
743 |
return this.id; |
744 |
} |
745 |
|
746 |
public String getNamespace() { |
747 |
return "DALFeature"; |
748 |
} |
749 |
|
750 |
public DynStruct[] getSuperDynStructs() { |
751 |
return null; |
752 |
} |
753 |
|
754 |
public void setDescription(String description) { |
755 |
throw new UnsupportedOperationException(); |
756 |
} |
757 |
|
758 |
public void setNamespace(String namespace) { |
759 |
throw new UnsupportedOperationException(); |
760 |
} |
761 |
|
762 |
public DynField addDynFieldFile(String name) { |
763 |
throw new UnsupportedOperationException(); |
764 |
} |
765 |
|
766 |
public DynField addDynFieldFolder(String name) { |
767 |
throw new UnsupportedOperationException(); |
768 |
} |
769 |
|
770 |
public DynField addDynFieldURL(String name) { |
771 |
throw new UnsupportedOperationException(); |
772 |
} |
773 |
|
774 |
public DynField addDynFieldURI(String name) { |
775 |
throw new UnsupportedOperationException(); |
776 |
} |
777 |
|
778 |
public boolean isExtendable(DynStruct dynStruct) { |
779 |
return false; |
780 |
} |
781 |
|
782 |
public void extend(DynStruct[] structs) { |
783 |
// TODO Auto-generated method stub
|
784 |
|
785 |
} |
786 |
|
787 |
public void remove(DynStruct superDynStruct) { |
788 |
// TODO Auto-generated method stub
|
789 |
|
790 |
} |
791 |
|
792 |
public void removeAll(DynStruct[] superDynStruct) { |
793 |
// TODO Auto-generated method stub
|
794 |
|
795 |
} |
796 |
|
797 |
public FeatureAttributeDescriptor getDefaultTimeAttribute() {
|
798 |
if (this.defaultTimeAttributeIndex < 0) { |
799 |
return null; |
800 |
} |
801 |
return (FeatureAttributeDescriptor) super |
802 |
.get(this.defaultTimeAttributeIndex);
|
803 |
} |
804 |
|
805 |
public void setDefaultTimeAttributeName(String name) { |
806 |
if (name == null || name.length() == 0) { |
807 |
this.defaultTimeAttributeIndex = -1; |
808 |
return;
|
809 |
} |
810 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
|
811 |
if (attr == null) { |
812 |
throw new IllegalArgumentException("Attribute '" + name + "' not found."); |
813 |
} |
814 |
if( attr.getIndex()<0 ) { |
815 |
fixAll(); |
816 |
} |
817 |
this.defaultTimeAttributeIndex = attr.getIndex();
|
818 |
} |
819 |
|
820 |
protected void fixAll() { |
821 |
int i = 0; |
822 |
Iterator iter = super.iterator(); |
823 |
DefaultFeatureAttributeDescriptor attr; |
824 |
|
825 |
while (iter.hasNext()) {
|
826 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
827 |
attr.setIndex(i++); |
828 |
attr.fixAll(); |
829 |
if (attr.getEvaluator() != null) { |
830 |
this.hasEvaluators = true; |
831 |
} |
832 |
if (attr.getFeatureAttributeEmulator() != null) { |
833 |
this.hasEmulators = true; |
834 |
String[] x = attr.getFeatureAttributeEmulator().getRequiredFieldNames(); |
835 |
if( !ArrayUtils.isEmpty(x) ) {
|
836 |
this.requiredFields = true; |
837 |
} |
838 |
} |
839 |
switch(attr.getType()) {
|
840 |
case DataTypes.GEOMETRY:
|
841 |
if (this.defaultGeometryAttributeName == null ) { |
842 |
this.defaultGeometryAttributeName = attr.getName();
|
843 |
} |
844 |
break;
|
845 |
case DataTypes.INSTANT:
|
846 |
case DataTypes.INTERVAL:
|
847 |
case DataTypes.DATE:
|
848 |
if (this.defaultTimeAttributeName == null && attr.isTime() ) { |
849 |
this.defaultTimeAttributeName = attr.getName();
|
850 |
} |
851 |
break;
|
852 |
} |
853 |
} |
854 |
if (this.defaultGeometryAttributeName != null) { |
855 |
this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
856 |
} |
857 |
if (this.defaultTimeAttributeName != null) { |
858 |
this.defaultTimeAttributeIndex = this.getIndex(this.defaultTimeAttributeName); |
859 |
} |
860 |
this.internalID = Long.toHexString(this.getCRC()); |
861 |
|
862 |
} |
863 |
|
864 |
protected long getCRC() { |
865 |
StringBuffer buffer = new StringBuffer(); |
866 |
for (int i = 0; i < this.size(); i++) { |
867 |
FeatureAttributeDescriptor x = this.getAttributeDescriptor(i);
|
868 |
buffer.append(x.getName()); |
869 |
buffer.append(x.getDataTypeName()); |
870 |
buffer.append(x.getSize()); |
871 |
} |
872 |
CRC32 crc = new CRC32(); |
873 |
byte[] data = buffer.toString().getBytes(); |
874 |
crc.update(data); |
875 |
return crc.getValue();
|
876 |
} |
877 |
|
878 |
@Override
|
879 |
public FeatureStore getStore() {
|
880 |
if( this.storeRef == null ) { |
881 |
return null; |
882 |
} |
883 |
return (FeatureStore) this.storeRef.get(); |
884 |
} |
885 |
|
886 |
} |