Revision 9508

View differences:

trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/types/XMLComplexType.java
52 52
 *
53 53
 * $Id$
54 54
 * $Log$
55
 * Revision 1.1  2006-12-22 11:25:04  csanchez
55
 * Revision 1.2  2006-12-29 17:22:17  jorpiell
56
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
57
 *
58
 * Revision 1.1  2006/12/22 11:25:04  csanchez
56 59
 * Nuevo parser GML 2.x para gml's sin esquema
57 60
 *
58 61
 * Revision 1.7  2006/10/31 13:52:37  ppiqueras
......
89 92
 * 
90 93
 */
91 94
public class XMLComplexType implements IXMLType {
95
	public static int SEQUENCE_TYPE = 0;
96
	public static int CHOICE_TYPE = 1;
97
	
92 98
	private String type = null;
93 99
	private LinkedHashMap attributes = null;
100
	private int attributesType = 0; 
94 101
			
95 102
	public XMLComplexType(String type) {
96 103
		super();
......
151 158
		}
152 159
		return vector;
153 160
	}
161

  
162
	public int getAttributesType() {
163
		return attributesType;
164
	}
165

  
166
	public void setAttributesType(int attributesType) {
167
		this.attributesType = attributesType;
168
	}
154 169
	
155 170
	
156 171
	
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/types/XMLSimpleType.java
46 46
 *
47 47
 * $Id$
48 48
 * $Log$
49
 * Revision 1.1  2006-12-22 11:25:04  csanchez
49
 * Revision 1.2  2006-12-29 17:22:17  jorpiell
50
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
51
 *
52
 * Revision 1.1  2006/12/22 11:25:04  csanchez
50 53
 * Nuevo parser GML 2.x para gml's sin esquema
51 54
 *
52 55
 * Revision 1.5  2006/10/11 11:21:00  jorpiell
......
86 89
	public static final String INT = "xs:int";
87 90
	
88 91
	private String type = null;
89
		
92
	private String name = null;
90 93
	
91
	
92 94
	public XMLSimpleType(String type) {
93 95
		super();
96
		this.name = type;
94 97
		this.type = type;
95 98
	}
99
	
100
	public XMLSimpleType(String name, String type) {
101
		super();
102
		this.name = name;
103
		this.type = type;
104
	}
96 105

  
97 106
	/*
98 107
	 *  (non-Javadoc)
99 108
	 * @see org.gvsig.remoteClient.gml.IXMLType#getName()
100 109
	 */
101 110
	public String getName() {
102
		return type;
111
		return name;
103 112
	}
104 113
	
105 114
	/*
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/v2/GMLSimpleFeature_v2.java
1 1
package org.gvsig.remoteClient.gml.v2;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.Hashtable;
5
import java.util.Map;
4 6

  
5 7
import org.gvsig.remoteClient.gml.GMLSimpleFeature;
8
import org.gvsig.remoteClient.gml.schemas.XMLElement;
9
import org.gvsig.remoteClient.gml.types.IXMLType;
10
import org.gvsig.remoteClient.gml.types.XMLComplexType;
6 11

  
7 12

  
8 13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
49 54
 *
50 55
 * $Id$
51 56
 * $Log$
52
 * Revision 1.2  2006-12-22 11:25:44  csanchez
57
 * Revision 1.3  2006-12-29 17:22:17  jorpiell
58
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
59
 *
60
 * Revision 1.2  2006/12/22 11:25:44  csanchez
53 61
 * Nuevo parser GML 2.x para gml's sin esquema
54 62
 *
55 63
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
......
62 70
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
63 71
 */
64 72
public class GMLSimpleFeature_v2 extends GMLSimpleFeature {
65
	private ArrayList params  = null;
66
	private ArrayList values  = null;
73
	private IXMLType type = null;
74
	private Map values  = null;
67 75
	private Object geom = null;
68 76
	
69
	public GMLSimpleFeature_v2(String name, ArrayList params, ArrayList values, Object geom) {
70
		super(name);
71
		this.params = params;
77
	/**
78
	 * GML without schema
79
	 * @param name
80
	 * @param values
81
	 * @param geom
82
	 */
83
	public GMLSimpleFeature_v2(String name, Map values, Object geom) {
84
		super(name);		
72 85
		this.values = values;
73 86
		this.geom = geom;
74 87
	}
75

  
88
	
76 89
	/**
77
	 * Gets tha attribute name
78
	 * @param attName
79
	 * @return
90
	 * GML with schema
91
	 * @param name
92
	 * @param type
93
	 * @param values
94
	 * @param geom
80 95
	 */
81
	public String getAttribute(String attName){
82
		for (int i=0 ; i<params.size() ; i++){
83
			if (params.get(i).equals(attName)){
84
				return (String)values.get(i);
85
			}
86
		}
87
		return null;
96
	public GMLSimpleFeature_v2(String name, IXMLType type, Map values, Object geom) {
97
		super(name);		
98
		this.values = values;
99
		this.geom = geom;
100
		this.type = type;
88 101
	}
89 102

  
103

  
90 104
	/**
91
	 * @return Returns the fields.
105
	 * @return Returns the type.
92 106
	 */
93
	public ArrayList getParams() {
94
		return params;
107
	public IXMLType getType() {
108
		return type;
95 109
	}
96 110

  
97 111
	/**
......
104 118
	/**
105 119
	 * @return Returns the values.
106 120
	 */
107
	public ArrayList getValues() {
121
	public Map getValues() {
108 122
		return values;
109 123
	}
110 124
	
125
	
111 126
}
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/v2/GMLFeaturesIterator_v2.java
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
}

Also available in: Unified diff