root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / GMLReader.java @ 9729
History | View | Annotate | Download (6.38 KB)
1 |
package org.gvsig.remoteClient.gml; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.File; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.IOException; |
7 |
|
8 |
import org.gvsig.exceptions.BaseException; |
9 |
import org.gvsig.exceptions.ListBaseException; |
10 |
import org.gvsig.remoteClient.gml.exceptions.GMLException; |
11 |
import org.gvsig.remoteClient.gml.exceptions.GMLParserException; |
12 |
import org.gvsig.remoteClient.gml.factories.FeaturesParserFactory; |
13 |
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
14 |
import org.gvsig.remoteClient.gml.factories.XMLParserFactory; |
15 |
import org.gvsig.remoteClient.gml.schemas.XMLSchemaManager; |
16 |
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser; |
17 |
import org.gvsig.remoteClient.gml.warnings.GMLWarningInfo; |
18 |
import org.xmlpull.v1.XmlPullParserException; |
19 |
|
20 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
21 |
*
|
22 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* as published by the Free Software Foundation; either version 2
|
27 |
* of the License, or (at your option) any later version.
|
28 |
*
|
29 |
* This program is distributed in the hope that it will be useful,
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
* GNU General Public License for more details.
|
33 |
*
|
34 |
* You should have received a copy of the GNU General Public License
|
35 |
* along with this program; if not, write to the Free Software
|
36 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
37 |
*
|
38 |
* For more information, contact:
|
39 |
*
|
40 |
* Generalitat Valenciana
|
41 |
* Conselleria d'Infraestructures i Transport
|
42 |
* Av. Blasco Ib??ez, 50
|
43 |
* 46010 VALENCIA
|
44 |
* SPAIN
|
45 |
*
|
46 |
* +34 963862235
|
47 |
* gvsig@gva.es
|
48 |
* www.gvsig.gva.es
|
49 |
*
|
50 |
* or
|
51 |
*
|
52 |
* IVER T.I. S.A
|
53 |
* Salamanca 50
|
54 |
* 46005 Valencia
|
55 |
* Spain
|
56 |
*
|
57 |
* +34 963163400
|
58 |
* dac@iver.es
|
59 |
*/
|
60 |
/* CVS MESSAGES:
|
61 |
*
|
62 |
* $Id: GMLReader.java 9729 2007-01-15 13:11:17Z csanchez $
|
63 |
* $Log$
|
64 |
* Revision 1.4 2007-01-15 13:11:00 csanchez
|
65 |
* Sistema de Warnings y Excepciones adaptado a BasicException
|
66 |
*
|
67 |
* Revision 1.3 2006/12/22 11:25:44 csanchez
|
68 |
* Nuevo parser GML 2.x para gml's sin esquema
|
69 |
*
|
70 |
* Revision 1.2 2006/11/06 12:15:11 jorpiell
|
71 |
* A?adido un constructor con un par?metro booleano que se usar? para abrir gml's sin validar el esquema
|
72 |
*
|
73 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell
|
74 |
* Primer commit del driver de Gml
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
/**
|
79 |
* This class must be used to read any GML 2.x file (2.0, 2.1.1
|
80 |
* 2.1.2). It is able to parse GML features that have a xml complex
|
81 |
* type with only one level of complexity. More levels and GML 3.x
|
82 |
* will be supported in next versions.
|
83 |
*
|
84 |
* Name: OpenGIS? Geography Markup Language (GML) Implementation Specification,
|
85 |
* Version: 2.x
|
86 |
* Project Document: 01-029 (2.0), 02-099 (2.1.1) and 02-069 (v2.1.2)
|
87 |
*
|
88 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
89 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
|
90 |
*
|
91 |
*/
|
92 |
public class GMLReader { |
93 |
private XMLSchemaManager schemaManager = null; |
94 |
private GMLFeaturesParser featuresParser = null; |
95 |
private FeaturesParserFactory featuresFactory = null; |
96 |
private GMLWarningInfo warnings = null; |
97 |
private File m_File = null; |
98 |
|
99 |
|
100 |
/**
|
101 |
* Constructor
|
102 |
* @param file
|
103 |
* GML File to read
|
104 |
* @param factory
|
105 |
* Geometries factory that is used to create the parsed
|
106 |
* GML geometries
|
107 |
* @throws Exception
|
108 |
* @throws FileNotFoundException
|
109 |
* When the file is not found
|
110 |
*/
|
111 |
public GMLReader(File file,IGeometriesFactory factory) throws GMLException{ |
112 |
|
113 |
//file to parse...
|
114 |
this.m_File = file;
|
115 |
initialize(factory); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Initializes the XMLSchemaParser, tries to parse the GML header
|
120 |
* to obtain the GML version and parses all the needed schemas
|
121 |
* @param factory
|
122 |
* Geometries factory that is used to create the parsed
|
123 |
* GML geometries
|
124 |
* @throws Exception
|
125 |
*/
|
126 |
private void initialize(IGeometriesFactory factory) throws GMLException{ |
127 |
|
128 |
warnings = new GMLWarningInfo();
|
129 |
XMLSchemaParser parser = new XMLParserFactory().createSchemaParser(m_File);
|
130 |
|
131 |
//Retrieve the header attributes and download and parse the schema
|
132 |
schemaManager = new XMLSchemaManager(m_File);
|
133 |
try {
|
134 |
schemaManager.parse(parser); |
135 |
} catch (XmlPullParserException e) {
|
136 |
// TODO Auto-generated catch block
|
137 |
throw new GMLException(m_File.getName(),e); |
138 |
} catch (IOException e) { |
139 |
// TODO Auto-generated catch block
|
140 |
throw new GMLException(m_File.getName(),e); |
141 |
} |
142 |
|
143 |
//Parse the GML global fields
|
144 |
featuresFactory = new FeaturesParserFactory();
|
145 |
try {
|
146 |
featuresParser = featuresFactory.createParser(getVersion(),factory,parser); |
147 |
} catch (GMLParserException e) {
|
148 |
throw new GMLException(m_File.getName(),e); |
149 |
} |
150 |
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Gets the GML iteartor used to retrieve all the
|
155 |
* features
|
156 |
* @param factory
|
157 |
* Factory to create the geometries
|
158 |
* @return
|
159 |
*/
|
160 |
public IGMLFeaturesIterator getFeaturesIterator() throws GMLException{ |
161 |
try {
|
162 |
return featuresParser.getFeaturesReader();
|
163 |
} catch (BaseException e) {
|
164 |
throw new GMLException(e); |
165 |
} |
166 |
} |
167 |
|
168 |
/**
|
169 |
* @return Returns the version.
|
170 |
*/
|
171 |
public String getVersion(){ |
172 |
return schemaManager.getVersion();
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* @return Returns a list of codes with information to the user about GML parse.
|
177 |
* @throws ListBaseException
|
178 |
*/
|
179 |
public ListBaseException getWarnings(){
|
180 |
if (schemaManager.warnings.areWarnings())
|
181 |
{ |
182 |
warnings.setGMLWarningList(schemaManager.warnings.getGMLWarningList()); |
183 |
} |
184 |
if (featuresFactory.warnings.areWarnings())
|
185 |
{ |
186 |
warnings.setGMLWarningList(featuresFactory.warnings.getGMLWarningList()); |
187 |
} |
188 |
//***********************************************************
|
189 |
// CUIDADO CON LANZAR LOS WARNINGS, YA VEREMOS COMO LANZARLOS
|
190 |
//***********************************************************
|
191 |
return warnings.getGMLWarningList();
|
192 |
|
193 |
} |
194 |
|
195 |
// /**
|
196 |
// * @return Returns true if there are warnings parsing the gml file.
|
197 |
// */
|
198 |
// public boolean areWarnings(){
|
199 |
// this.getWarnings();
|
200 |
// if (warnings.areWarnings())
|
201 |
// {
|
202 |
// return true;
|
203 |
// }
|
204 |
// return false;
|
205 |
// }
|
206 |
|
207 |
/**
|
208 |
* @return Returns the target namespace.
|
209 |
*/
|
210 |
public String getTargetNamespace(){ |
211 |
return schemaManager.getTargetNamespace();
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* @return Returns the extent.
|
216 |
*/
|
217 |
public Rectangle2D getExtent(){ |
218 |
return featuresParser.getExtent().getExtent();
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* @return Returns the SRS
|
223 |
*/
|
224 |
public String getSRS(){ |
225 |
return featuresParser.getExtent().getSrs();
|
226 |
} |
227 |
} |