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