Revision 44259 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/feature/spi/simpleprovider/SimpleSequentialReaderStoreProvider.java
SimpleSequentialReaderStoreProvider.java | ||
---|---|---|
26 | 26 |
import java.io.File; |
27 | 27 |
import java.io.IOException; |
28 | 28 |
import java.util.ArrayList; |
29 |
import java.util.Collections; |
|
30 | 29 |
import java.util.HashMap; |
31 | 30 |
import java.util.Iterator; |
32 | 31 |
import java.util.List; |
33 | 32 |
import java.util.Locale; |
34 | 33 |
import java.util.Map; |
35 |
import org.apache.commons.io.FilenameUtils; |
|
36 | 34 |
|
37 | 35 |
import org.apache.commons.lang3.StringUtils; |
38 | 36 |
import org.cresques.cts.IProjection; |
... | ... | |
87 | 85 |
import org.gvsig.tools.exception.BaseException; |
88 | 86 |
import org.gvsig.tools.task.SimpleTaskStatus; |
89 | 87 |
import org.gvsig.tools.task.TaskStatusManager; |
88 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
|
89 |
import org.gvsig.tools.util.UnmodifiableBasicMapToMapAdapter; |
|
90 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
90 | 91 |
import org.gvsig.tools.visitor.VisitCanceledException; |
91 | 92 |
import org.gvsig.tools.visitor.Visitor; |
92 | 93 |
import org.slf4j.Logger; |
... | ... | |
101 | 102 |
private class ReaderData { |
102 | 103 |
private FeatureType defaultFeatureType; |
103 | 104 |
private List<FeatureType> featureTypes; |
104 |
private List<FeatureProvider> features; |
|
105 |
private final List<FeatureProvider> features;
|
|
105 | 106 |
private boolean needCalculateEnvelope; |
106 | 107 |
private String name; |
107 | 108 |
private long OIDcounter; |
... | ... | |
172 | 173 |
return this.store; |
173 | 174 |
} |
174 | 175 |
} |
176 |
|
|
177 |
class Children implements UnmodifiableBasicMap<String, DataStore> { |
|
178 |
// Con esta clase se pospone la creacion de los stores hasta que se |
|
179 |
// pide cada uno de ellos, y no cuando se pide el Map de estos, ya |
|
180 |
// que el map se puede pedir solo para saber si hay o cuantos hay. |
|
175 | 181 |
|
182 |
@Override |
|
183 |
public DataStore get(String key) { |
|
184 |
for (ReaderData child : childrenData) { |
|
185 |
if( StringUtils.equalsIgnoreCase(child.getName(), key) ) { |
|
186 |
try { |
|
187 |
return child.getStore(); |
|
188 |
} catch (Exception ex) { |
|
189 |
throw new RuntimeException(ex); |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public boolean isEmpty() { |
|
198 |
return childrenData.isEmpty(); |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public boolean containsKey(String key) { |
|
203 |
for (ReaderData child : childrenData) { |
|
204 |
if( StringUtils.equalsIgnoreCase(child.getName(), key) ) { |
|
205 |
return true; |
|
206 |
} |
|
207 |
} |
|
208 |
return false; |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public Map<String, DataStore> toMap() { |
|
213 |
return new UnmodifiableBasicMapToMapAdapter<>(this); |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public int size() { |
|
218 |
return childrenData.size(); |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public UnmodifiableBasicSet<String> keySet() { |
|
223 |
return new UnmodifiableBasicSet<String>() { |
|
224 |
|
|
225 |
@Override |
|
226 |
public boolean isEmpty() { |
|
227 |
return childrenData.isEmpty(); |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public int size() { |
|
232 |
return childrenData.size(); |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public Iterator<String> iterator() { |
|
237 |
final Iterator<ReaderData> it = childrenData.iterator(); |
|
238 |
return new Iterator<String>() { |
|
239 |
@Override |
|
240 |
public boolean hasNext() { |
|
241 |
return it.hasNext(); |
|
242 |
} |
|
243 |
|
|
244 |
@Override |
|
245 |
public String next() { |
|
246 |
ReaderData theReaderData = it.next(); |
|
247 |
return theReaderData.getName(); |
|
248 |
} |
|
249 |
}; |
|
250 |
} |
|
251 |
}; |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public Iterator<DataStore> iterator() { |
|
256 |
final Iterator<String> it = this.keySet().iterator(); |
|
257 |
return new Iterator<DataStore>() { |
|
258 |
@Override |
|
259 |
public boolean hasNext() { |
|
260 |
return it.hasNext(); |
|
261 |
} |
|
262 |
|
|
263 |
@Override |
|
264 |
public DataStore next() { |
|
265 |
String name = it.next(); |
|
266 |
return get(name); |
|
267 |
} |
|
268 |
}; |
|
269 |
} |
|
270 |
|
|
271 |
} |
|
272 |
|
|
176 | 273 |
private final ResourceProvider resource; |
177 | 274 |
|
178 | 275 |
private Envelope envelope; |
... | ... | |
180 | 277 |
private final SimpleTaskStatus taskStatus; |
181 | 278 |
private String name = ""; |
182 | 279 |
private final SimpleSequentialReaderFactory readerFactory; |
183 |
private final List<ReaderData> childrenData;
|
|
280 |
private List<ReaderData> childrenData; |
|
184 | 281 |
private ReaderData readerData; |
185 | 282 |
|
186 | 283 |
public SimpleSequentialReaderStoreProvider( |
... | ... | |
217 | 314 |
); |
218 | 315 |
|
219 | 316 |
resource.addConsumer(this); |
317 |
if( this.readerData!=null ) { |
|
318 |
this.name = this.readerData.getName(); |
|
319 |
} |
|
220 | 320 |
if( storeServices != null ) { |
221 | 321 |
initializeFeatureTypes(); |
222 | 322 |
} |
... | ... | |
547 | 647 |
break; |
548 | 648 |
} |
549 | 649 |
default: |
550 |
LOGGER.warn("Illegal argumente '"+option+"' in '"+getProviderName()+"' file '" + getFullFileName() + "'.");
|
|
650 |
LOGGER.warn("Illegal argumente '"+option+"' for field '"+this.name+"' in '"+getProviderName()+"' file '" + getFullFileName() + "' ("+value+").");
|
|
551 | 651 |
} |
552 | 652 |
} |
553 | 653 |
return true; |
... | ... | |
820 | 920 |
SimpleSequentialReader reader = this.readerFactory.createReader(this.getParameters()); |
821 | 921 |
try { |
822 | 922 |
loadFeatures(reader, theReaderData); |
823 |
|
|
923 |
this.childrenData = new ArrayList<>(); |
|
824 | 924 |
for(SimpleSequentialReader childReader : reader.getChildren() ) { |
825 | 925 |
ReaderData childData = new ReaderData(); |
826 | 926 |
loadFeatures(childReader, childData); |
... | ... | |
832 | 932 |
} |
833 | 933 |
} |
834 | 934 |
this.name = theReaderData.getName(); |
835 |
FeatureStoreProviderServices store = this.getStoreServices();
|
|
836 |
store.setFeatureTypes(theReaderData.getFeatureTypes(), theReaderData.getDefaultFeatureType());
|
|
935 |
FeatureStoreProviderServices theStore = this.getStoreServices();
|
|
936 |
theStore.setFeatureTypes(theReaderData.getFeatureTypes(), theReaderData.getDefaultFeatureType());
|
|
837 | 937 |
this.need_calculate_envelope = theReaderData.getNeedCalculateEnvelope(); |
838 | 938 |
this.data = theReaderData.getFeatures(); |
839 | 939 |
|
... | ... | |
1001 | 1101 |
} |
1002 | 1102 |
|
1003 | 1103 |
@Override |
1004 |
public DataStore getChild(String name) { |
|
1005 |
for (ReaderData childData : this.childrenData) { |
|
1006 |
if( StringUtils.equalsIgnoreCase(name, childData.getName()) ) { |
|
1007 |
try { |
|
1008 |
return childData.getStore(); |
|
1009 |
} catch (InitializeException ex) { |
|
1010 |
throw new RuntimeException("Can't acces to child '"+name+"'", ex); |
|
1011 |
} |
|
1012 |
} |
|
1013 |
} |
|
1014 |
return null; |
|
1104 |
public UnmodifiableBasicMap<String, DataStore> getChildren() { |
|
1105 |
return new Children(); |
|
1015 | 1106 |
} |
1016 |
|
|
1017 |
@Override |
|
1018 |
public Iterator<DataStore> getChildren() { |
|
1019 |
if( this.childrenData==null || this.childrenData.isEmpty() ) { |
|
1020 |
return Collections.EMPTY_LIST.iterator(); |
|
1021 |
} |
|
1022 |
try { |
|
1023 |
List<DataStore> children = new ArrayList<>(); |
|
1024 |
for (ReaderData childData : this.childrenData) { |
|
1025 |
children.add(childData.getStore()); |
|
1026 |
} |
|
1027 |
return children.iterator(); |
|
1028 |
} catch (InitializeException ex) { |
|
1029 |
throw new RuntimeException("Can't access to children", ex); |
|
1030 |
} |
|
1031 |
} |
|
1032 | 1107 |
|
1033 |
@Override |
|
1034 |
public boolean hasChildren() { |
|
1035 |
return this.childrenData!=null && !this.childrenData.isEmpty(); |
|
1036 |
} |
|
1037 |
|
|
1038 | 1108 |
} |
Also available in: Unified diff