Statistics
| Revision:

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 / featureset / EditedIterator.java @ 45647

History | View | Annotate | Download (5.25 KB)

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

    
26
import java.util.Iterator;
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
29
import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
30
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
31
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager;
32
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
33
import org.gvsig.tools.exception.BaseException;
34
import org.gvsig.tools.util.ChainedIterator;
35

    
36
/**
37
 * Iterator for stores in edition mode.
38
 * 
39
 * @author gvSIG Team
40
 * @version $Id$
41
 * @deprecated use the {@link FastEditedIterator} instead
42
 */
43
public class EditedIterator extends FilteredIterator {
44

    
45
    private DefaultFeatureStore store;
46
    protected FeatureManager featureManager;
47

    
48
    public EditedIterator(DefaultFeatureSet featureSet) {
49
        super(featureSet);
50
        this.store = featureSet.store;
51
        this.featureManager = this.store.getFeatureManager();
52
    }
53

    
54
    public EditedIterator(DefaultFeatureSet featureSet, long index)
55
        throws DataException {
56
        this(featureSet);
57

    
58
        Iterator<FeatureProvider> insertedFeatures = this.featureManager.getInserted();
59
//        Iterator<FeatureProvider> updatedFeatures = this.featureManager.getUpdated();
60
        final Iterator<FeatureProvider> providerIterator = featureSet.provider.iterator();
61
        Iterator<FeatureProvider> wrappedProviderIterator = new Iterator<FeatureProvider>() {
62
            @Override
63
            public boolean hasNext() {
64
                return providerIterator.hasNext();
65
            }
66

    
67
            @Override
68
            public FeatureProvider next() {
69
                return providerIterator.next();
70
            }
71

    
72
            @Override
73
            public void remove() {
74
                EditedIterator.super.remove();
75
            }
76
        };
77
        this.iterator = new ChainedIterator(wrappedProviderIterator, insertedFeatures); //, updatedFeatures);
78
        if (index > 0) {
79
            skypto(index);
80
        }
81
    }
82
    
83
    @Override
84
    public void remove() {
85
        this.iterator.remove();
86
    }
87

    
88
    @Override
89
    public boolean hasNext() {
90
        if (store.isEditing()) {
91
            return super.hasNext();
92
        } else {
93
            throw new ConcurrentDataModificationException(store.getFullName());
94
        }
95
    }
96

    
97
    @Override
98
    public Object next() {
99
        if (store.isEditing()) {
100
            return super.next();
101
        } else {
102
            throw new ConcurrentDataModificationException(store.getFullName());
103
        }
104
    }
105

    
106
    @Override
107
    protected ChainedIterator getIterator() {
108
        return (ChainedIterator) this.iterator;
109
    }
110
    
111
    @Override
112
    protected DefaultFeature createFeature(FeatureProvider data) throws DataException {
113

    
114
        DefaultFeature f = this.featureManager.get(data);
115
//        DefaultFeature f = null;
116
//        try {
117
//            FeatureReference ref = new DefaultFeatureReference(store, data);
118
//            f= (DefaultFeature) this.featureManager.get(ref, store, data.getType());
119
//        } catch (DataException e) {
120
//            RuntimeException ex = new RuntimeException();
121
//            e.initCause(e);
122
//            throw ex;
123
//        }
124
        if (f == null) {
125
            // La feature no se ha editado.
126
            f = new DefaultFeature(store, data);
127
        }
128
        if (this.fset.transform.isEmpty()) {
129
            return f;
130
        } else {
131
            return (DefaultFeature) this.fset.transform.applyTransform(
132
                    f, fset.getDefaultFeatureType());
133
        }     
134
    }
135
    
136
    @Override
137
    protected boolean skipFeature(FeatureProvider data) {
138
        try {
139
            if (getIterator().getCurrent() == 0) {
140
//                FeatureReference ref = new DefaultFeatureReference(store, data);
141
                if (this.featureManager.isDeleted(data)) {
142
                    return true;
143
                };
144
//                if (this.featureManager.get(ref, store) != null) {
145
//                    return true;
146
//                };
147
            }
148
        } catch (Exception ex) {
149
            LOGGER.warn("Can't check if must skip feature.", ex);
150
        }
151
        return false;
152
    }
153

    
154
    @Override
155
    protected void doDispose() throws BaseException {
156
        super.doDispose();
157
        this.featureManager = null;
158
        this.store = null;
159
    }
160

    
161
}