Revision 42293

View differences:

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/DefaultFeatureStore.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
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 10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
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 15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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.
19 20
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22 23
 */
24

  
23 25
package org.gvsig.fmap.dal.feature.impl;
24 26

  
25 27
import java.util.ArrayList;
......
145 147
import org.gvsig.tools.visitor.Visitor;
146 148

  
147 149
public class DefaultFeatureStore extends AbstractDisposable implements
148
        DataStoreInitializer, FeatureStoreProviderServices, FeatureStore, Observer {
150
    DataStoreInitializer, FeatureStoreProviderServices, FeatureStore, Observer {
149 151

  
150 152
    private static final Logger LOG = LoggerFactory
151
            .getLogger(DefaultFeatureStore.class);
153
        .getLogger(DefaultFeatureStore.class);
152 154

  
153 155
    private static final String PERSISTENCE_DEFINITION_NAME = "FeatureStore";
154 156

  
......
156 158
    private FeatureSelection selection;
157 159
    private FeatureLocks locks;
158 160

  
159
    private DelegateWeakReferencingObservable delegateObservable
160
            = new DelegateWeakReferencingObservable(this);
161
    private DelegateWeakReferencingObservable delegateObservable =
162
        new DelegateWeakReferencingObservable(this);
161 163

  
162 164
    private FeatureCommandsStack commands;
163 165
    private FeatureTypeManager featureTypeManager;
......
198 200
     * featureType al que se le han cambiado las reglas de validacion cuando
199 201
     * hasStrongChanges=false.
200 202
     */
203

  
201 204
    public DefaultFeatureStore() {
202 205

  
203 206
    }
204 207

  
205 208
    public void intializePhase1(DataManager dataManager,
206
            DataStoreParameters parameters) throws InitializeException {
209
        DataStoreParameters parameters) throws InitializeException {
207 210

  
208 211
        DynObjectManager dynManager = ToolsLocator.getDynObjectManager();
209 212

  
210
        this.metadata
211
                = (DelegatedDynObject) dynManager.createDynObject(
212
                        METADATA_DEFINITION_NAME, MetadataManager.METADATA_NAMESPACE);
213
        this.metadata =
214
            (DelegatedDynObject) dynManager.createDynObject(
215
                METADATA_DEFINITION_NAME, MetadataManager.METADATA_NAMESPACE);
213 216

  
214 217
        this.dataManager = (DefaultDataManager) dataManager;
215 218

  
......
264 267
            // TODO: Se puede hacer un open estando en edicion ?
265 268
            try {
266 269
                throw new IllegalStateException();
267
            } catch (Exception ex) {
268
                LOG.warn("Opening a store in editing/append mode (" + this.getFullName() + ").", ex);
270
            } catch(Exception ex) {
271
                LOG.warn("Opening a store in editing/append mode ("+this.getFullName()+").",ex);
269 272
            }
270 273
        }
271 274
        this.notifyChange(DataStoreNotification.BEFORE_OPEN);
......
288 291
            // TODO: Se puede hacer un close estando en edicion ?
289 292
            try {
290 293
                throw new IllegalStateException();
291
            } catch (Exception ex) {
292
                LOG.warn("Clossing a store in editing/append mode (" + this.getFullName() + ").", ex);
294
            } catch(Exception ex) {
295
                LOG.warn("Clossing a store in editing/append mode ("+this.getFullName()+").",ex);
293 296
            }
294 297
        }
295 298
        this.notifyChange(DataStoreNotification.BEFORE_CLOSE);
......
303 306
            // TODO: Se puede hacer un dispose estando en edicion ?
304 307
            try {
305 308
                throw new IllegalStateException();
306
            } catch (Exception ex) {
307
                LOG.warn("Dispossing a store in editing/append mode (" + this.getFullName() + ").", ex);
309
            } catch(Exception ex) {
310
                LOG.warn("Dispossing a store in editing/append mode ("+this.getFullName()+").",ex);
308 311
            }
309 312
        }
310 313
        this.notifyChange(DataStoreNotification.BEFORE_DISPOSE);
......
339 342

  
340 343
    public boolean allowWrite() {
341 344
        SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager();
342
        if (!identityManager.getCurrentIdentity().isAuthorized(DataManager.WRITE_STORE_AUTHORIZATION, this.getParameters(), this.getName())) {
345
        if( ! identityManager.getCurrentIdentity().isAuthorized(DataManager.WRITE_STORE_AUTHORIZATION,this.getParameters(), this.getName()) ) {
343 346
            return false;
344 347
        }
345 348
        return this.provider.allowWrite();
......
350 353
    }
351 354

  
352 355
    public DataServerExplorer getExplorer() throws ReadException,
353
            ValidateDataParametersException {
356
        ValidateDataParametersException {
354 357
        return this.provider.getExplorer();
355 358
    }
356 359

  
......
365 368
     * return this.provider.getMetadata();
366 369
     * }
367 370
     */
371

  
368 372
    public Envelope getEnvelope() throws DataException {
369 373
        if (this.mode == MODE_FULLEDIT) {
370
            // Just in case another thread tries to write in the store
371
            synchronized (this) {
372
                return this.spatialManager.getEnvelope();
373
            }
374
        	// Just in case another thread tries to write in the store
375
        	synchronized (this) {
376
        		return this.spatialManager.getEnvelope();
377
			}
374 378
        }
375
        if (hasDynValue(DataStore.METADATA_ENVELOPE)) {
376
            return (Envelope) getDynValue(DataStore.METADATA_ENVELOPE);
379
        if (hasDynValue(DataStore.METADATA_ENVELOPE)){
380
            return (Envelope)getDynValue(DataStore.METADATA_ENVELOPE);
377 381
        }
378 382
        return this.provider.getEnvelope();
379 383
    }
......
386 390
    }
387 391

  
388 392
    public FeatureSelection createDefaultFeatureSelection()
389
            throws DataException {
393
        throws DataException {
390 394
        return new DefaultFeatureSelection(this);
391 395
    }
392 396

  
393 397
    public FeatureProvider createDefaultFeatureProvider(FeatureType type)
394
            throws DataException {
398
        throws DataException {
395 399
        if (type.hasOID()) {
396 400
            return new DefaultFeatureProvider(type,
397
                    this.provider.createNewOID());
401
                this.provider.createNewOID());
398 402
        }
399 403
        return new DefaultFeatureProvider(type);
400 404
    }
401 405

  
402 406
    public void saveToState(PersistentState state) throws PersistenceException {
403 407
        /*if (this.mode != FeatureStore.MODE_QUERY) {
404
         throw new PersistenceException(new IllegalStateException(
405
         this.getName()));
406
         }*/
408
            throw new PersistenceException(new IllegalStateException(
409
                this.getName()));
410
        }*/
407 411
        state.set("dataStoreName", this.getName());
408 412
        state.set("parameters", this.parameters);
409 413
        state.set("selection", this.selection);
......
425 429
            while (iterAttr.hasNext()) {
426 430
                attr = (DefaultFeatureAttributeDescriptor) iterAttr.next();
427 431
                if ((attr.getEvaluator() != null)
428
                        && (attr.getEvaluator() instanceof Persistent)) {
432
                    && (attr.getEvaluator() instanceof Persistent)) {
429 433
                    attrs.add(attr);
430 434
                }
431 435
            }
......
445 449
    }
446 450

  
447 451
    public void loadFromState(PersistentState state)
448
            throws PersistenceException {
452
        throws PersistenceException {
449 453
        if (this.provider != null) {
450 454
            throw new PersistenceStoreAlreadyLoadedException(this.getName());
451 455
        }
......
453 457
            this.dataManager = (DefaultDataManager) DALLocator.getDataManager();
454 458
        }
455 459

  
456
        DataStoreParameters params
457
                = (DataStoreParameters) state.get("parameters");
460
        DataStoreParameters params =
461
            (DataStoreParameters) state.get("parameters");
458 462

  
459 463
        try {
460 464

  
461 465
            this.dataManager.intializeDataStore(this, params);
462 466
            this.selection = (FeatureSelection) state.get("selection");
463
            this.transforms
464
                    = (DefaultFeatureStoreTransforms) state.get("transforms");
467
            this.transforms =
468
                (DefaultFeatureStoreTransforms) state.get("transforms");
465 469
            Map evaluatedAttributes = (Map) state.get("evaluatedAttributes");
466 470
            if ((evaluatedAttributes != null) && !evaluatedAttributes.isEmpty()) {
467 471
                List attrs;
468
                Iterator iterEntries
469
                        = evaluatedAttributes.entrySet().iterator();
472
                Iterator iterEntries =
473
                    evaluatedAttributes.entrySet().iterator();
470 474
                Entry entry;
471 475
                while (iterEntries.hasNext()) {
472 476
                    entry = (Entry) iterEntries.next();
......
485 489
                    }
486 490
                    if (fTypePos < 0) {
487 491
                        throw new PersistenceCantFindFeatureTypeException(
488
                                this.getName(), (String) entry.getKey());
492
                            this.getName(), (String) entry.getKey());
489 493
                    }
490
                    DefaultEditableFeatureType eType
491
                            = (DefaultEditableFeatureType) type.getEditable();
494
                    DefaultEditableFeatureType eType =
495
                        (DefaultEditableFeatureType) type.getEditable();
492 496
                    Iterator iterAttr = attrs.iterator();
493 497
                    FeatureAttributeDescriptor attr;
494 498
                    while (iterAttr.hasNext()) {
......
504 508
            String defFTypeid = state.getString("defaultFeatureTypeId");
505 509
            FeatureType ftype = null;
506 510

  
507
            if (this.defaultFeatureType == null
508
                    || this.defaultFeatureType.getId() == null
509
                    || !this.defaultFeatureType.getId().equals(
510
                            state.getString("defaultFeatureTypeId"))) {
511
            if (this.defaultFeatureType == null ||
512
                this.defaultFeatureType.getId() == null ||
513
                !this.defaultFeatureType.getId().equals(
514
                state.getString("defaultFeatureTypeId"))) {
511 515

  
512 516
                ftype = getFeatureType(defFTypeid);
513 517
                if (ftype == null) {
514 518
                    throw new PersistenceCantFindDefaultFeatureTypeException(
515
                            this.getName(), defFTypeid);
519
                        this.getName(), defFTypeid);
516 520
                }
517 521
                this.defaultFeatureType = ftype;
518 522
            }
......
528 532
    public static void registerPersistenceDefinition() {
529 533
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
530 534
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
531
            DynStruct definition
532
                    = manager.addDefinition(DefaultFeatureStore.class,
533
                            PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME
534
                            + " Persistent definition", null, null);
535
            DynStruct definition =
536
                manager.addDefinition(DefaultFeatureStore.class,
537
                    PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME
538
                        + " Persistent definition", null, null);
535 539
            definition.addDynFieldString("dataStoreName").setMandatory(true)
536
                    .setPersistent(true);
540
                .setPersistent(true);
537 541

  
538 542
            definition.addDynFieldObject("parameters")
539
                    .setClassOfValue(DynObject.class).setMandatory(true)
540
                    .setPersistent(true);
543
                .setClassOfValue(DynObject.class).setMandatory(true)
544
                .setPersistent(true);
541 545

  
542 546
            definition.addDynFieldObject("selection")
543
                    .setClassOfValue(FeatureSelection.class).setMandatory(false)
544
                    .setPersistent(true);
547
                .setClassOfValue(FeatureSelection.class).setMandatory(false)
548
                .setPersistent(true);
545 549

  
546 550
            definition.addDynFieldObject("transforms")
547
                    .setClassOfValue(DefaultFeatureStoreTransforms.class)
548
                    .setMandatory(true).setPersistent(true);
551
                .setClassOfValue(DefaultFeatureStoreTransforms.class)
552
                .setMandatory(true).setPersistent(true);
549 553

  
550 554
            definition.addDynFieldMap("evaluatedAttributes")
551
                    .setClassOfItems(List.class) // List<DefaultFeatureAttributeDescriptor>
552
                    .setMandatory(false).setPersistent(true);
555
                .setClassOfItems(List.class) // List<DefaultFeatureAttributeDescriptor>
556
                .setMandatory(false).setPersistent(true);
553 557

  
554 558
            definition.addDynFieldString("defaultFeatureTypeId")
555
                    .setMandatory(true).setPersistent(true);
559
                .setMandatory(true).setPersistent(true);
556 560
        }
557 561
    }
558 562

  
559 563
    public static void registerMetadataDefinition() throws MetadataException {
560 564
        MetadataManager manager = MetadataLocator.getMetadataManager();
561 565
        if (manager.getDefinition(METADATA_DEFINITION_NAME) == null) {
562
            DynStruct metadataDefinition
563
                    = manager.addDefinition(METADATA_DEFINITION_NAME, null);
566
            DynStruct metadataDefinition =
567
                manager.addDefinition(METADATA_DEFINITION_NAME, null);
564 568
            metadataDefinition.extend(manager
565
                    .getDefinition(DataStore.METADATA_DEFINITION_NAME));
569
                .getDefinition(DataStore.METADATA_DEFINITION_NAME));
566 570
        }
567 571
    }
568 572

  
......
570 574
    // ====================================================================
571 575
    // Gestion de la seleccion
572 576
    //
577

  
573 578
    public void setSelection(DataSet selection) throws DataException {
574 579
        this.setSelection((FeatureSet) selection);
575 580
    }
......
588 593

  
589 594
    /**
590 595
     * @see #setSelection(FeatureSet)
591
     * @param undoable if the action must be undoable
596
     * @param undoable
597
     *            if the action must be undoable
592 598
     */
593 599
    public void setSelection(FeatureSet selection, boolean undoable)
594
            throws DataException {
600
        throws DataException {
595 601
        if (selection == null) {
596 602
            if (undoable) {
597 603
                throw new SelectionNotAllowedException(getName());
......
619 625
        if (selection instanceof FeatureSelection) {
620 626
            if (undoable && isEditing()) {
621 627
                commands.selectionSet(this, this.selection,
622
                        (FeatureSelection) selection);
628
                    (FeatureSelection) selection);
623 629
            }
624 630
            if (this.selection != null) {
625 631
                this.selection.dispose();
......
630 636
                commands.startComplex("_selectionSet");
631 637
            }
632 638
            if (selection instanceof DefaultFeatureSelection) {
633
                DefaultFeatureSelection defSelection
634
                        = (DefaultFeatureSelection) selection;
639
                DefaultFeatureSelection defSelection =
640
                    (DefaultFeatureSelection) selection;
635 641
                defSelection.deselectAll(undoable);
636 642
                defSelection.select(selection, undoable);
637 643
            } else {
......
663 669
    // ====================================================================
664 670
    // Gestion de notificaciones
665 671
    //
672

  
666 673
    public void notifyChange(String notification) {
667 674
        if (delegateObservable != null) {
668 675
            notifyChange(new DefaultFeatureStoreNotification(this, notification));
......
675 682
            notifyChange(notification, createFeature(data));
676 683
        } catch (DataException ex) {
677 684
            LOG.error("Error notifying about the notification: " + notification
678
                    + ", with the data: " + data, ex);
685
                + ", with the data: " + data, ex);
679 686
        }
680 687
    }
681 688

  
682 689
    public void notifyChange(String notification, Feature feature) {
683 690
        notifyChange(new DefaultFeatureStoreNotification(this, notification,
684
                feature));
691
            feature));
685 692
    }
686 693

  
687 694
    public void notifyChange(String notification, Command command) {
688 695
        notifyChange(new DefaultFeatureStoreNotification(this, notification,
689
                command));
696
            command));
690 697
    }
691 698

  
692 699
    public void notifyChange(String notification, EditableFeatureType type) {
693 700
        notifyChange(new DefaultFeatureStoreNotification(this, notification,
694
                type));
701
            type));
695 702
    }
696 703

  
697 704
    public void notifyChange(FeatureStoreNotification storeNotification) {
......
700 707

  
701 708
    public void notifyChange(String notification, Resource resource) {
702 709
        notifyChange(new DefaultFeatureStoreNotification(this,
703
                DataStoreNotification.RESOURCE_CHANGED));
710
            DataStoreNotification.RESOURCE_CHANGED));
704 711
    }
705 712

  
706 713
    //
707 714
    // ====================================================================
708 715
    // Gestion de bloqueos
709 716
    //
717

  
710 718
    public boolean isLocksSupported() {
711 719
        return this.provider.isLocksSupported();
712 720
    }
......
726 734
    // ====================================================================
727 735
    // Interface Observable
728 736
    //
737

  
729 738
    public void disableNotifications() {
730 739
        this.delegateObservable.disableNotifications();
731 740

  
......
771 780
    // - sus bloqueos
772 781
    // - sus recursos
773 782
    //
783

  
774 784
    public void update(Observable observable, Object notification) {
775 785
        if (observable instanceof FeatureSet) {
776 786
            if (observable == this.selection) {
777 787
                this.notifyChange(DataStoreNotification.SELECTION_CHANGE);
778
            } else if (observable == this.locks) {
779
                this.notifyChange(FeatureStoreNotification.LOCKS_CHANGE);
780
            }
788
            } else
789
                if (observable == this.locks) {
790
                    this.notifyChange(FeatureStoreNotification.LOCKS_CHANGE);
791
                }
781 792

  
782
        } else if (observable instanceof FeatureStoreProvider) {
783
            if (observable == this.provider) {
793
        } else
794
            if (observable instanceof FeatureStoreProvider) {
795
                if (observable == this.provider) {
784 796

  
797
                }
798

  
785 799
            }
786

  
787
        }
788 800
    }
789 801

  
790 802
    //
791 803
    // ====================================================================
792 804
    // Edicion
793 805
    //
806

  
794 807
    private void newVersionOfUpdate() {
795 808
        this.versionOfUpdate++;
796 809
    }
......
807 820

  
808 821
    private void checkNotInAppendMode() throws IllegalStateException {
809 822
        if (mode == MODE_APPEND) {
810
            throw new IllegalStateException("Error: store "
811
                    + this.getFullName() + " is in append mode");
823
			throw new IllegalStateException("Error: store "
824
					+ this.getFullName() + " is in append mode");
812 825
        }
813 826
    }
814 827

  
815 828
    private void checkIsOwnFeature(Feature feature)
816
            throws IllegalFeatureException {
829
        throws IllegalFeatureException {
817 830
        if (((DefaultFeature) feature).getStore() != this) {
818 831
            throw new IllegalFeatureException(this.getName());
819 832
        }
......
858 871
                mode = MODE_FULLEDIT;
859 872
            }
860 873
            switch (mode) {
861
                case MODE_QUERY:
874
            case MODE_QUERY:
875
                throw new IllegalStateException(this.getName());
876

  
877
            case MODE_FULLEDIT:
878
                if (!this.transforms.isEmpty()) {
862 879
                    throw new IllegalStateException(this.getName());
880
                }
881
                notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING);
882
                invalidateIndexes();
883
                featureManager =
884
                    new FeatureManager(new MemoryExpansionAdapter());
885
                featureTypeManager =
886
                    new FeatureTypeManager(this, new MemoryExpansionAdapter());
887
                spatialManager =
888
                    new SpatialManager(this, provider.getEnvelope());
863 889

  
864
                case MODE_FULLEDIT:
865
                    if (!this.transforms.isEmpty()) {
866
                        throw new IllegalStateException(this.getName());
867
                    }
868
                    notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING);
869
                    invalidateIndexes();
870
                    featureManager
871
                            = new FeatureManager(new MemoryExpansionAdapter());
872
                    featureTypeManager
873
                            = new FeatureTypeManager(this, new MemoryExpansionAdapter());
874
                    spatialManager
875
                            = new SpatialManager(this, provider.getEnvelope());
876

  
877
                    commands
878
                            = new DefaultFeatureCommandsStack(this, featureManager,
879
                                    spatialManager, featureTypeManager);
880
                    this.mode = MODE_FULLEDIT;
881
                    hasStrongChanges = false;
882
                    hasInserts = false;
883
                    notifyChange(FeatureStoreNotification.AFTER_STARTEDITING);
884
                    break;
885
                case MODE_APPEND:
886
                    if (!this.transforms.isEmpty()) {
887
                        throw new IllegalStateException(this.getName());
888
                    }
889
                    notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING);
890
                    invalidateIndexes();
891
                    this.provider.beginAppend();
892
                    this.mode = MODE_APPEND;
893
                    hasInserts = false;
894
                    notifyChange(FeatureStoreNotification.AFTER_STARTEDITING);
895
                    break;
890
                commands =
891
                    new DefaultFeatureCommandsStack(this, featureManager,
892
                        spatialManager, featureTypeManager);
893
                this.mode = MODE_FULLEDIT;
894
                hasStrongChanges = false;
895
                hasInserts = false;
896
                notifyChange(FeatureStoreNotification.AFTER_STARTEDITING);
897
                break;
898
            case MODE_APPEND:
899
                if (!this.transforms.isEmpty()) {
900
                    throw new IllegalStateException(this.getName());
901
                }
902
                notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING);
903
                invalidateIndexes();
904
                this.provider.beginAppend();
905
                this.mode = MODE_APPEND;
906
                hasInserts = false;
907
                notifyChange(FeatureStoreNotification.AFTER_STARTEDITING);
908
                break;
896 909
            }
897 910
        } catch (Exception e) {
898 911
            throw new StoreEditException(e, this.getName());
......
906 919
    private void setIndexesValidStatus(boolean valid) {
907 920
        FeatureIndexes indexes = getIndexes();
908 921
        LOG.debug("Setting the store indexes to valid status {}: {}", (valid
909
                ? Boolean.TRUE : Boolean.FALSE), indexes);
922
            ? Boolean.TRUE : Boolean.FALSE), indexes);
910 923
        for (Iterator iterator = indexes.iterator(); iterator.hasNext();) {
911 924
            FeatureIndex index = (FeatureIndex) iterator.next();
912 925
            if (index instanceof FeatureIndexProviderServices) {
913
                FeatureIndexProviderServices indexServices
914
                        = (FeatureIndexProviderServices) index;
926
                FeatureIndexProviderServices indexServices =
927
                    (FeatureIndexProviderServices) index;
915 928
                indexServices.setValid(valid);
916 929
            }
917 930
        }
......
923 936
        for (Iterator iterator = indexes.iterator(); iterator.hasNext();) {
924 937
            FeatureIndex index = (FeatureIndex) iterator.next();
925 938
            if (index instanceof FeatureIndexProviderServices) {
926
                FeatureIndexProviderServices indexServices
927
                        = (FeatureIndexProviderServices) index;
939
                FeatureIndexProviderServices indexServices =
940
                    (FeatureIndexProviderServices) index;
928 941
                indexServices.fill(true, null);
929 942
            }
930 943
        }
......
936 949
        for (Iterator iterator = indexes.iterator(); iterator.hasNext();) {
937 950
            FeatureIndex index = (FeatureIndex) iterator.next();
938 951
            if (index instanceof FeatureIndexProviderServices) {
939
                FeatureIndexProviderServices indexServices
940
                        = (FeatureIndexProviderServices) index;
952
                FeatureIndexProviderServices indexServices =
953
                    (FeatureIndexProviderServices) index;
941 954
                indexServices.waitForIndex();
942 955
            }
943 956
        }
......
949 962
        for (Iterator iterator = indexes.iterator(); iterator.hasNext();) {
950 963
            FeatureIndex index = (FeatureIndex) iterator.next();
951 964
            if (index instanceof FeatureIndexProviderServices) {
952
                FeatureIndexProviderServices indexServices
953
                        = (FeatureIndexProviderServices) index;
965
                FeatureIndexProviderServices indexServices =
966
                    (FeatureIndexProviderServices) index;
954 967
                indexServices.dispose();
955 968
            }
956 969
        }
......
965 978
    }
966 979

  
967 980
    synchronized public void update(EditableFeatureType type)
968
            throws DataException {
981
        throws DataException {
969 982
        try {
970 983
            checkInEditingMode();
971 984
            if (type == null) {
......
1016 1029
    private static EditableFeature lastChangedFeature = null;
1017 1030

  
1018 1031
    public synchronized void insert(EditableFeature feature)
1019
            throws DataException {
1032
        throws DataException {
1020 1033
        LOG.debug("In editing mode {}, insert feature: {}", new Integer(mode),
1021
                feature);
1034
            feature);
1022 1035
        try {
1023 1036
            switch (mode) {
1024
                case MODE_QUERY:
1025
                    throw new NeedEditingModeException(this.getName());
1037
            case MODE_QUERY:
1038
                throw new NeedEditingModeException(this.getName());
1026 1039

  
1027
                case MODE_APPEND:
1028
                    checkIsOwnFeature(feature);
1029
                    if (feature.getSource() != null) {
1030
                        throw new NoNewFeatureInsertException(this.getName());
1031
                    }
1032
                    this.featureCount = null;
1033
                    notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature);
1034
                    feature.validate(Feature.UPDATE);
1035
                    provider.append(((DefaultEditableFeature) feature).getData());
1036
                    hasStrongChanges = true;
1037
                    hasInserts = true;
1038
                    notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
1039
                    break;
1040
            case MODE_APPEND:
1041
                checkIsOwnFeature(feature);
1042
                if (feature.getSource() != null) {
1043
                    throw new NoNewFeatureInsertException(this.getName());
1044
                }
1045
                this.featureCount = null;
1046
                notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature);
1047
                feature.validate(Feature.UPDATE);
1048
                provider.append(((DefaultEditableFeature) feature).getData());
1049
                hasStrongChanges = true;
1050
                hasInserts = true;
1051
                notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
1052
                break;
1040 1053

  
1041
                case MODE_FULLEDIT:
1042
                    if (feature.getSource() != null) {
1043
                        throw new NoNewFeatureInsertException(this.getName());
1044
                    }
1045
                    commands.insert(feature);
1054
            case MODE_FULLEDIT:
1055
                if (feature.getSource() != null) {
1056
                    throw new NoNewFeatureInsertException(this.getName());
1057
                }
1058
                commands.insert(feature);
1046 1059
            }
1047 1060
        } catch (Exception e) {
1048 1061
            throw new StoreInsertFeatureException(e, this.getName());
......
1050 1063
    }
1051 1064

  
1052 1065
    synchronized public void doInsert(EditableFeature feature)
1053
            throws DataException {
1066
        throws DataException {
1054 1067
        checkIsOwnFeature(feature);
1055 1068

  
1056 1069
        waitForIndexes();
......
1058 1071
        notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature);
1059 1072
        newVersionOfUpdate();
1060 1073
        if ((lastChangedFeature == null)
1061
                || (lastChangedFeature.getSource() != feature.getSource())) {
1074
            || (lastChangedFeature.getSource() != feature.getSource())) {
1062 1075
            lastChangedFeature = feature;
1063 1076
            feature.validate(Feature.UPDATE);
1064 1077
            lastChangedFeature = null;
......
1067 1080
        ((DefaultEditableFeature) feature).setInserted(true);
1068 1081
        DefaultFeature newFeature = (DefaultFeature) feature.getNotEditableCopy();
1069 1082

  
1083

  
1070 1084
        featureManager.add(newFeature);
1071 1085
        spatialManager.insertFeature(newFeature);
1072 1086

  
......
1076 1090
    }
1077 1091

  
1078 1092
    public void update(EditableFeature feature)
1079
            throws DataException {
1093
    throws DataException {
1080 1094
        if ((feature).getSource() == null) {
1081 1095
            insert(feature);
1082 1096
            return;
......
1085 1099
    }
1086 1100

  
1087 1101
    synchronized public void doUpdate(EditableFeature feature, Feature oldFeature)
1088
            throws DataException {
1102
        throws DataException {
1089 1103
        try {
1090 1104
            checkInEditingMode();
1091 1105
            checkIsOwnFeature(feature);
1092 1106
            notifyChange(FeatureStoreNotification.BEFORE_UPDATE, feature);
1093 1107
            newVersionOfUpdate();
1094 1108
            if ((lastChangedFeature == null)
1095
                    || (lastChangedFeature.getSource() != feature.getSource())) {
1109
                || (lastChangedFeature.getSource() != feature.getSource())) {
1096 1110
                lastChangedFeature = feature;
1097 1111
                feature.validate(Feature.UPDATE);
1098 1112
                lastChangedFeature = null;
......
1155 1169
    }
1156 1170

  
1157 1171
    public synchronized FeatureCommandsStack getCommandsStack()
1158
            throws DataException {
1172
        throws DataException {
1159 1173
        checkInEditingMode();
1160 1174
        return commands;
1161 1175
    }
......
1193 1207
            ((FeatureSelection) this.getSelection()).deselectAll();
1194 1208

  
1195 1209
            switch (mode) {
1196
                case MODE_QUERY:
1197
                    throw new NeedEditingModeException(this.getName());
1210
            case MODE_QUERY:
1211
                throw new NeedEditingModeException(this.getName());
1198 1212

  
1199
                case MODE_APPEND:
1200
                    notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1201
                    provider.endAppend();
1202
                    exitEditingMode();
1203
                    updateIndexes();
1204
                    notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1205
                    break;
1213
            case MODE_APPEND:
1214
                notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1215
                provider.endAppend();
1216
                exitEditingMode();
1217
                updateIndexes();
1218
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1219
                break;
1206 1220

  
1207
                case MODE_FULLEDIT:
1208
                    if (hasStrongChanges && !this.allowWrite()) {
1209
                        throw new WriteNotAllowedException(getName());
1210
                    }
1211
                    notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1212
                    if (hasStrongChanges) {
1213
                        validateFeatures(Feature.FINISH_EDITING);
1221
            case MODE_FULLEDIT:
1222
                if (hasStrongChanges && !this.allowWrite()) {
1223
                    throw new WriteNotAllowedException(getName());
1224
                }
1225
                notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1226
                if (hasStrongChanges) {
1227
                    validateFeatures(Feature.FINISH_EDITING);
1214 1228

  
1215
                        /*
1216
                         * This will throw a PerformEditingExceptionif the provider
1217
                         * does not accept the changes (for example, an invalid field name)
1218
                         */
1219
                        provider.performChanges(featureManager.getDeleted(),
1220
                                featureManager.getInserted(),
1221
                                featureManager.getUpdated(),
1222
                                featureTypeManager.getFeatureTypesChanged());
1223
                    }
1224
                    exitEditingMode();
1225
                    updateIndexes();
1226
                    notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1227
                    break;
1229
                    /*
1230
                     * This will throw a PerformEditingExceptionif the provider
1231
                     * does not accept the changes (for example, an invalid field name)
1232
                     */
1233
                    provider.performChanges(featureManager.getDeleted(),
1234
                        featureManager.getInserted(),
1235
                        featureManager.getUpdated(),
1236
                        featureTypeManager.getFeatureTypesChanged());
1237
                }
1238
                exitEditingMode();
1239
                updateIndexes();
1240
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1241
                break;
1228 1242
            }
1229 1243
        } catch (PerformEditingException pee) {
1230 1244
            throw new WriteException(provider.getSourceId().toString(), pee);
......
1234 1248
    }
1235 1249

  
1236 1250
    /**
1237
     * Save changes in the provider without leaving the edit mode. Do not call
1238
     * observers to communicate a change of ediding mode. The operation's
1239
     * history is eliminated to prevent inconsistencies in the data.
1251
     * Save changes in the provider without leaving the edit mode.
1252
     * Do not call observers to communicate a change of ediding mode.
1253
     * The operation's history is eliminated to prevent inconsistencies
1254
     * in the data.
1240 1255
     *
1241 1256
     * @throws DataException
1242 1257
     */
1243 1258
    synchronized public void commitChanges() throws DataException {
1244
        LOG.debug("commitChanges of mode: {}", new Integer(mode));
1245
        if (!canCommitChanges()) {
1246
            throw new WriteNotAllowedException(getName());
1247
        }
1248
        try {
1249
            switch (mode) {
1250
                case MODE_QUERY:
1251
                    throw new NeedEditingModeException(this.getName());
1259
      LOG.debug("commitChanges of mode: {}", new Integer(mode));
1260
      if( !canCommitChanges() ) {
1261
    	  throw new WriteNotAllowedException(getName());
1262
      }
1263
      try {
1264
        switch (mode) {
1265
        case MODE_QUERY:
1266
          throw new NeedEditingModeException(this.getName());
1252 1267

  
1253
                case MODE_APPEND:
1254
                    this.provider.endAppend();
1255
                    exitEditingMode();
1256
                    invalidateIndexes();
1257
                    this.provider.beginAppend();
1258
                    hasInserts = false;
1259
                    break;
1268
        case MODE_APPEND:
1269
          this.provider.endAppend();
1270
          exitEditingMode();
1271
          invalidateIndexes();
1272
          this.provider.beginAppend();
1273
          hasInserts = false;
1274
          break;
1260 1275

  
1261
                case MODE_FULLEDIT:
1262
                    if (hasStrongChanges && !this.allowWrite()) {
1263
                        throw new WriteNotAllowedException(getName());
1264
                    }
1265
                    if (hasStrongChanges) {
1266
                        validateFeatures(Feature.FINISH_EDITING);
1267
                        provider.performChanges(featureManager.getDeleted(),
1268
                                featureManager.getInserted(),
1269
                                featureManager.getUpdated(),
1270
                                featureTypeManager.getFeatureTypesChanged());
1271
                    }
1272
                    invalidateIndexes();
1273
                    featureManager
1274
                            = new FeatureManager(new MemoryExpansionAdapter());
1275
                    featureTypeManager
1276
                            = new FeatureTypeManager(this, new MemoryExpansionAdapter());
1277
                    spatialManager
1278
                            = new SpatialManager(this, provider.getEnvelope());
1276
        case MODE_FULLEDIT:
1277
          if (hasStrongChanges && !this.allowWrite()) {
1278
            throw new WriteNotAllowedException(getName());
1279
          }
1280
          if (hasStrongChanges) {
1281
            validateFeatures(Feature.FINISH_EDITING);
1282
            provider.performChanges(featureManager.getDeleted(),
1283
              featureManager.getInserted(),
1284
              featureManager.getUpdated(),
1285
              featureTypeManager.getFeatureTypesChanged());
1286
          }
1287
          invalidateIndexes();
1288
          featureManager =
1289
            new FeatureManager(new MemoryExpansionAdapter());
1290
          featureTypeManager =
1291
            new FeatureTypeManager(this, new MemoryExpansionAdapter());
1292
          spatialManager =
1293
            new SpatialManager(this, provider.getEnvelope());
1279 1294

  
1280
                    commands
1281
                            = new DefaultFeatureCommandsStack(this, featureManager,
1282
                                    spatialManager, featureTypeManager);
1283
                    featureCount = null;
1284
                    hasStrongChanges = false;
1285
                    hasInserts = false;
1286
                    break;
1287
            }
1288
        } catch (Exception e) {
1289
            throw new FinishEditingException(e);
1295
          commands =
1296
            new DefaultFeatureCommandsStack(this, featureManager,
1297
              spatialManager, featureTypeManager);
1298
          featureCount = null;
1299
          hasStrongChanges = false;
1300
          hasInserts = false;
1301
          break;
1290 1302
        }
1303
      } catch (Exception e) {
1304
        throw new FinishEditingException(e);
1305
      }
1291 1306
    }
1292 1307

  
1293 1308
    synchronized public boolean canCommitChanges() throws DataException {
1294
        if (!this.allowWrite()) {
1295
            return false;
1309
        if ( !this.allowWrite()) {
1310
        	return false;
1296 1311
        }
1297
        switch (mode) {
1298
            default:
1299
            case MODE_QUERY:
1300
                return false;
1312
    	switch (mode) {
1313
    	default:
1314
        case MODE_QUERY:
1315
        	return false;
1301 1316

  
1302
            case MODE_APPEND:
1303
                return true;
1317
        case MODE_APPEND:
1318
        	return true;
1304 1319

  
1305
            case MODE_FULLEDIT:
1306
                List types = this.getFeatureTypes();
1307
                for (int i = 0; i < types.size(); i++) {
1308
                    Object type = types.get(i);
1309
                    if (type instanceof DefaultEditableFeatureType) {
1310
                        if (((DefaultEditableFeatureType) type).hasStrongChanges()) {
1311
                            return false;
1312
                        }
1313
                    }
1314
                }
1315
                return true;
1316
        }
1320
        case MODE_FULLEDIT:
1321
            List types = this.getFeatureTypes();
1322
            for( int i=0; i<types.size(); i++ ) {
1323
            	Object type = types.get(i);
1324
            	if( type instanceof DefaultEditableFeatureType ) {
1325
	            	if( ((DefaultEditableFeatureType)type).hasStrongChanges() ) {
1326
	            		return false;
1327
	            	}
1328
            	}
1329
            }
1330
            return true;
1331
    	}
1317 1332
    }
1318 1333

  
1319 1334
    public void beginEditingGroup(String description)
1320
            throws NeedEditingModeException {
1335
        throws NeedEditingModeException {
1321 1336
        checkInEditingMode();
1322 1337
        commands.startComplex(description);
1323 1338
    }
......
1332 1347
    }
1333 1348

  
1334 1349
    public void export(DataServerExplorer explorer, String provider,
1335
            NewFeatureStoreParameters params) throws DataException {
1350
        NewFeatureStoreParameters params) throws DataException {
1336 1351

  
1337 1352
        if (this.getFeatureTypes().size() != 1) {
1338 1353
            throw new NotYetImplemented(
1339
                    "export whith more than one type not yet implemented");
1354
                "export whith more than one type not yet implemented");
1340 1355
        }
1341 1356
        FeatureSelection featureSelection = (FeatureSelection) getSelection();
1342 1357
        FeatureStore target = null;
......
1345 1360
        try {
1346 1361
            FeatureType type = this.getDefaultFeatureType();
1347 1362
            if ((params.getDefaultFeatureType() == null)
1348
                    || (params.getDefaultFeatureType().size() == 0)) {
1363
                || (params.getDefaultFeatureType().size() == 0)) {
1349 1364
                params.setDefaultFeatureType(type.getEditable());
1350 1365

  
1351 1366
            }
......
1391 1406
    // Obtencion de datos
1392 1407
    // getDataCollection, getFeatureCollection
1393 1408
    //
1409

  
1394 1410
    public DataSet getDataSet() throws DataException {
1395 1411
        checkNotInAppendMode();
1396
        FeatureQuery query
1397
                = new DefaultFeatureQuery(this.getDefaultFeatureType());
1412
        FeatureQuery query =
1413
            new DefaultFeatureQuery(this.getDefaultFeatureType());
1398 1414
        return new DefaultFeatureSet(this, query);
1399 1415
    }
1400 1416

  
......
1409 1425
    }
1410 1426

  
1411 1427
    public void getDataSet(DataQuery dataQuery, Observer observer)
1412
            throws DataException {
1428
        throws DataException {
1413 1429
        checkNotInAppendMode();
1414 1430
        this.getFeatureSet((FeatureQuery) dataQuery, observer);
1415 1431
    }
1416 1432

  
1417 1433
    public FeatureSet getFeatureSet() throws DataException {
1418 1434
        checkNotInAppendMode();
1419
        FeatureQuery query
1420
                = new DefaultFeatureQuery(this.getDefaultFeatureType());
1435
        FeatureQuery query =
1436
            new DefaultFeatureQuery(this.getDefaultFeatureType());
1421 1437
        return new DefaultFeatureSet(this, query);
1422 1438
    }
1423 1439

  
1424 1440
    public FeatureSet getFeatureSet(FeatureQuery featureQuery)
1425
            throws DataException {
1441
        throws DataException {
1426 1442
        checkNotInAppendMode();
1427 1443
        return new DefaultFeatureSet(this, featureQuery);
1428 1444
    }
......
1437 1453
    }
1438 1454

  
1439 1455
    public void accept(Visitor visitor, DataQuery dataQuery)
1440
            throws BaseException {
1456
        throws BaseException {
1441 1457
        FeatureSet set = getFeatureSet((FeatureQuery) dataQuery);
1442 1458
        try {
1443 1459
            set.accept(visitor);
......
1447 1463
    }
1448 1464

  
1449 1465
    public FeatureType getFeatureType(FeatureQuery featureQuery)
1450
            throws DataException {
1451
        DefaultFeatureType fType
1452
                = (DefaultFeatureType) this.getFeatureType(featureQuery
1453
                        .getFeatureTypeId());
1454
        if (featureQuery.hasAttributeNames() || featureQuery.hasConstantsAttributeNames()) {
1455
            return fType.getSubtype(featureQuery.getAttributeNames(), featureQuery.getConstantsAttributeNames());
1466
        throws DataException {
1467
        DefaultFeatureType fType =
1468
            (DefaultFeatureType) this.getFeatureType(featureQuery
1469
                .getFeatureTypeId());
1470
        if( featureQuery.hasAttributeNames() || featureQuery.hasConstantsAttributeNames() ) {
1471
            return fType.getSubtype(featureQuery.getAttributeNames(), featureQuery.getConstantsAttributeNames() );
1456 1472
        }
1457 1473
        return fType;
1458 1474
    }
......
1463 1479
    }
1464 1480

  
1465 1481
    public void getFeatureSet(FeatureQuery query, Observer observer)
1466
            throws DataException {
1482
        throws DataException {
1467 1483
        class LoadInBackGround implements Runnable {
1468 1484

  
1469 1485
            private FeatureStore store;
......
1471 1487
            private Observer observer;
1472 1488

  
1473 1489
            public LoadInBackGround(FeatureStore store, FeatureQuery query,
1474
                    Observer observer) {
1490
                Observer observer) {
1475 1491
                this.store = store;
1476 1492
                this.query = query;
1477 1493
                this.observer = observer;
......
1487 1503
                try {
1488 1504
                    set = store.getFeatureSet(query);
1489 1505
                    notify(new DefaultFeatureStoreNotification(store,
1490
                            FeatureStoreNotification.LOAD_FINISHED, set));
1506
                        FeatureStoreNotification.LOAD_FINISHED, set));
1491 1507
                } catch (Exception e) {
1492 1508
                    notify(new DefaultFeatureStoreNotification(store,
1493
                            FeatureStoreNotification.LOAD_FINISHED, e));
1509
                        FeatureStoreNotification.LOAD_FINISHED, e));
1494 1510
                } finally {
1495 1511
                    dispose(set);
1496 1512
                }
......
1507 1523
    }
1508 1524

  
1509 1525
    public Feature getFeatureByReference(FeatureReference reference)
1510
            throws DataException {
1526
        throws DataException {
1511 1527
        checkNotInAppendMode();
1512 1528
        DefaultFeatureReference ref = (DefaultFeatureReference) reference;
1513 1529
        FeatureType featureType;
......
1520 1536
    }
1521 1537

  
1522 1538
    public Feature getFeatureByReference(FeatureReference reference,
1523
            FeatureType featureType) throws DataException {
1539
        FeatureType featureType) throws DataException {
1524 1540
        checkNotInAppendMode();
1525 1541
        featureType = fixFeatureType((DefaultFeatureType) featureType);
1526 1542
        if (this.mode == MODE_FULLEDIT) {
......
1536 1552
        }
1537 1553
        // TODO comprobar que el id es de este store
1538 1554

  
1539
        DefaultFeature feature
1540
                = new DefaultFeature(this,
1541
                        this.provider.getFeatureProviderByReference(
1542
                                (FeatureReferenceProviderServices) reference, sourceFeatureType));
1555
        DefaultFeature feature =
1556
            new DefaultFeature(this,
1557
                this.provider.getFeatureProviderByReference(
1558
                    (FeatureReferenceProviderServices) reference, sourceFeatureType));
1543 1559

  
1544 1560
        if (!this.transforms.isEmpty()) {
1545 1561
            return this.transforms.applyTransform(feature, featureType);
......
1551 1567
    // ====================================================================
1552 1568
    // Gestion de features
1553 1569
    //
1570

  
1554 1571
    private FeatureType fixFeatureType(DefaultFeatureType type)
1555
            throws DataException {
1572
        throws DataException {
1556 1573
        FeatureType original = this.getDefaultFeatureType();
1557 1574

  
1558 1575
        if ((type == null) || type.equals(original)) {
......
1567 1584
                    if (type.equals(tmpType)) {
1568 1585
                        return type;
1569 1586

  
1570
                    } else if (type.isSubtypeOf(tmpType)) {
1571
                        found = true;
1572
                        original = tmpType;
1573
                        break;
1574
                    }
1587
                    } else
1588
                        if (type.isSubtypeOf(tmpType)) {
1589
                            found = true;
1590
                            original = tmpType;
1591
                            break;
1592
                        }
1575 1593

  
1576 1594
                }
1577 1595
                if (!found) {
......
1584 1602
        // else add the missing attributes at the end.
1585 1603
        if (!original.hasOID()) {
1586 1604
            // Gets original pk attributes
1587
            DefaultEditableFeatureType edOriginal
1588
                    = (DefaultEditableFeatureType) original.getEditable();
1605
            DefaultEditableFeatureType edOriginal =
1606
                (DefaultEditableFeatureType) original.getEditable();
1589 1607
            FeatureAttributeDescriptor orgAttr;
1590 1608
            Iterator edOriginalIter = edOriginal.iterator();
1591 1609
            while (edOriginalIter.hasNext()) {
......
1614 1632
            // add missing pk attributes if any
1615 1633
            if (edOriginal.size() > 0) {
1616 1634
                boolean isEditable = type instanceof DefaultEditableFeatureType;
1617
                DefaultEditableFeatureType edType
1618
                        = (DefaultEditableFeatureType) original.getEditable();
1635
                DefaultEditableFeatureType edType =
1636
                    (DefaultEditableFeatureType) original.getEditable();
1619 1637
                edType.clear();
1620 1638
                edType.addAll(type);
1621 1639
                edType.addAll(edOriginal);
......
1655 1673
        try {
1656 1674

  
1657 1675
            if (isEditing()) {
1658
                FeatureType auxFeatureType
1659
                        = featureTypeManager.getType(defaultFeatureType.getId());
1676
                FeatureType auxFeatureType =
1677
                    featureTypeManager.getType(defaultFeatureType.getId());
1660 1678
                if (auxFeatureType != null) {
1661 1679
                    return avoidEditable(auxFeatureType);
1662 1680
                }
......
1682 1700
    }
1683 1701

  
1684 1702
    public FeatureType getFeatureType(String featureTypeId)
1685
            throws DataException {
1703
        throws DataException {
1686 1704
        if (featureTypeId == null) {
1687 1705
            return this.getDefaultFeatureType();
1688 1706
        }
1689 1707
        try {
1690 1708
            if (isEditing()) {
1691
                FeatureType auxFeatureType
1692
                        = featureTypeManager.getType(featureTypeId);
1709
                FeatureType auxFeatureType =
1710
                    featureTypeManager.getType(featureTypeId);
1693 1711
                if (auxFeatureType != null) {
1694 1712
                    return auxFeatureType;
1695 1713
                }
......
1723 1741
                Iterator it = featureTypes.iterator();
1724 1742
                while (it.hasNext()) {
1725 1743
                    FeatureType type = (FeatureType) it.next();
1726
                    FeatureType typeaux
1727
                            = featureTypeManager.getType(type.getId());
1744
                    FeatureType typeaux =
1745
                        featureTypeManager.getType(type.getId());
1728 1746
                    if (typeaux != null) {
1729 1747
                        types.add(typeaux);
1730 1748
                    } else {
......
1758 1776
    }
1759 1777

  
1760 1778
    public Feature createFeature(FeatureProvider data, FeatureType type)
1761
            throws DataException {
1779
        throws DataException {
1762 1780
        // FIXME: falta por implementar
1763 1781
        // Comprobar si es un subtipo del feature de data
1764 1782
        // y construir un feature usando el subtipo.
......
1767 1785
    }
1768 1786

  
1769 1787
    public EditableFeature createNewFeature(FeatureType type,
1770
            Feature defaultValues) throws DataException {
1788
        Feature defaultValues) throws DataException {
1771 1789
        try {
1772 1790
            FeatureProvider data = createNewFeatureProvider(type);
1773
            DefaultEditableFeature feature
1774
                    = new DefaultEditableFeature(this, data);
1791
            DefaultEditableFeature feature =
1792
                new DefaultEditableFeature(this, data);
1775 1793
            feature.initializeValues(defaultValues);
1776 1794
            data.setNew(true);
1777 1795

  
......
1782 1800
    }
1783 1801

  
1784 1802
    private FeatureProvider createNewFeatureProvider(FeatureType type)
1785
            throws DataException {
1803
        throws DataException {
1786 1804
        type = this.fixFeatureType((DefaultFeatureType) type);
1787 1805
        FeatureProvider data = this.provider.createFeatureProvider(type);
1788 1806
        data.setNew(true);
......
1796 1814
    }
1797 1815

  
1798 1816
    public EditableFeature createNewFeature(FeatureType type,
1799
            boolean defaultValues) throws DataException {
1817
        boolean defaultValues) throws DataException {
1800 1818
        try {
1801 1819
            FeatureProvider data = createNewFeatureProvider(type);
1802
            DefaultEditableFeature feature
1803
                    = new DefaultEditableFeature(this, data);
1820
            DefaultEditableFeature feature =
1821
                new DefaultEditableFeature(this, data);
1804 1822
            if (defaultValues) {
1805 1823
                feature.initializeValues();
1806 1824
            }
......
1811 1829
    }
1812 1830

  
1813 1831
    public EditableFeature createNewFeature(boolean defaultValues)
1814
            throws DataException {
1832
        throws DataException {
1815 1833
        return this.createNewFeature(this.getDefaultFeatureType(),
1816
                defaultValues);
1834
            defaultValues);
1817 1835
    }
1818 1836

  
1819 1837
    public EditableFeature createNewFeature() throws DataException {
1820 1838
        return this.createNewFeature(this.getDefaultFeatureType(), true);
1821 1839
    }
1822 1840

  
1841
    public EditableFeature createNewFeature(Feature defaultValues) throws DataException {
1842
        FeatureType ft = this.getDefaultFeatureType();
1843
        EditableFeature f = this.createNewFeature(ft, false);
1844
        Iterator it = ft.iterator();
1845
        while(it.hasNext()) {
1846
            FeatureAttributeDescriptor desc = (FeatureAttributeDescriptor) it.next();
1847
            try {
1848
                f.set(desc.getName(), defaultValues.get(desc.getName()));
1849
            } catch(Throwable th) {
1850
                // Ignore
1851
            }
1852
        }
1853
        return f;
1854
    }
1855

  
1823 1856
    public EditableFeatureType createFeatureType() {
1824 1857
        DefaultEditableFeatureType ftype = new DefaultEditableFeatureType();
1825 1858
        return ftype;
......
1834 1867
    // ====================================================================
1835 1868
    // Index related methods
1836 1869
    //
1870

  
1837 1871
    public FeatureIndexes getIndexes() {
1838 1872
        return this.indexes;
1839 1873
    }
1840 1874

  
1841 1875
    public FeatureIndex createIndex(FeatureType featureType,
1842
            String attributeName, String indexName) throws DataException {
1876
        String attributeName, String indexName) throws DataException {
1843 1877
        return createIndex(null, featureType, attributeName, indexName);
1844 1878
    }
1845 1879

  
1846 1880
    public FeatureIndex createIndex(String indexTypeName,
1847
            FeatureType featureType, String attributeName, String indexName)
1848
            throws DataException {
1881
        FeatureType featureType, String attributeName, String indexName)
1882
        throws DataException {
1849 1883

  
1850 1884
        return createIndex(indexTypeName, featureType, attributeName,
1851
                indexName, false, null);
1885
            indexName, false, null);
1852 1886
    }
1853 1887

  
1854 1888
    public FeatureIndex createIndex(FeatureType featureType,
1855
            String attributeName, String indexName, Observer observer)
1856
            throws DataException {
1889
        String attributeName, String indexName, Observer observer)
1890
        throws DataException {
1857 1891
        return createIndex(null, featureType, attributeName, indexName,
1858
                observer);
1892
            observer);
1859 1893
    }
1860 1894

  
1861 1895
    public FeatureIndex createIndex(String indexTypeName,
1862
            FeatureType featureType, String attributeName, String indexName,
1863
            final Observer observer) throws DataException {
1896
        FeatureType featureType, String attributeName, String indexName,
1897
        final Observer observer) throws DataException {
1864 1898

  
1865 1899
        return createIndex(indexTypeName, featureType, attributeName,
1866
                indexName, true, observer);
1900
            indexName, true, observer);
1867 1901
    }
1868 1902

  
1869 1903
    private FeatureIndex createIndex(String indexTypeName,
1870
            FeatureType featureType, String attributeName, String indexName,
1871
            boolean background, final Observer observer) throws DataException {
1904
        FeatureType featureType, String attributeName, String indexName,
1905
        boolean background, final Observer observer) throws DataException {
1872 1906

  
1873 1907
        checkNotInAppendMode();
1874 1908
        FeatureIndexProviderServices index = null;
1875
        index
1876
                = dataManager.createFeatureIndexProvider(indexTypeName, this,
1877
                        featureType, indexName,
1878
                        featureType.getAttributeDescriptor(attributeName));
1909
        index =
1910
            dataManager.createFeatureIndexProvider(indexTypeName, this,
1911
                featureType, indexName,
1912
                featureType.getAttributeDescriptor(attributeName));
1879 1913

  
1880 1914
        try {
1881 1915
            index.fill(background, observer);
......
1891 1925
    // ====================================================================
1892 1926
    // Transforms related methods
1893 1927
    //
1928

  
1894 1929
    public FeatureStoreTransforms getTransforms() {
1895 1930
        return this.transforms;
1896 1931
    }
......
1907 1942
    // ====================================================================
1908 1943
    // UndoRedo related methods
1909 1944
    //
1945

  
1910 1946
    public boolean canRedo() {
1911 1947
        return commands.canRedo();
1912 1948
    }
......
1931 1967
    // ====================================================================
1932 1968
    // Metadata related methods
1933 1969
    //
1970

  
1934 1971
    public Object getMetadataID() {
1935 1972
        return this.provider.getSourceId();
1936 1973
    }
......
1943 1980
        return this.metadata.getDynClass();
1944 1981
    }
1945 1982

  
1946
    public Object getDynValue(String name) throws DynFieldNotFoundException {
1947
        if (this.transforms.hasDynValue(name)) {
1948
            return this.transforms.getDynValue(name);
1949
        }
1950
        if (this.metadata.hasDynValue(name)) {
1951
            return this.metadata.getDynValue(name);
1952
        }
1953
        if (METADATA_PROVIDER.equalsIgnoreCase(name)) {
1954
            return this.provider.getProviderName();
1955
        } else if (METADATA_CONTAINERNAME.equalsIgnoreCase(name)) {
1956
            return this.provider.getSourceId();
1957
        } else if (METADATA_FEATURETYPE.equalsIgnoreCase(name)) {
1958
            try {
1959
                return this.getDefaultFeatureType();
1960
            } catch (DataException e) {
1961
                return null;
1962
            }
1963
        }
1964
        return this.metadata.getDynValue(name);
1965
    }
1983
	public Object getDynValue(String name) throws DynFieldNotFoundException {
1984
		if( this.transforms.hasDynValue(name) ) {
1985
			return this.transforms.getDynValue(name);
1986
		}
1987
		if (this.metadata.hasDynValue(name)) {
1988
			return this.metadata.getDynValue(name);
1989
		}
1990
		if (METADATA_PROVIDER.equalsIgnoreCase(name)) {
1991
			return this.provider.getProviderName();
1992
		} else if (METADATA_CONTAINERNAME.equalsIgnoreCase(name)) {
1993
			return this.provider.getSourceId();
1994
		} else if (METADATA_FEATURETYPE.equalsIgnoreCase(name)) {
1995
			try {
1996
				return this.getDefaultFeatureType();
1997
			} catch (DataException e) {
1998
				return null;
1999
			}
2000
		}
2001
		return this.metadata.getDynValue(name);
2002
	}
1966 2003

  
1967 2004
    public boolean hasDynValue(String name) {
1968
        if (this.transforms.hasDynValue(name)) {
1969
            return true;
1970
        }
2005
		if( this.transforms.hasDynValue(name) ) {
2006
			return true;
2007
		}
1971 2008
        return this.metadata.hasDynValue(name);
1972 2009
    }
1973 2010

  
......
1976 2013
    }
1977 2014

  
1978 2015
    public Object invokeDynMethod(String name, DynObject context)
1979
            throws DynMethodException {
2016
        throws DynMethodException {
1980 2017
        return this.metadata.invokeDynMethod(this, name, context);
1981 2018
    }
1982 2019

  
1983 2020
    public Object invokeDynMethod(int code, DynObject context)
1984
            throws DynMethodException {
2021
        throws DynMethodException {
1985 2022
        return this.metadata.invokeDynMethod(this, code, context);
1986 2023
    }
1987 2024

  
1988 2025
    public void setDynValue(String name, Object value)
1989
            throws DynFieldNotFoundException {
1990
        if (this.transforms.hasDynValue(name)) {
1991
            this.transforms.setDynValue(name, value);
1992
            return;
1993
        }
2026
        throws DynFieldNotFoundException {
2027
		if( this.transforms.hasDynValue(name) ) {
2028
			this.transforms.setDynValue(name, value);
2029
			return;
2030
		}
1994 2031
        this.metadata.setDynValue(name, value);
1995 2032

  
1996 2033
    }
......
2023 2060
        }
2024 2061
        if (this.isEditing() && !this.isAppending()) {
2025 2062
            return featureCount.longValue()
2026
                    - this.featureManager.getDeltaSize();
2063
                - this.featureManager.getDeltaSize();
2027 2064
        }
2028 2065
        return featureCount.longValue();
2029 2066
    }
......
2060 2097
    }
2061 2098

  
2062 2099
    public void createCache(String name, DynObject parameters)
2063
            throws DataException {
2100
        throws DataException {
2064 2101
        cache = dataManager.createFeatureCacheProvider(name, parameters);
2065 2102
        if (cache == null) {
2066 2103
            throw new CreateException("FeaureCacheProvider", null);
......
2088 2125
    public String getFullName() {
2089 2126
        try {
2090 2127
            return this.provider.getFullName();
2091
        } catch (Throwable th) {
2128
        } catch(Throwable th) {
2092 2129
            return null;
2093 2130
        }
2094 2131
    }
......
2132 2169

  
2133 2170
        try {
2134 2171
            cloned_store = (DefaultFeatureStore) DALLocator.getDataManager().
2135
                    openStore(this.getProviderName(), dsp);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff