Revision 32446
branches/v2_0_0_prep/libraries/org.gvsig.arcims/src/org/gvsig/remoteclient/arcims/ArcImsProtFeatureHandler.java | ||
---|---|---|
42 | 42 |
import java.net.URL; |
43 | 43 |
import java.util.ArrayList; |
44 | 44 |
import java.util.Date; |
45 |
import java.util.Hashtable; |
|
46 | 45 |
import java.util.Iterator; |
47 | 46 |
import java.util.List; |
48 | 47 |
import java.util.StringTokenizer; |
49 | 48 |
import java.util.Vector; |
50 | 49 |
|
51 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
|
52 | 50 |
import org.gvsig.fmap.geom.Geometry; |
53 | 51 |
import org.gvsig.fmap.geom.GeometryLocator; |
54 | 52 |
import org.gvsig.fmap.geom.GeometryManager; |
... | ... | |
58 | 56 |
import org.gvsig.fmap.geom.primitive.Point; |
59 | 57 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
60 | 58 |
import org.gvsig.remoteclient.arcims.utils.ArcImsDownloadUtils; |
59 |
import org.gvsig.remoteclient.arcims.utils.ArcImsFeature; |
|
61 | 60 |
import org.gvsig.remoteclient.arcims.utils.FieldInformation; |
62 | 61 |
import org.gvsig.remoteclient.arcims.utils.GetFeaturesTags; |
63 | 62 |
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags; |
... | ... | |
87 | 86 |
* table |
88 | 87 |
* @throws ArcImsException |
89 | 88 |
*/ |
90 |
public List getMap(ArcImsVectStatus status) throws ArcImsException { |
|
89 |
public List<List<ArcImsFeature>> getMap(ArcImsVectStatus status) |
|
90 |
throws ArcImsException { |
|
91 | 91 |
logger.info("Start getMap"); |
92 | 92 |
|
93 |
List array = new ArrayList();
|
|
93 |
List<List<ArcImsFeature>> array = new ArrayList<List<ArcImsFeature>>();
|
|
94 | 94 |
|
95 | 95 |
try { |
96 | 96 |
/* |
... | ... | |
134 | 134 |
reader = br; |
135 | 135 |
|
136 | 136 |
logger.debug("Start features with attributes parsing"); |
137 |
array.add(this.getFeatures(reader, status.getServiceInfo(), |
|
138 |
layerId, status.getSubfields(), 1)); |
|
137 |
List<ArcImsFeature> feats = this.getFeatures(reader, status |
|
138 |
.getServiceInfo(), layerId, status.getSubfields(), 1); |
|
139 |
array.add(feats); |
|
139 | 140 |
logger.debug("End features with attributes parsing"); |
140 | 141 |
} |
141 | 142 |
|
... | ... | |
174 | 175 |
* @return ArrayList of IFeatures or Value[] |
175 | 176 |
* @throws ArcImsException |
176 | 177 |
*/ |
177 |
private Hashtable getFeatures(Reader lector, ServiceInformation si,
|
|
178 |
String layerId, String[] subfields, int withGeometries)
|
|
179 |
throws ArcImsException { |
|
178 |
private List<ArcImsFeature> getFeatures(Reader lector,
|
|
179 |
ServiceInformation si, String layerId, String[] subfields,
|
|
180 |
int withGeometries) throws ArcImsException {
|
|
180 | 181 |
|
181 |
// TODO |
|
182 |
// clear features map |
|
183 |
// this.features.clear(); |
|
184 |
|
|
185 | 182 |
// fill features map |
186 | 183 |
FieldInformation fi = null; |
187 | 184 |
ServiceInformationLayerFeatures sil = (ServiceInformationLayerFeatures) si |
... | ... | |
230 | 227 |
/* |
231 | 228 |
* ArrayList with features |
232 | 229 |
*/ |
233 |
List<DefaultFeature> features = new ArrayList<DefaultFeature>();
|
|
230 |
List<ArcImsFeature> features = new ArrayList<ArcImsFeature>();
|
|
234 | 231 |
|
235 | 232 |
/* |
236 | 233 |
* Start parsing |
... | ... | |
238 | 235 |
int tag; |
239 | 236 |
KXmlParser kxmlParser = new KXmlParser(); |
240 | 237 |
|
241 |
FileReader fr = null; |
|
242 | 238 |
Geometry geom = null; |
239 |
Object[] values = new Object[fieldsInfoA.size()]; |
|
243 | 240 |
// Value[] values = new Value[fieldsInfoA.size()]; |
244 |
// int[] position = new int[fieldsInfoA.size()]; |
|
245 |
// |
|
246 |
// // Initialize position array |
|
247 |
// for (int i = 0; i < position.length; i++) |
|
248 |
// position[i] = -1; |
|
249 |
// |
|
250 |
// // long timeFeat = 0; |
|
251 |
// // long timeGeom = 0; |
|
252 |
// // long timeTemp = 0; |
|
253 |
// try { |
|
254 |
// kxmlParser.setInput(lector); |
|
255 |
// kxmlParser.nextTag(); |
|
256 |
// |
|
257 |
// if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) { |
|
258 |
// kxmlParser.require(KXmlParser.START_TAG, null, |
|
259 |
// ServiceInfoTags.tARCXML); |
|
260 |
// tag = kxmlParser.nextTag(); |
|
261 |
// |
|
262 |
// while (tag != KXmlParser.END_DOCUMENT) { |
|
263 |
// switch (tag) { |
|
264 |
// case KXmlParser.START_TAG: |
|
265 |
// |
|
266 |
// if (kxmlParser.getName().compareTo( |
|
267 |
// GetFeaturesTags.FEATURE) == 0) { |
|
268 |
// /* |
|
269 |
// * parse FEATURES' tag |
|
270 |
// */ |
|
271 |
// |
|
272 |
// // FIRST ENVELOPE TAG (We hope that ENVELOPE will |
|
273 |
// // ALLWAYS be returned at first...) |
|
274 |
// if (withGeometries == 2) { |
|
275 |
// // timeTemp = System.currentTimeMillis(); |
|
276 |
// geom = parseEnvelopeFromFeatureTag(kxmlParser, |
|
277 |
// delDec); |
|
278 |
// } |
|
279 |
// |
|
280 |
// // SECOND FIELDS TAG |
|
281 |
// // timeTemp = System.currentTimeMillis(); |
|
282 |
// values = parseValuesFromFeatureTag(kxmlParser, // the |
|
283 |
// // kxml |
|
284 |
// // parser |
|
285 |
// fieldsInfoA, // Hashmap with names and |
|
286 |
// // FieldInformation objects) |
|
287 |
// delDec, // the separators |
|
288 |
// position // the relative positions of |
|
289 |
// // returned values |
|
290 |
// ); |
|
291 |
// |
|
292 |
// // timeFeat += System.currentTimeMillis() - |
|
293 |
// // timeTemp; |
|
294 |
// |
|
295 |
// // If geometries are neede we add to the ArrayList |
|
296 |
// // the Ifeature |
|
297 |
// if (withGeometries == 1) { |
|
298 |
// // THIRD GEOMETRIES |
|
299 |
// // timeTemp = System.currentTimeMillis(); |
|
300 |
// geom = parseGeomFromFeatureTag(kxmlParser, // the |
|
301 |
// // kxml |
|
302 |
// // parser |
|
303 |
// delTuple, delCoords, delDec // the |
|
304 |
// // separators |
|
305 |
// ); |
|
306 |
// |
|
307 |
// // timeGeom += System.currentTimeMillis() - |
|
308 |
// // timeTemp; |
|
309 |
// } |
|
310 |
// |
|
311 |
// // If some geometry is created, we add a IFeature |
|
312 |
// // into features ArrayList |
|
313 |
// if (withGeometries > 0) { |
|
314 |
// features.add(new DefaultFeature(geom, values)); |
|
315 |
// } |
|
316 |
// // Else we only need the Value[] array |
|
317 |
// else { |
|
318 |
// features.add(values); |
|
319 |
// } |
|
320 |
// } else if (kxmlParser.getName().compareTo( |
|
321 |
// GetFeaturesTags.FEATURECOUNT) == 0) { |
|
322 |
// String value = new String(); |
|
323 |
// |
|
324 |
// // Get the feature count |
|
325 |
// value = kxmlParser.getAttributeValue("", |
|
326 |
// GetFeaturesTags.COUNT); |
|
327 |
// |
|
328 |
// Integer intFeatCount = new Integer(value); |
|
329 |
// featCount += intFeatCount.intValue(); |
|
330 |
// |
|
331 |
// // Get the hasmore boolean |
|
332 |
// value = kxmlParser.getAttributeValue("", |
|
333 |
// GetFeaturesTags.HASMORE); |
|
334 |
// |
|
335 |
// Boolean boHasMore = new Boolean(value); |
|
336 |
// hasMore = boHasMore.booleanValue(); |
|
337 |
// } else if (kxmlParser.getName().compareTo( |
|
338 |
// ServiceInfoTags.tERROR) == 0) { |
|
339 |
// logger.error("Error parsing GET_FEATURES:\r\n" |
|
340 |
// + kxmlParser.nextText()); |
|
341 |
// throw new ArcImsException("arcims_server_error"); |
|
342 |
// } |
|
343 |
// |
|
344 |
// break; |
|
345 |
// |
|
346 |
// case KXmlParser.END_TAG: |
|
347 |
// break; |
|
348 |
// |
|
349 |
// case KXmlParser.TEXT: |
|
350 |
// break; |
|
351 |
// } |
|
352 |
// |
|
353 |
// tag = kxmlParser.next(); |
|
354 |
// } |
|
355 |
// |
|
356 |
// kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
|
357 |
// } |
|
358 |
// } catch (ParseException pe) { |
|
359 |
// logger.error(pe.getMessage(), pe); |
|
360 |
// throw new ArcImsException("arcims_no_features"); |
|
361 |
// } catch (XmlPullParserException parser_ex) { |
|
362 |
// logger.error(parser_ex.getMessage(), parser_ex); |
|
363 |
// throw new ArcImsException("arcims_no_features"); |
|
364 |
// } catch (IOException ioe) { |
|
365 |
// logger.error(ioe.getMessage(), ioe); |
|
366 |
// throw new ArcImsException("arcims_no_features"); |
|
367 |
// } |
|
368 |
// |
|
369 |
// // logger.debug("Time for parsing features " + timeFeat + " msecs"); |
|
370 |
// // logger.debug("Time for parsing geometries " + timeGeom + |
|
371 |
// " msecs"); |
|
372 |
// return features; |
|
373 |
return null; |
|
241 |
int[] position = new int[fieldsInfoA.size()]; |
|
242 |
|
|
243 |
// Initialize position array |
|
244 |
for (int i = 0; i < position.length; i++) |
|
245 |
position[i] = -1; |
|
246 |
|
|
247 |
// long timeFeat = 0; |
|
248 |
// long timeGeom = 0; |
|
249 |
// long timeTemp = 0; |
|
250 |
try { |
|
251 |
kxmlParser.setInput(lector); |
|
252 |
kxmlParser.nextTag(); |
|
253 |
|
|
254 |
if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) { |
|
255 |
kxmlParser.require(KXmlParser.START_TAG, null, |
|
256 |
ServiceInfoTags.tARCXML); |
|
257 |
tag = kxmlParser.nextTag(); |
|
258 |
|
|
259 |
while (tag != KXmlParser.END_DOCUMENT) { |
|
260 |
switch (tag) { |
|
261 |
case KXmlParser.START_TAG: |
|
262 |
|
|
263 |
if (kxmlParser.getName().compareTo( |
|
264 |
GetFeaturesTags.FEATURE) == 0) { |
|
265 |
/* |
|
266 |
* parse FEATURES' tag |
|
267 |
*/ |
|
268 |
|
|
269 |
// FIRST ENVELOPE TAG (We hope that ENVELOPE will |
|
270 |
// ALLWAYS be returned at first...) |
|
271 |
if (withGeometries == 2) { |
|
272 |
// timeTemp = System.currentTimeMillis(); |
|
273 |
geom = parseEnvelopeFromFeatureTag(kxmlParser, |
|
274 |
delDec); |
|
275 |
} |
|
276 |
|
|
277 |
// SECOND FIELDS TAG |
|
278 |
// timeTemp = System.currentTimeMillis(); |
|
279 |
values = parseValuesFromFeatureTag(kxmlParser, // the |
|
280 |
// kxml |
|
281 |
// parser |
|
282 |
fieldsInfoA, // Hashmap with names and |
|
283 |
// FieldInformation objects) |
|
284 |
delDec, // the separators |
|
285 |
position // the relative positions of |
|
286 |
// returned values |
|
287 |
); |
|
288 |
|
|
289 |
// timeFeat += System.currentTimeMillis() - |
|
290 |
// timeTemp; |
|
291 |
|
|
292 |
// If geometries are neede we add to the ArrayList |
|
293 |
// the Ifeature |
|
294 |
if (withGeometries == 1) { |
|
295 |
// THIRD GEOMETRIES |
|
296 |
// timeTemp = System.currentTimeMillis(); |
|
297 |
geom = parseGeomFromFeatureTag(kxmlParser, // the |
|
298 |
// kxml |
|
299 |
// parser |
|
300 |
delTuple, delCoords, delDec // the |
|
301 |
// separators |
|
302 |
); |
|
303 |
|
|
304 |
// timeGeom += System.currentTimeMillis() - |
|
305 |
// timeTemp; |
|
306 |
} |
|
307 |
|
|
308 |
// If some geometry is created, we add a IFeature |
|
309 |
// into features ArrayList |
|
310 |
if (withGeometries > 0) { |
|
311 |
features.add(new ArcImsFeature(geom, values)); |
|
312 |
} |
|
313 |
// Else we only need the Value[] array |
|
314 |
else { |
|
315 |
features.add(new ArcImsFeature(values)); |
|
316 |
} |
|
317 |
} else if (kxmlParser.getName().compareTo( |
|
318 |
GetFeaturesTags.FEATURECOUNT) == 0) { |
|
319 |
String value = new String(); |
|
320 |
|
|
321 |
// Get the feature count |
|
322 |
value = kxmlParser.getAttributeValue("", |
|
323 |
GetFeaturesTags.COUNT); |
|
324 |
|
|
325 |
Integer intFeatCount = new Integer(value); |
|
326 |
featCount += intFeatCount.intValue(); |
|
327 |
|
|
328 |
// Get the hasmore boolean |
|
329 |
value = kxmlParser.getAttributeValue("", |
|
330 |
GetFeaturesTags.HASMORE); |
|
331 |
|
|
332 |
Boolean boHasMore = new Boolean(value); |
|
333 |
hasMore = boHasMore.booleanValue(); |
|
334 |
} else if (kxmlParser.getName().compareTo( |
|
335 |
ServiceInfoTags.tERROR) == 0) { |
|
336 |
logger.error("Error parsing GET_FEATURES:\r\n" |
|
337 |
+ kxmlParser.nextText()); |
|
338 |
throw new ArcImsException("arcims_server_error"); |
|
339 |
} |
|
340 |
|
|
341 |
break; |
|
342 |
|
|
343 |
case KXmlParser.END_TAG: |
|
344 |
break; |
|
345 |
|
|
346 |
case KXmlParser.TEXT: |
|
347 |
break; |
|
348 |
} |
|
349 |
|
|
350 |
tag = kxmlParser.next(); |
|
351 |
} |
|
352 |
|
|
353 |
kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
|
354 |
} |
|
355 |
} |
|
356 |
|
|
357 |
catch (XmlPullParserException parser_ex) { |
|
358 |
logger.error(parser_ex.getMessage(), parser_ex); |
|
359 |
throw new ArcImsException("arcims_no_features"); |
|
360 |
} catch (IOException ioe) { |
|
361 |
logger.error(ioe.getMessage(), ioe); |
|
362 |
throw new ArcImsException("arcims_no_features"); |
|
363 |
} catch (CreateGeometryException e) { |
|
364 |
logger.error(e.getMessage(), e); |
|
365 |
throw new ArcImsException("arcims_no_features"); |
|
366 |
} |
|
367 |
|
|
368 |
return features; |
|
369 |
|
|
374 | 370 |
} |
375 | 371 |
|
376 | 372 |
/** |
... | ... | |
386 | 382 |
throws XmlPullParserException, IOException { |
387 | 383 |
int currentTag; |
388 | 384 |
boolean end = false; |
389 |
int f = 0; |
|
390 |
String att; |
|
391 |
String val; |
|
392 |
int type; |
|
393 | 385 |
|
394 | 386 |
BoundaryBox bb = null; |
395 | 387 |
|
... | ... | |
463 | 455 |
* @throws ParseException |
464 | 456 |
*/ |
465 | 457 |
private Object[] parseValuesFromFeatureTag(KXmlParser parser, |
466 |
List fieldsInfoA, char delDec, int[] position) |
|
458 |
List<FieldInformation> fieldsInfoA, char delDec, int[] position)
|
|
467 | 459 |
throws XmlPullParserException, IOException, ArcImsException { |
468 | 460 |
|
469 | 461 |
int currentTag; |
... | ... | |
697 | 689 |
List<Point> points = parseCoords(strPoints, |
698 | 690 |
delTuple, delCoords, delDec); |
699 | 691 |
|
700 |
Iterator it = points.iterator(); |
|
692 |
Iterator<Point> it = points.iterator();
|
|
701 | 693 |
Point point; |
702 | 694 |
|
703 | 695 |
// First we MOVE to the first point of the path |
... | ... | |
899 | 891 |
* @return |
900 | 892 |
* @throws ArcImsException |
901 | 893 |
*/ |
902 |
public List getAttributes(ArcImsVectStatus status, String[] subfields, |
|
903 |
String where, Rectangle2D envelope) throws ArcImsException { |
|
894 |
public List<List<ArcImsFeature>> getAttributes(ArcImsVectStatus status, |
|
895 |
String[] subfields, String where, Rectangle2D envelope) |
|
896 |
throws ArcImsException { |
|
904 | 897 |
|
905 | 898 |
logger.info("Start getAttributes"); |
906 | 899 |
|
907 |
List valuesArray = new ArrayList();
|
|
900 |
List<List<ArcImsFeature>> features = new ArrayList<List<ArcImsFeature>>();
|
|
908 | 901 |
|
909 | 902 |
// Clone the status and set temporal subfields and where clause |
910 | 903 |
ArcImsVectStatus statusCloned = status; |
... | ... | |
989 | 982 |
String layerId = (String) statusCloned.getLayerIds().get(0); |
990 | 983 |
logger.debug("Start attributes downloading and parsing (" |
991 | 984 |
+ featCount + ") ids retrieved"); |
992 |
valuesArray.add(getFeatures(br, statusCloned.getServiceInfo(),
|
|
985 |
features.add(getFeatures(br, statusCloned.getServiceInfo(),
|
|
993 | 986 |
layerId, statusCloned.getSubfields(), 0)); |
994 | 987 |
logger.debug("End attributes downloading and parsing"); |
995 | 988 |
} |
... | ... | |
1010 | 1003 |
|
1011 | 1004 |
logger.debug("End attributes retrieving"); |
1012 | 1005 |
|
1013 |
return valuesArray;
|
|
1006 |
return features;
|
|
1014 | 1007 |
} |
1015 | 1008 |
|
1016 | 1009 |
/** |
... | ... | |
1025 | 1018 |
* @return |
1026 | 1019 |
* @throws ArcImsException |
1027 | 1020 |
*/ |
1028 |
public ArrayList getAttributesWithEnvelope(ArcImsVectStatus status,
|
|
1029 |
String[] subfields, String where, Rectangle2D envelope)
|
|
1030 |
throws ArcImsException { |
|
1021 |
public List<List<ArcImsFeature>> getAttributesWithEnvelope(
|
|
1022 |
ArcImsVectStatus status, String[] subfields, String where,
|
|
1023 |
Rectangle2D envelope) throws ArcImsException {
|
|
1031 | 1024 |
|
1032 | 1025 |
logger.info("Start getAttributesWihtEnvelope"); |
1033 | 1026 |
|
1034 |
ArrayList valuesArray = new ArrayList();
|
|
1027 |
List<List<ArcImsFeature>> features = new ArrayList<List<ArcImsFeature>>();
|
|
1035 | 1028 |
|
1036 | 1029 |
// Clone the status and set temporal subfields and where clause |
1037 | 1030 |
ArcImsVectStatus statusCloned = status; |
... | ... | |
1116 | 1109 |
String layerId = (String) statusCloned.getLayerIds().get(0); |
1117 | 1110 |
logger.debug("Start attributes downloading and parsing (" |
1118 | 1111 |
+ featCount + ") ids retrieved"); |
1119 |
valuesArray.add(getFeatures(br, statusCloned.getServiceInfo(),
|
|
1112 |
features.add(getFeatures(br, statusCloned.getServiceInfo(),
|
|
1120 | 1113 |
layerId, statusCloned.getSubfields(), 2)); // Here we |
1121 | 1114 |
// request |
1122 | 1115 |
// envelopes instead |
... | ... | |
1140 | 1133 |
|
1141 | 1134 |
logger.debug("End attributes retrieving"); |
1142 | 1135 |
|
1143 |
return valuesArray;
|
|
1136 |
return features;
|
|
1144 | 1137 |
} |
1145 | 1138 |
|
1146 | 1139 |
/* |
... | ... | |
1155 | 1148 |
throw new ClassCastException( |
1156 | 1149 |
"Invalid request, this method is only valid for Image Services"); |
1157 | 1150 |
} |
1158 |
} |
|
1151 |
} |
Also available in: Unified diff