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