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 @ 45765
History | View | Annotate | Download (6.03 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 java.util.logging.Level; |
28 |
import java.util.logging.Logger; |
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
31 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
32 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
33 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
34 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
35 |
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager; |
36 |
import org.gvsig.fmap.dal.feature.impl.featurereference.FeatureReferenceFactory; |
37 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
38 |
import org.gvsig.tools.exception.BaseException; |
39 |
import org.gvsig.tools.util.ChainedIterator; |
40 |
|
41 |
/**
|
42 |
* Iterator for stores in edition mode.
|
43 |
*
|
44 |
* @author gvSIG Team
|
45 |
* @version $Id$
|
46 |
* @deprecated use the {@link FastEditedIterator} instead
|
47 |
*/
|
48 |
public class EditedIterator extends FilteredIterator { |
49 |
|
50 |
private DefaultFeatureStore store;
|
51 |
protected FeatureManager featureManager;
|
52 |
|
53 |
public EditedIterator(DefaultFeatureSet featureSet) {
|
54 |
super(featureSet);
|
55 |
this.store = featureSet.store;
|
56 |
this.featureManager = this.store.getFeatureManager(); |
57 |
} |
58 |
|
59 |
public EditedIterator(DefaultFeatureSet featureSet, long index) |
60 |
throws DataException {
|
61 |
this(featureSet);
|
62 |
|
63 |
Iterator<EditableFeature> insertedFeatures = this.featureManager.getInsertedFeatures();//Don't use getInserteds because referenceFeature will be missed |
64 |
Iterator<EditableFeature> updatedFeatures = this.featureManager.getUpdatedFeatures(); |
65 |
final Iterator<FeatureProvider> providerIterator = featureSet.provider.iterator(); |
66 |
Iterator<FeatureProvider> wrappedProviderIterator = new Iterator<FeatureProvider>() { |
67 |
@Override
|
68 |
public boolean hasNext() { |
69 |
return providerIterator.hasNext();
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public FeatureProvider next() {
|
74 |
FeatureProvider data = providerIterator.next(); |
75 |
FeatureReference ref = FeatureReferenceFactory.createFromFeatureProvider(store, data); |
76 |
DefaultFeature modified; |
77 |
try {
|
78 |
modified = featureManager.get(ref, store); |
79 |
} catch (DataException ex) {
|
80 |
return data;
|
81 |
} |
82 |
if (modified != null) { |
83 |
return modified.getData();
|
84 |
} |
85 |
return data;
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void remove() { |
90 |
EditedIterator.super.remove(); |
91 |
} |
92 |
}; |
93 |
this.iterator = new ChainedIterator(wrappedProviderIterator, insertedFeatures); |
94 |
if (index > 0) { |
95 |
skypto(index); |
96 |
} |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public void remove() { |
101 |
this.iterator.remove();
|
102 |
} |
103 |
|
104 |
@Override
|
105 |
public boolean hasNext() { |
106 |
if (store.isEditing()) {
|
107 |
return super.hasNext(); |
108 |
} else {
|
109 |
throw new ConcurrentDataModificationException(store.getFullName()); |
110 |
} |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public Object next() { |
115 |
if (store.isEditing()) {
|
116 |
return super.next(); |
117 |
} else {
|
118 |
throw new ConcurrentDataModificationException(store.getFullName()); |
119 |
} |
120 |
} |
121 |
|
122 |
@Override
|
123 |
protected ChainedIterator getIterator() {
|
124 |
return (ChainedIterator) this.iterator; |
125 |
} |
126 |
|
127 |
@Override
|
128 |
protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
129 |
|
130 |
DefaultFeature f = this.featureManager.get(data);
|
131 |
// DefaultFeature f = null;
|
132 |
// try {
|
133 |
// FeatureReference ref = new DefaultFeatureReference(store, data);
|
134 |
// f= (DefaultFeature) this.featureManager.get(ref, store, data.getType());
|
135 |
// } catch (DataException e) {
|
136 |
// RuntimeException ex = new RuntimeException();
|
137 |
// e.initCause(e);
|
138 |
// throw ex;
|
139 |
// }
|
140 |
if (f == null) { |
141 |
// La feature no se ha editado.
|
142 |
f = new DefaultFeature(store, data);
|
143 |
} |
144 |
if (this.fset.transform.isEmpty()) { |
145 |
return f;
|
146 |
} else {
|
147 |
return (DefaultFeature) this.fset.transform.applyTransform( |
148 |
f, fset.getDefaultFeatureType()); |
149 |
} |
150 |
} |
151 |
|
152 |
@Override
|
153 |
protected boolean skipFeature(FeatureProvider data) { |
154 |
try {
|
155 |
if (getIterator().getCurrent() == 0) { |
156 |
if (this.featureManager.isDeleted(data)) { |
157 |
return true; |
158 |
}; |
159 |
// FeatureReference ref = FeatureReferenceFactory.createFromFeatureProvider(store, data);
|
160 |
// if (this.featureManager.get(ref, store) != null) {
|
161 |
// return true;
|
162 |
// };
|
163 |
} |
164 |
} catch (Exception ex) { |
165 |
LOGGER.warn("Can't check if must skip feature.", ex);
|
166 |
} |
167 |
return false; |
168 |
} |
169 |
|
170 |
@Override
|
171 |
protected void doDispose() throws BaseException { |
172 |
super.doDispose();
|
173 |
this.featureManager = null; |
174 |
this.store = null; |
175 |
} |
176 |
|
177 |
} |