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 @ 44207
History | View | Annotate | Download (6.28 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal.feature.impl.featureset; |
||
25 | |||
26 | import java.util.Iterator; |
||
27 | |||
28 | import org.gvsig.fmap.dal.exception.DataException; |
||
29 | import org.gvsig.fmap.dal.feature.FeatureReference; |
||
30 | import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
||
31 | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
||
32 | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReference; |
||
33 | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
||
34 | 43840 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager; |
35 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
36 | import org.gvsig.tools.dispose.DisposableIterator; |
||
37 | import org.gvsig.tools.exception.BaseException; |
||
38 | |||
39 | /**
|
||
40 | * Iterator for stores in edition mode.
|
||
41 | *
|
||
42 | * @author gvSIG Team
|
||
43 | * @version $Id$
|
||
44 | * @deprecated use the {@link FastEditedIterator} instead
|
||
45 | */
|
||
46 | public class EditedIterator extends FilteredIterator { |
||
47 | |||
48 | private Iterator newsFeatures; |
||
49 | private boolean featureIsNew; |
||
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 | this.newsFeatures = null; |
||
63 | if (index > 0) { |
||
64 | 40629 | jldominguez | |
65 | this.iterator = featureSet.provider.iterator();
|
||
66 | skypto(index); |
||
67 | |||
68 | /*
|
||
69 | * This did not work because the provider
|
||
70 | * skips to the index without considering the
|
||
71 | * changes in editing mode. We need the
|
||
72 | * "skypto" method which knows about those
|
||
73 | * changes.
|
||
74 | *
|
||
75 | if (featureSet.provider.canIterateFromIndex()) {
|
||
76 | 40435 | jjdelcerro | try {
|
77 | this.iterator = featureSet.provider.iterator(index);
|
||
78 | } catch (IllegalArgumentException e) {
|
||
79 | this.iterator = featureSet.provider.iterator();
|
||
80 | skypto(index);
|
||
81 | } catch (UnsupportedOperationException e) {
|
||
82 | this.iterator = featureSet.provider.iterator();
|
||
83 | skypto(index);
|
||
84 | }
|
||
85 | } else {
|
||
86 | this.iterator = featureSet.provider.iterator();
|
||
87 | skypto(index);
|
||
88 | }
|
||
89 | 40629 | jldominguez | */
|
90 | |||
91 | 40435 | jjdelcerro | } else {
|
92 | this.iterator = featureSet.provider.iterator();
|
||
93 | } |
||
94 | |||
95 | } |
||
96 | |||
97 | public void remove() { |
||
98 | if(this.getIterator() == newsFeatures) { |
||
99 | newsFeatures.remove(); |
||
100 | } else {
|
||
101 | super.remove();
|
||
102 | } |
||
103 | } |
||
104 | |||
105 | public boolean hasNext() { |
||
106 | if (store.isEditing()) {
|
||
107 | return super.hasNext(); |
||
108 | } else {
|
||
109 | throw new ConcurrentDataModificationException(store.getFullName()); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | public Object next() { |
||
114 | if (store.isEditing()) {
|
||
115 | return super.next(); |
||
116 | } else {
|
||
117 | throw new ConcurrentDataModificationException(store.getFullName()); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | protected void setNewsFeatures(Iterator newsFeatures) { |
||
122 | this.newsFeatures = newsFeatures;
|
||
123 | } |
||
124 | |||
125 | protected boolean isFeatureIsNew() { |
||
126 | return featureIsNew;
|
||
127 | } |
||
128 | |||
129 | protected Iterator getIterator() { |
||
130 | if (this.featureIsNew) { |
||
131 | return this.newsFeatures; |
||
132 | } else
|
||
133 | if (this.iterator.hasNext()) { |
||
134 | featureIsNew = false;
|
||
135 | return this.iterator; |
||
136 | } else {
|
||
137 | featureIsNew = true;
|
||
138 | this.newsFeatures = this.featureManager.getInserted(); |
||
139 | return this.newsFeatures; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
||
144 | |||
145 | DefaultFeature f = null;
|
||
146 | data.setNew(featureIsNew); |
||
147 | try {
|
||
148 | FeatureReference ref = new DefaultFeatureReference(store, data);
|
||
149 | f = |
||
150 | (DefaultFeature) this.featureManager.get(ref, store,
|
||
151 | data.getType()); |
||
152 | } catch (DataException e) {
|
||
153 | RuntimeException ex = new RuntimeException(); |
||
154 | e.initCause(e); |
||
155 | throw ex;
|
||
156 | } |
||
157 | if (f == null) { |
||
158 | // La feature no se ha editado.
|
||
159 | f = new DefaultFeature(store, data);
|
||
160 | } |
||
161 | if (this.fset.transform.isEmpty()) { |
||
162 | return f;
|
||
163 | } else {
|
||
164 | return (DefaultFeature) this.fset.transform.applyTransform( |
||
165 | f, fset.getDefaultFeatureType()); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | protected boolean isDeletedOrHasToSkip(FeatureProvider data) { |
||
170 | |||
171 | // XXX
|
||
172 | // si recorriendo los originales nos
|
||
173 | // encontramos uno nuevo, no lo devolvemos
|
||
174 | // porque se recorrera mas tarde.
|
||
175 | // Esto es una interaccion con los indices
|
||
176 | // ya que estos contienen todas las features ya
|
||
177 | // sea nuevas o no
|
||
178 | |||
179 | if (data.isNew() && !featureIsNew) {
|
||
180 | return true; |
||
181 | } |
||
182 | FeatureReference ref = new DefaultFeatureReference(store, data);
|
||
183 | return this.featureManager.isDeleted(ref); |
||
184 | } |
||
185 | |||
186 | protected void doDispose() throws BaseException { |
||
187 | super.doDispose();
|
||
188 | if (newsFeatures instanceof DisposableIterator) { |
||
189 | ((DisposableIterator) newsFeatures).dispose(); |
||
190 | } |
||
191 | newsFeatures = null;
|
||
192 | this.featureManager = null; |
||
193 | this.store = null; |
||
194 | } |
||
195 | |||
196 | } |