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