svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / featureset / EditedIterator.java @ 39080
History | View | Annotate | Download (5.84 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.fmap.dal.feature.impl.featureset; |
23 |
|
24 |
import java.util.Iterator; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
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.DefaultFeatureReference; |
31 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
32 |
import org.gvsig.fmap.dal.feature.impl.FeatureManager; |
33 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
34 |
import org.gvsig.tools.dispose.DisposableIterator; |
35 |
import org.gvsig.tools.exception.BaseException; |
36 |
|
37 |
/**
|
38 |
* Iterator for stores in edition mode.
|
39 |
*
|
40 |
* @author gvSIG Team
|
41 |
* @version $Id$
|
42 |
* @deprecated use the {@link FastEditedIterator} instead
|
43 |
*/
|
44 |
public class EditedIterator extends FilteredIterator { |
45 |
|
46 |
private Iterator newsFeatures; |
47 |
private boolean featureIsNew; |
48 |
private DefaultFeatureStore store;
|
49 |
protected FeatureManager featureManager;
|
50 |
|
51 |
public EditedIterator(DefaultFeatureSet featureSet) {
|
52 |
super(featureSet);
|
53 |
this.store = featureSet.store;
|
54 |
this.featureManager = this.store.getFeatureManager(); |
55 |
} |
56 |
|
57 |
public EditedIterator(DefaultFeatureSet featureSet, long index) |
58 |
throws DataException {
|
59 |
this(featureSet);
|
60 |
this.newsFeatures = null; |
61 |
if (index > 0) { |
62 |
if (featureSet.provider.canIterateFromIndex()) {
|
63 |
try {
|
64 |
this.iterator = featureSet.provider.iterator(index);
|
65 |
} catch (IllegalArgumentException e) { |
66 |
this.iterator = featureSet.provider.iterator();
|
67 |
skypto(index); |
68 |
} catch (UnsupportedOperationException e) { |
69 |
this.iterator = featureSet.provider.iterator();
|
70 |
skypto(index); |
71 |
} |
72 |
} else {
|
73 |
this.iterator = featureSet.provider.iterator();
|
74 |
skypto(index); |
75 |
} |
76 |
} else {
|
77 |
this.iterator = featureSet.provider.iterator();
|
78 |
} |
79 |
|
80 |
} |
81 |
|
82 |
public void remove() { |
83 |
if(this.getIterator() == newsFeatures) { |
84 |
newsFeatures.remove(); |
85 |
} else {
|
86 |
super.remove();
|
87 |
} |
88 |
} |
89 |
|
90 |
public boolean hasNext() { |
91 |
if (store.isEditing()) {
|
92 |
return super.hasNext(); |
93 |
} else {
|
94 |
throw new ConcurrentDataModificationException(store.getFullName()); |
95 |
} |
96 |
} |
97 |
|
98 |
public Object next() { |
99 |
if (store.isEditing()) {
|
100 |
return super.next(); |
101 |
} else {
|
102 |
throw new ConcurrentDataModificationException(store.getFullName()); |
103 |
} |
104 |
} |
105 |
|
106 |
protected void setNewsFeatures(Iterator newsFeatures) { |
107 |
this.newsFeatures = newsFeatures;
|
108 |
} |
109 |
|
110 |
protected boolean isFeatureIsNew() { |
111 |
return featureIsNew;
|
112 |
} |
113 |
|
114 |
protected Iterator getIterator() { |
115 |
if (this.featureIsNew) { |
116 |
return this.newsFeatures; |
117 |
} else
|
118 |
if (this.iterator.hasNext()) { |
119 |
featureIsNew = false;
|
120 |
return this.iterator; |
121 |
} else {
|
122 |
featureIsNew = true;
|
123 |
this.newsFeatures = this.featureManager.getInserted(); |
124 |
return this.newsFeatures; |
125 |
} |
126 |
} |
127 |
|
128 |
protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
129 |
|
130 |
DefaultFeature f = null;
|
131 |
data.setNew(featureIsNew); |
132 |
try {
|
133 |
FeatureReference ref = new DefaultFeatureReference(store, data);
|
134 |
f = |
135 |
(DefaultFeature) this.featureManager.get(ref, store,
|
136 |
data.getType()); |
137 |
} catch (DataException e) {
|
138 |
RuntimeException ex = new RuntimeException(); |
139 |
e.initCause(e); |
140 |
throw ex;
|
141 |
} |
142 |
if (f == null) { |
143 |
// La feature no se ha editado.
|
144 |
f = new DefaultFeature(store, data);
|
145 |
} |
146 |
if (this.fset.transform.isEmpty()) { |
147 |
return f;
|
148 |
} else {
|
149 |
return (DefaultFeature) this.fset.transform.applyTransform( |
150 |
f, fset.getDefaultFeatureType()); |
151 |
} |
152 |
} |
153 |
|
154 |
protected boolean isDeletedOrHasToSkip(FeatureProvider data) { |
155 |
|
156 |
// XXX
|
157 |
// si recorriendo los originales nos
|
158 |
// encontramos uno nuevo, no lo devolvemos
|
159 |
// porque se recorrera mas tarde.
|
160 |
// Esto es una interaccion con los indices
|
161 |
// ya que estos contienen todas las features ya
|
162 |
// sea nuevas o no
|
163 |
|
164 |
if (data.isNew() && !featureIsNew) {
|
165 |
return true; |
166 |
} |
167 |
FeatureReference ref = new DefaultFeatureReference(store, data);
|
168 |
return this.featureManager.isDeleted(ref); |
169 |
} |
170 |
|
171 |
protected void doDispose() throws BaseException { |
172 |
super.doDispose();
|
173 |
if (newsFeatures instanceof DisposableIterator) { |
174 |
((DisposableIterator) newsFeatures).dispose(); |
175 |
} |
176 |
newsFeatures = null;
|
177 |
this.featureManager = null; |
178 |
this.store = null; |
179 |
} |
180 |
|
181 |
} |