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 @ 40559
History | View | Annotate | Download (5.89 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 | import org.gvsig.fmap.dal.feature.impl.FeatureManager; |
||
35 | 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 | if (featureSet.provider.canIterateFromIndex()) {
|
||
65 | try {
|
||
66 | this.iterator = featureSet.provider.iterator(index);
|
||
67 | } catch (IllegalArgumentException e) { |
||
68 | this.iterator = featureSet.provider.iterator();
|
||
69 | skypto(index); |
||
70 | } catch (UnsupportedOperationException e) { |
||
71 | this.iterator = featureSet.provider.iterator();
|
||
72 | skypto(index); |
||
73 | } |
||
74 | } else {
|
||
75 | this.iterator = featureSet.provider.iterator();
|
||
76 | skypto(index); |
||
77 | } |
||
78 | } else {
|
||
79 | this.iterator = featureSet.provider.iterator();
|
||
80 | } |
||
81 | |||
82 | } |
||
83 | |||
84 | public void remove() { |
||
85 | if(this.getIterator() == newsFeatures) { |
||
86 | newsFeatures.remove(); |
||
87 | } else {
|
||
88 | super.remove();
|
||
89 | } |
||
90 | } |
||
91 | |||
92 | public boolean hasNext() { |
||
93 | if (store.isEditing()) {
|
||
94 | return super.hasNext(); |
||
95 | } else {
|
||
96 | throw new ConcurrentDataModificationException(store.getFullName()); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | public Object next() { |
||
101 | if (store.isEditing()) {
|
||
102 | return super.next(); |
||
103 | } else {
|
||
104 | throw new ConcurrentDataModificationException(store.getFullName()); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | protected void setNewsFeatures(Iterator newsFeatures) { |
||
109 | this.newsFeatures = newsFeatures;
|
||
110 | } |
||
111 | |||
112 | protected boolean isFeatureIsNew() { |
||
113 | return featureIsNew;
|
||
114 | } |
||
115 | |||
116 | protected Iterator getIterator() { |
||
117 | if (this.featureIsNew) { |
||
118 | return this.newsFeatures; |
||
119 | } else
|
||
120 | if (this.iterator.hasNext()) { |
||
121 | featureIsNew = false;
|
||
122 | return this.iterator; |
||
123 | } else {
|
||
124 | featureIsNew = true;
|
||
125 | this.newsFeatures = this.featureManager.getInserted(); |
||
126 | return this.newsFeatures; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
||
131 | |||
132 | DefaultFeature f = null;
|
||
133 | data.setNew(featureIsNew); |
||
134 | try {
|
||
135 | FeatureReference ref = new DefaultFeatureReference(store, data);
|
||
136 | f = |
||
137 | (DefaultFeature) this.featureManager.get(ref, store,
|
||
138 | data.getType()); |
||
139 | } catch (DataException e) {
|
||
140 | RuntimeException ex = new RuntimeException(); |
||
141 | e.initCause(e); |
||
142 | throw ex;
|
||
143 | } |
||
144 | if (f == null) { |
||
145 | // La feature no se ha editado.
|
||
146 | f = new DefaultFeature(store, data);
|
||
147 | } |
||
148 | if (this.fset.transform.isEmpty()) { |
||
149 | return f;
|
||
150 | } else {
|
||
151 | return (DefaultFeature) this.fset.transform.applyTransform( |
||
152 | f, fset.getDefaultFeatureType()); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | protected boolean isDeletedOrHasToSkip(FeatureProvider data) { |
||
157 | |||
158 | // XXX
|
||
159 | // si recorriendo los originales nos
|
||
160 | // encontramos uno nuevo, no lo devolvemos
|
||
161 | // porque se recorrera mas tarde.
|
||
162 | // Esto es una interaccion con los indices
|
||
163 | // ya que estos contienen todas las features ya
|
||
164 | // sea nuevas o no
|
||
165 | |||
166 | if (data.isNew() && !featureIsNew) {
|
||
167 | return true; |
||
168 | } |
||
169 | FeatureReference ref = new DefaultFeatureReference(store, data);
|
||
170 | return this.featureManager.isDeleted(ref); |
||
171 | } |
||
172 | |||
173 | protected void doDispose() throws BaseException { |
||
174 | super.doDispose();
|
||
175 | if (newsFeatures instanceof DisposableIterator) { |
||
176 | ((DisposableIterator) newsFeatures).dispose(); |
||
177 | } |
||
178 | newsFeatures = null;
|
||
179 | this.featureManager = null; |
||
180 | this.store = null; |
||
181 | } |
||
182 | |||
183 | } |