2 |
2 |
|
3 |
3 |
import java.io.IOException;
|
4 |
4 |
import java.util.ArrayList;
|
|
5 |
import java.util.Hashtable;
|
|
6 |
import java.util.LinkedHashMap;
|
|
7 |
import java.util.Map;
|
5 |
8 |
|
6 |
9 |
import org.gvsig.remoteClient.gml.GMLException;
|
7 |
10 |
import org.gvsig.remoteClient.gml.GMLFileParseInfo;
|
... | ... | |
63 |
66 |
*
|
64 |
67 |
* $Id$
|
65 |
68 |
* $Log$
|
66 |
|
* Revision 1.6 2006-12-22 11:25:44 csanchez
|
|
69 |
* Revision 1.7 2006-12-29 17:22:17 jorpiell
|
|
70 |
* Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
|
|
71 |
*
|
|
72 |
* Revision 1.6 2006/12/22 11:25:44 csanchez
|
67 |
73 |
* Nuevo parser GML 2.x para gml's sin esquema
|
68 |
74 |
*
|
69 |
75 |
* Revision 1.5 2006/11/06 12:14:38 jorpiell
|
... | ... | |
186 |
192 |
private Object parseFeature(String elementName) throws GMLException {
|
187 |
193 |
int currentTag;
|
188 |
194 |
boolean end = false;
|
189 |
|
ArrayList params = new ArrayList();
|
190 |
|
ArrayList values = new ArrayList();
|
|
195 |
Hashtable values = new Hashtable();
|
191 |
196 |
Object geometry = null;
|
192 |
197 |
Object feature = null;
|
193 |
198 |
XMLElement entity = null;
|
... | ... | |
200 |
205 |
case KXmlParser.START_TAG:
|
201 |
206 |
entity = XMLElementsFactory.getElement(getParser().getName());
|
202 |
207 |
if (entity != null){
|
203 |
|
geometry = parseComplexFeature(entity,params,values,geometry);
|
|
208 |
geometry = parseComplexFeature(entity,values,geometry);
|
204 |
209 |
//When the feature is parsed, it's time to create it
|
205 |
210 |
if (geometry != null){
|
206 |
|
feature = getFactory().createSimpleFeature(entity.getName(),geometry,params,values);
|
|
211 |
feature = getFactory().createSimpleFeature(entity.getName(),entity.getEntityType(),values,geometry);
|
207 |
212 |
}
|
208 |
213 |
end = true;
|
209 |
214 |
}
|
210 |
215 |
//if the element doesn't exist, it tries to parse it without schema.
|
211 |
216 |
else{
|
212 |
|
geometry = parseComplexFeatureNoSchema(entityTag,params,values);
|
|
217 |
geometry = parseComplexFeatureNoSchema(entityTag,values);
|
213 |
218 |
//The feature is created without schema
|
214 |
219 |
if (geometry != null){
|
215 |
|
feature = getFactory().createSimpleFeature("GMLFeature",geometry,params,values);
|
|
220 |
feature = getFactory().createSimpleFeature("GMLFeature",null,values,geometry);
|
216 |
221 |
}
|
217 |
222 |
end = true;
|
218 |
223 |
}
|
... | ... | |
251 |
256 |
* @return geometry
|
252 |
257 |
* @throws GMLException
|
253 |
258 |
*/
|
254 |
|
private Object parseComplexFeature(XMLElement entity,ArrayList params,ArrayList values, Object geometry) throws GMLException{
|
|
259 |
private Object parseComplexFeature(XMLElement entity,Map values, Object geometry) throws GMLException{
|
255 |
260 |
int currentTag;
|
256 |
|
boolean end = false;
|
257 |
|
ArrayList myValues = new ArrayList();
|
258 |
|
ArrayList myParams = new ArrayList();
|
|
261 |
boolean end = false;
|
259 |
262 |
|
260 |
|
params.add(entity.getName());
|
261 |
|
values.add(null);
|
262 |
|
|
263 |
|
params.add(myParams);
|
264 |
|
values.add(myValues);
|
265 |
|
|
266 |
263 |
XMLComplexType entityType = (XMLComplexType)entity.getEntityType();
|
267 |
264 |
try{
|
268 |
265 |
currentTag = getParser().nextTag();
|
... | ... | |
280 |
277 |
if ((attribute != null)||(gmlGeometry.isGML()==true)){
|
281 |
278 |
if ((gmlGeometry.isGML()==true)||(attribute.getEntityType() != null)){
|
282 |
279 |
if ((gmlGeometry.isGML()==false)&&(attribute.getEntityType().getType() == IXMLType.SIMPLE)){
|
283 |
|
myParams.add(attName);
|
284 |
|
getParser().next();
|
285 |
|
myValues.add(((XMLSimpleType)attribute.getEntityType()).getJavaType(getParser().getText()));
|
|
280 |
if (attribute.isMultiple()){
|
|
281 |
ArrayList multiple = null;
|
|
282 |
if (values.get(attribute.getName()) == null){
|
|
283 |
multiple = new ArrayList();
|
|
284 |
}else{
|
|
285 |
multiple = (ArrayList)values.get(attribute.getName());
|
|
286 |
}
|
|
287 |
getParser().next();
|
|
288 |
multiple.add(((XMLSimpleType)attribute.getEntityType()).getJavaType(getParser().getText()));
|
|
289 |
values.put(attName,multiple);
|
|
290 |
}else{
|
|
291 |
getParser().next();
|
|
292 |
values.put(attName,((XMLSimpleType)attribute.getEntityType()).getJavaType(getParser().getText()));
|
|
293 |
}
|
286 |
294 |
}else if ((gmlGeometry.isGML()==true)||(attribute.getEntityType().getType() == IXMLType.GML_GEOMETRY)){
|
287 |
295 |
//if is GML geometry we try to parse it
|
288 |
296 |
if (gmlGeometry.isGeometryGML()==true){
|
... | ... | |
298 |
306 |
//Else, it don't do nothing
|
299 |
307 |
}
|
300 |
308 |
}else if ((gmlGeometry.isGML()==false)&&(attribute.getEntityType().getType() == IXMLType.COMPLEX)){
|
301 |
|
geometry=parseComplexFeature(attribute,myParams,myValues,geometry);
|
|
309 |
if (attribute.isMultiple()){
|
|
310 |
ArrayList multiple = null;
|
|
311 |
if (values.get(attName) == null){
|
|
312 |
multiple = new ArrayList();
|
|
313 |
}else{
|
|
314 |
multiple = (ArrayList)values.get(attribute.getName());
|
|
315 |
}
|
|
316 |
LinkedHashMap myValues = new LinkedHashMap();
|
|
317 |
geometry=parseComplexFeature(attribute,myValues,geometry);
|
|
318 |
multiple.add(myValues);
|
|
319 |
values.put(attName,multiple);
|
|
320 |
}else{
|
|
321 |
LinkedHashMap myValues = new LinkedHashMap();
|
|
322 |
geometry=parseComplexFeature(attribute,myValues,geometry);
|
|
323 |
values.put(attName,myValues);
|
|
324 |
}
|
302 |
325 |
}
|
303 |
326 |
}
|
304 |
327 |
}
|
... | ... | |
328 |
351 |
return geometry;
|
329 |
352 |
}
|
330 |
353 |
|
331 |
|
/**
|
332 |
|
* Parses a Complex type without Schema
|
333 |
|
* @param params
|
334 |
|
* @param values
|
335 |
|
* @return
|
336 |
|
* The geom
|
337 |
|
* @throws GMLException
|
338 |
|
*/
|
339 |
|
private Object parseComplexFeatureNoSchema(String entityTag,ArrayList params,ArrayList values) throws GMLException{
|
340 |
|
int currentTag;
|
341 |
|
boolean end = false;
|
342 |
|
Object geometry = null;
|
343 |
|
ArrayList myValues = new ArrayList();
|
344 |
|
ArrayList myParams = new ArrayList();
|
345 |
|
|
346 |
|
params.add("DEFAULT FEATURE");
|
347 |
|
values.add(null);
|
348 |
|
try{
|
349 |
|
currentTag = getParser().nextTag();
|
350 |
|
while (!end){
|
351 |
|
switch(currentTag){
|
352 |
|
case KXmlParser.START_TAG:
|
353 |
|
if (getParser().getName().compareTo(GMLTags.GML_BOUNDEDBY)==0){
|
354 |
|
GMLUtilsParser.parseBoundedBy(getParser());
|
355 |
|
}else{
|
356 |
|
String namespace = getParser().getNameSpace();
|
357 |
|
String tagName = getParser().getName();
|
358 |
|
GMLGeometries gmlGeometry = new GMLGeometries(tagName);
|
359 |
|
//If the tag hasn't namesapce it's local, maybe is an object declaration (or table component)
|
|
354 |
/**
|
|
355 |
* Parses a Complex type without Schema
|
|
356 |
* @param params
|
|
357 |
* @param values
|
|
358 |
* @return
|
|
359 |
* The geom
|
|
360 |
* @throws GMLException
|
|
361 |
*/
|
|
362 |
private Object parseComplexFeatureNoSchema(String entityTag,Map values) throws GMLException{
|
|
363 |
int currentTag;
|
|
364 |
boolean end = false;
|
|
365 |
Object geometry = null;
|
360 |
366 |
|
361 |
|
/**************
|
362 |
|
* <GEOMETRY> *
|
363 |
|
**************/
|
364 |
|
if ((namespace.compareTo("gml") == 0)||(gmlGeometry.isGML())){
|
365 |
|
//if is GML geometry we try to parse it
|
366 |
|
if (gmlGeometry.isGeometryGML()==true){
|
367 |
|
geometry = GMLUtilsParser.parseGeometry(getParser(),tagName,getFactory());
|
|
367 |
try{
|
|
368 |
currentTag = getParser().nextTag();
|
|
369 |
while (!end){
|
|
370 |
switch(currentTag){
|
|
371 |
case KXmlParser.START_TAG:
|
|
372 |
if (getParser().getName().compareTo(GMLTags.GML_BOUNDEDBY)==0){
|
|
373 |
GMLUtilsParser.parseBoundedBy(getParser());
|
|
374 |
}else{
|
|
375 |
String namespace = getParser().getNameSpace();
|
|
376 |
String tagName = getParser().getName();
|
|
377 |
GMLGeometries gmlGeometry = new GMLGeometries(tagName);
|
|
378 |
//If the tag hasn't namesapce it's local, maybe is an object declaration (or table component)
|
|
379 |
|
|
380 |
/**************
|
|
381 |
* <GEOMETRY> *
|
|
382 |
**************/
|
|
383 |
if ((namespace.compareTo("gml") == 0)||(gmlGeometry.isGML())){
|
|
384 |
//if is GML geometry we try to parse it
|
|
385 |
if (gmlGeometry.isGeometryGML()==true){
|
|
386 |
geometry = GMLUtilsParser.parseGeometry(getParser(),tagName,getFactory());
|
|
387 |
}
|
|
388 |
else{
|
|
389 |
if (gmlGeometry.isFeatureGML()==false){
|
|
390 |
warnings.setElement(GMLFileParseInfo.WAR_WRONG_NAMESPACE);
|
|
391 |
//MAYBE IT HAD SCHEMA AND IS A GEOM DECLARED THERE, WE CAN TAKE IT LIKE THE IDENTIFIER OF THE GEOM
|
|
392 |
}
|
|
393 |
//Else it do nothing
|
|
394 |
}
|
368 |
395 |
}
|
|
396 |
/**********
|
|
397 |
* <DATA> *
|
|
398 |
**********/
|
369 |
399 |
else{
|
370 |
|
if (gmlGeometry.isFeatureGML()==false){
|
371 |
|
warnings.setElement(GMLFileParseInfo.WAR_WRONG_NAMESPACE);
|
372 |
|
//MAYBE IT HAD SCHEMA AND IS A GEOM DECLARED THERE, WE CAN TAKE IT LIKE THE IDENTIFIER OF THE GEOM
|
|
400 |
//If another namespace it should be tables data
|
|
401 |
//it checks that it isn't geometry hide in other namespace
|
|
402 |
if (gmlGeometry.isGML()==false){
|
|
403 |
currentTag = getParser().next();
|
|
404 |
String nextTagName = getParser().getName();
|
|
405 |
gmlGeometry = new GMLGeometries(nextTagName);
|
|
406 |
/****************
|
|
407 |
* <SIMPLE> *
|
|
408 |
****************/
|
|
409 |
if (currentTag==KXmlParser.TEXT){
|
|
410 |
//it gets the value of the param,
|
|
411 |
//it doesn't know what type is, it takes string to default.
|
|
412 |
String texto = getParser().getText();
|
|
413 |
values.put(tagName,texto);
|
|
414 |
|
|
415 |
}
|
|
416 |
/****************
|
|
417 |
* <COMPLEX> *
|
|
418 |
****************/
|
|
419 |
else
|
|
420 |
{
|
|
421 |
goNextTag = false;
|
|
422 |
LinkedHashMap myValues = new LinkedHashMap();
|
|
423 |
parseComplexFeatureNoSchema("COMPLEX FEATURE",myValues);
|
|
424 |
values.put(tagName,myValues);
|
|
425 |
}
|
373 |
426 |
}
|
374 |
|
//Else it do nothing
|
375 |
|
}
|
|
427 |
}
|
376 |
428 |
}
|
377 |
|
/**********
|
378 |
|
* <DATA> *
|
379 |
|
**********/
|
380 |
|
else{
|
381 |
|
//If another namespace it should be tables data
|
382 |
|
//it checks that it isn't geometry hide in other namespace
|
383 |
|
if (gmlGeometry.isGML()==false){
|
384 |
|
myParams.add(tagName);
|
385 |
|
currentTag = getParser().next();
|
386 |
|
String nextTagName = getParser().getName();
|
387 |
|
gmlGeometry = new GMLGeometries(nextTagName);
|
388 |
|
/****************
|
389 |
|
* <SIMPLE> *
|
390 |
|
****************/
|
391 |
|
if (currentTag==KXmlParser.TEXT){
|
392 |
|
//it gets the value of the param,
|
393 |
|
//it doesn't know what type is, it takes string to default.
|
394 |
|
String texto = getParser().getText();
|
395 |
|
myValues.add(texto);
|
396 |
|
}
|
397 |
|
/****************
|
398 |
|
* <COMPLEX> *
|
399 |
|
****************/
|
400 |
|
else
|
401 |
|
{
|
402 |
|
myParams.remove(tagName);
|
403 |
|
goNextTag = false;
|
404 |
|
parseComplexFeatureNoSchema("COMPLEX FEATURE",myParams,myValues);
|
405 |
|
}
|
406 |
|
}
|
407 |
|
}
|
|
429 |
break;
|
|
430 |
case KXmlParser.END_TAG:
|
|
431 |
if ((getParser().getName().compareTo(entityTag) == 0)||(getParser().getName().compareTo(getFeatureRoot()) == 0)){
|
|
432 |
end = true;
|
|
433 |
}
|
|
434 |
break;
|
|
435 |
case KXmlParser.TEXT:
|
|
436 |
break;
|
408 |
437 |
}
|
409 |
|
break;
|
410 |
|
case KXmlParser.END_TAG:
|
411 |
|
if ((getParser().getName().compareTo(entityTag) == 0)||(getParser().getName().compareTo(getFeatureRoot()) == 0)){
|
412 |
|
end = true;
|
|
438 |
if ((!end)&&(goNextTag==true)){
|
|
439 |
currentTag = getParser().next();
|
|
440 |
}
|
|
441 |
else{
|
|
442 |
goNextTag = true;
|
413 |
443 |
}
|
414 |
|
break;
|
415 |
|
case KXmlParser.TEXT:
|
416 |
|
break;
|
417 |
444 |
}
|
418 |
|
if ((!end)&&(goNextTag==true)){
|
419 |
|
currentTag = getParser().next();
|
420 |
|
}
|
421 |
|
else{
|
422 |
|
goNextTag = true;
|
423 |
|
}
|
424 |
|
}
|
425 |
|
}catch (XmlPullParserException e) {
|
426 |
|
// TODO Auto-generated catch block
|
427 |
|
e.printStackTrace();
|
428 |
|
throw new GMLException(GMLException.EXC_PARSE);
|
429 |
|
} catch (IOException e) {
|
430 |
|
// TODO Auto-generated catch block
|
431 |
|
e.printStackTrace();
|
432 |
|
throw new GMLException(GMLException.EXC_READ_FILE);
|
433 |
|
}
|
434 |
|
params.add(myParams);
|
435 |
|
values.add(myValues);
|
436 |
|
return geometry;
|
437 |
|
}
|
|
445 |
}catch (XmlPullParserException e) {
|
|
446 |
// TODO Auto-generated catch block
|
|
447 |
e.printStackTrace();
|
|
448 |
throw new GMLException(GMLException.EXC_PARSE);
|
|
449 |
} catch (IOException e) {
|
|
450 |
// TODO Auto-generated catch block
|
|
451 |
e.printStackTrace();
|
|
452 |
throw new GMLException(GMLException.EXC_READ_FILE);
|
|
453 |
}
|
|
454 |
return geometry;
|
|
455 |
}
|
438 |
456 |
|
439 |
457 |
}
|