svn-gvsig-desktop / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / FeatureManager.java @ 20606
History | View | Annotate | Download (7.03 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
|
43 |
package org.gvsig.data.vectorial; |
44 |
|
45 |
import java.util.ArrayList; |
46 |
import java.util.HashMap; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import org.gvsig.data.exception.InitializeException; |
50 |
import org.gvsig.data.exception.ReadException; |
51 |
import org.gvsig.data.vectorial.expansionadapter.IExpansionAdapter; |
52 |
|
53 |
|
54 |
/**
|
55 |
* DOCUMENT ME!
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
*/
|
59 |
public class FeatureManager { |
60 |
protected HashMap relations = new HashMap();//<IFeatureID,Integer> |
61 |
protected IExpansionAdapter expansionAdapter;
|
62 |
protected ArrayList deletedFeatures = new ArrayList();//<IFeatureID> |
63 |
protected int num=0; |
64 |
public FeatureManager(IExpansionAdapter expansionAdapter){
|
65 |
this.expansionAdapter=expansionAdapter;
|
66 |
} |
67 |
|
68 |
public void deleteFeature(IFeatureID id) { |
69 |
deletedFeatures.add(id); |
70 |
num--; |
71 |
} |
72 |
|
73 |
/**
|
74 |
* DOCUMENT ME!
|
75 |
*
|
76 |
* @param feature DOCUMENT ME!
|
77 |
*/
|
78 |
public void addFeature(IFeature feature) { |
79 |
int pos = expansionAdapter.addObject(feature);
|
80 |
relations.put(feature.getID(), new Integer(pos)); |
81 |
num++; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* DOCUMENT ME!
|
86 |
*
|
87 |
* @param id DOCUMENT ME!
|
88 |
*/
|
89 |
public void deleteLastFeature(IFeatureID id) { |
90 |
expansionAdapter.deleteLastObject(); |
91 |
relations.remove(id); |
92 |
num--; |
93 |
} |
94 |
|
95 |
/**
|
96 |
* DOCUMENT ME!
|
97 |
*
|
98 |
* @param id DOCUMENT ME!
|
99 |
*
|
100 |
* @return DOCUMENT ME!
|
101 |
*/
|
102 |
public boolean contains(IFeatureID id) { |
103 |
return relations.containsKey(id);
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* DOCUMENT ME!
|
108 |
*
|
109 |
* @param id DOCUMENT ME!
|
110 |
*
|
111 |
* @return DOCUMENT ME!
|
112 |
* @throws IsNotFeatureSettingException
|
113 |
*/
|
114 |
public IFeature getFeature(IFeatureID id,IFeatureStore store) throws InitializeException { |
115 |
int num = ((Integer) relations.get(id)).intValue(); |
116 |
|
117 |
IFeature feature=(IFeature)expansionAdapter.getObject(num); |
118 |
return getCorrectFeature(feature, store);
|
119 |
} |
120 |
|
121 |
private IFeature getCorrectFeature(IFeature feature,IFeatureStore store) throws InitializeException { |
122 |
Iterator iterator=store.getDefaultFeatureType().iterator();
|
123 |
IFeature newFeature=store.createFeature(store.getDefaultFeatureType()); |
124 |
((Feature)newFeature).loading(); |
125 |
while (iterator.hasNext()) {
|
126 |
IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next(); |
127 |
int i=((AttributeDescriptor)fad).originalPosition();
|
128 |
try {
|
129 |
if (i<feature.size()){
|
130 |
newFeature.set(i,feature.get(i)); |
131 |
}else{
|
132 |
newFeature.set(i,fad.getDefaultValue()); |
133 |
} |
134 |
} catch (IsNotFeatureSettingException e) {
|
135 |
throw new InitializeException("FeatureManager",e); |
136 |
} |
137 |
|
138 |
} |
139 |
((Feature)newFeature).stopLoading(); |
140 |
return newFeature;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* DOCUMENT ME!
|
145 |
*
|
146 |
* @param feature DOCUMENT ME!
|
147 |
* @param oldFeature DOCUMENT ME!
|
148 |
*/
|
149 |
public void updateFeature(IFeature feature, IFeature oldFeature) { |
150 |
deletedFeatures.add(oldFeature.getID()); |
151 |
|
152 |
int num = expansionAdapter.updateObject(feature);
|
153 |
|
154 |
/*
|
155 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
156 |
* fichero de expansi?n.
|
157 |
*/
|
158 |
relations.put(feature.getID(), new Integer(num)); |
159 |
} |
160 |
|
161 |
/**
|
162 |
* DOCUMENT ME!
|
163 |
*
|
164 |
* @param id DOCUMENT ME!
|
165 |
*/
|
166 |
public void restoreFeature(IFeatureID id) { |
167 |
deletedFeatures.remove(id); |
168 |
num++; |
169 |
} |
170 |
public int getNum(){ |
171 |
return num;
|
172 |
} |
173 |
|
174 |
public IFeature getFeature(int i,IFeatureStore store) throws ReadException{ |
175 |
IFeature feature=(IFeature)expansionAdapter.getObject(i); |
176 |
return getCorrectFeature(feature,store);
|
177 |
} |
178 |
public boolean isDeleted(IFeature feature){ |
179 |
return deletedFeatures.contains(feature.getID());
|
180 |
} |
181 |
|
182 |
public void clear() { |
183 |
relations.clear();//<IFeatureID,Integer>
|
184 |
expansionAdapter.close(); |
185 |
deletedFeatures.clear();//<IFeatureID>
|
186 |
num=0;
|
187 |
} |
188 |
|
189 |
|
190 |
// public IFeatureCollection getDataCollection(IDataCollection originalCollection, IFeatureType type, String filter, String order) {
|
191 |
// MemoryFeatureCollection memoryCollection=new MemoryFeatureCollection();
|
192 |
//// TODO Filtrar y ordenar, quedar? tambi?n pendiente el IFeatureType que se pasa como
|
193 |
// //par?metro ya que aqu? lo ?nico que introducimos al DataCollection son IFeatureID,
|
194 |
// //todav?a no creamos IFeatures
|
195 |
// for (int i=0;i<relations.size();i++){
|
196 |
// IFeature feature=(IFeature)expansionAdapter.getObject(i);
|
197 |
// if (!deletedFeatures.contains(feature.getID())){
|
198 |
// memoryCollection.add(feature);
|
199 |
// }
|
200 |
// }
|
201 |
// Iterator iter=originalCollection.iterator();
|
202 |
// int i=0;
|
203 |
// featureStore.open();
|
204 |
// while (iter.hasNext()) {
|
205 |
// IFeature feature = (IFeature) iter.next();
|
206 |
// if (!deletedFeatures.contains(feature.getID())){
|
207 |
// memoryCollection.add(feature);
|
208 |
// }
|
209 |
// i++;
|
210 |
// }
|
211 |
//
|
212 |
// //TODO en el filtro de las features originales hay que a?adir, que no muestre las que est?n el el HashMap deletedFeatures
|
213 |
//// IFeatureCollection featureCollection=(IFeatureCollection)featureStore.getDataCollection(type,filter,order);
|
214 |
//
|
215 |
//
|
216 |
// EditingFeatureCollection collection=new EditingFeatureCollection(originalCollection, memoryCollection,type);
|
217 |
//// collection.
|
218 |
//// MemoryFeatureCollection collection=new MemoryFeatureCollection();
|
219 |
// //TODO Filtrar y ordenar, quedar? tambi?n pendiente el IFeatureType que se pasa como
|
220 |
// //par?metro ya que aqu? lo ?nico que introducimos al DataCollection son IFeatureID,
|
221 |
// //todav?a no creamos IFeatures
|
222 |
//// featureStore.createDefaultFeature()
|
223 |
//// for (int i=0;i<driver.getFeatureCount();i++){
|
224 |
//// MemoryFeatureID id=new MemoryFeatureID(driver.getFeatureByPosition(type,i));
|
225 |
//// collection.add(id);
|
226 |
//// }
|
227 |
// return collection;
|
228 |
//
|
229 |
// }
|
230 |
|
231 |
} |