svn-gvsig-desktop / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / v2 / GMLFeaturesIterator_v2.java @ 6722
History | View | Annotate | Download (5.86 KB)
1 |
package org.gvsig.remoteClient.gml.v2; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Vector; |
6 |
|
7 |
import org.gvsig.remoteClient.gml.GMLException; |
8 |
import org.gvsig.remoteClient.gml.IGMLFeaturesIterator; |
9 |
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
10 |
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory; |
11 |
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory; |
12 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
13 |
import org.gvsig.remoteClient.gml.schemas.XMLComplexType; |
14 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
15 |
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser; |
16 |
import org.gvsig.remoteClient.gml.schemas.XMLSimpleType; |
17 |
import org.gvsig.remoteClient.gml.utils.GMLUtilsParser; |
18 |
import org.kxml2.io.KXmlParser; |
19 |
import org.xmlpull.v1.XmlPullParserException; |
20 |
|
21 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
22 |
*
|
23 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
24 |
*
|
25 |
* This program is free software; you can redistribute it and/or
|
26 |
* modify it under the terms of the GNU General Public License
|
27 |
* as published by the Free Software Foundation; either version 2
|
28 |
* of the License, or (at your option) any later version.
|
29 |
*
|
30 |
* This program is distributed in the hope that it will be useful,
|
31 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
32 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
33 |
* GNU General Public License for more details.
|
34 |
*
|
35 |
* You should have received a copy of the GNU General Public License
|
36 |
* along with this program; if not, write to the Free Software
|
37 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
38 |
*
|
39 |
* For more information, contact:
|
40 |
*
|
41 |
* Generalitat Valenciana
|
42 |
* Conselleria d'Infraestructures i Transport
|
43 |
* Av. Blasco Ib??ez, 50
|
44 |
* 46010 VALENCIA
|
45 |
* SPAIN
|
46 |
*
|
47 |
* +34 963862235
|
48 |
* gvsig@gva.es
|
49 |
* www.gvsig.gva.es
|
50 |
*
|
51 |
* or
|
52 |
*
|
53 |
* IVER T.I. S.A
|
54 |
* Salamanca 50
|
55 |
* 46005 Valencia
|
56 |
* Spain
|
57 |
*
|
58 |
* +34 963163400
|
59 |
* dac@iver.es
|
60 |
*/
|
61 |
/* CVS MESSAGES:
|
62 |
*
|
63 |
* $Id: GMLFeaturesIterator_v2.java 6722 2006-08-10 12:00:49Z jorpiell $
|
64 |
* $Log$
|
65 |
* Revision 1.1 2006-08-10 12:00:49 jorpiell
|
66 |
* Primer commit del driver de Gml
|
67 |
*
|
68 |
*
|
69 |
*/
|
70 |
/**
|
71 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
72 |
*/
|
73 |
public class GMLFeaturesIterator_v2 extends IGMLFeaturesIterator { |
74 |
|
75 |
public GMLFeaturesIterator_v2(XMLSchemaParser parser, IGeometriesFactory factory) {
|
76 |
super(parser, factory);
|
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
* @see org.gvsig.remoteClient.gml.IGMLFeaturesIterator#hasNext()
|
82 |
*/
|
83 |
public boolean hasNext() throws GMLException { |
84 |
if (getParser().getName().compareTo(getFeatureRoot()) == 0){ |
85 |
return true; |
86 |
} |
87 |
return false; |
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
* @see org.gvsig.remoteClient.gml.IGMLFeaturesIterator#next()
|
93 |
*/
|
94 |
public Object next() throws GMLException { |
95 |
boolean endFeature = false; |
96 |
Object feature = null; |
97 |
int currentTag;
|
98 |
|
99 |
try {
|
100 |
currentTag = getParser().next(); |
101 |
while (!endFeature){
|
102 |
switch(currentTag){
|
103 |
case KXmlParser.START_TAG:
|
104 |
feature = parseFeature(); |
105 |
break;
|
106 |
case KXmlParser.END_TAG:
|
107 |
if (getParser().getName().compareTo(getFeatureRoot()) == 0) |
108 |
endFeature = true;
|
109 |
break;
|
110 |
case KXmlParser.TEXT:
|
111 |
break;
|
112 |
} |
113 |
currentTag = getParser().next(); |
114 |
} |
115 |
}catch (XmlPullParserException e) {
|
116 |
// TODO Auto-generated catch block
|
117 |
e.printStackTrace(); |
118 |
throw new GMLException(GMLException.EXC_PARSE); |
119 |
} catch (IOException e) { |
120 |
// TODO Auto-generated catch block
|
121 |
e.printStackTrace(); |
122 |
throw new GMLException(GMLException.EXC_READ_FILE); |
123 |
} |
124 |
return feature;
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* It parses a Feature
|
129 |
* @throws IOException
|
130 |
* @throws XmlPullParserException
|
131 |
*
|
132 |
*/
|
133 |
private Object parseFeature() throws GMLException { |
134 |
int currentTag;
|
135 |
boolean end = false; |
136 |
|
137 |
try {
|
138 |
currentTag = getParser().getEventType(); |
139 |
String featureType = null; |
140 |
|
141 |
if ((getParser().getName() != null) && (featureType == null)){ |
142 |
featureType = getParser().getName(); |
143 |
return parseSpecificFeature(featureType);
|
144 |
} |
145 |
}catch (XmlPullParserException e) {
|
146 |
e.printStackTrace(); |
147 |
throw new GMLException(GMLException.EXC_PARSE); |
148 |
} |
149 |
return null; |
150 |
|
151 |
} |
152 |
|
153 |
private Object parseSpecificFeature(String elementName) throws GMLException { |
154 |
int currentTag;
|
155 |
boolean end = false; |
156 |
ArrayList params = new ArrayList(); |
157 |
ArrayList values = new ArrayList();; |
158 |
Object geom = null; |
159 |
|
160 |
XMLElement element = XMLElementsFactory.getElement(elementName); |
161 |
XMLComplexType elementType = (XMLComplexType)element.getType(); |
162 |
if (element != null){ |
163 |
try{
|
164 |
currentTag = getParser().next(); |
165 |
while (!end){
|
166 |
switch(currentTag){
|
167 |
case KXmlParser.START_TAG:
|
168 |
String attName = getParser().getName();
|
169 |
XMLElement attribute = elementType.getElement(attName); |
170 |
if (attribute != null){ |
171 |
if (attribute.getType().getType() == IXMLType.SIMPLE){
|
172 |
params.add(attName); |
173 |
getParser().next(); |
174 |
values.add(((XMLSimpleType)attribute.getType()).getObject(getParser().getText())); |
175 |
}else if (attribute.getType().getType() == IXMLType.GML_GEOMETRY){ |
176 |
geom = GMLUtilsParser.parseGeometry(getParser(),attName,getFactory()); |
177 |
}else if (attribute.getType().getType() == IXMLType.COMPLEX){ |
178 |
//Not in GML v2
|
179 |
} |
180 |
} |
181 |
break;
|
182 |
case KXmlParser.END_TAG:
|
183 |
if ((getParser().getName().compareTo(elementName) == 0)) |
184 |
end = true;
|
185 |
break;
|
186 |
case KXmlParser.TEXT:
|
187 |
break;
|
188 |
} |
189 |
if (!end){
|
190 |
currentTag = getParser().next(); |
191 |
} |
192 |
} |
193 |
}catch (XmlPullParserException e) {
|
194 |
// TODO Auto-generated catch block
|
195 |
e.printStackTrace(); |
196 |
throw new GMLException(GMLException.EXC_PARSE); |
197 |
} catch (IOException e) { |
198 |
// TODO Auto-generated catch block
|
199 |
e.printStackTrace(); |
200 |
throw new GMLException(GMLException.EXC_READ_FILE); |
201 |
} |
202 |
} |
203 |
return getFactory().createSimpleFeature(elementName,geom,params,values);
|
204 |
} |
205 |
|
206 |
} |