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