Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / GMLFeaturesParser.java @ 11380

History | View | Annotate | Download (5.32 KB)

1
package org.gvsig.gpe.gml;
2

    
3
import java.awt.geom.Rectangle2D;
4

    
5
import org.gvsig.exceptions.BaseException;
6
import org.gvsig.gpe.gml.exceptions.GMLException;
7
import org.gvsig.gpe.gml.factories.IGeometriesFactory;
8
import org.gvsig.gpe.gml.schemas.XMLSchemaParser;
9
import org.kxml2.io.KXmlParser;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id: GMLFeaturesParser.java 10550 2007-02-28 11:49:30Z csanchez $
54
 * $Log$
55
 * Revision 1.1  2007-02-28 11:48:31  csanchez
56
 * *** empty log message ***
57
 *
58
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
59
 * A?adidos los proyectos de kml y gml antiguos
60
 *
61
 * Revision 1.3  2007/01/15 13:11:00  csanchez
62
 * Sistema de Warnings y Excepciones adaptado a BasicException
63
 *
64
 * Revision 1.2  2006/12/22 11:25:44  csanchez
65
 * Nuevo parser GML 2.x para gml's sin esquema
66
 *
67
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
68
 * Primer commit del driver de Gml
69
 *
70
 *
71
 */
72
/**
73
 * This class has all the methods that a GML parser
74
 * must implement. It has methods to parse some data and
75
 * methods to get info about the GML file
76
 * 
77
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
78
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
79
 * 
80
 */
81
public abstract class GMLFeaturesParser {
82
        private XMLSchemaParser parser = null;
83
        private IGeometriesFactory factory = null;
84
        private String documentRoot = null;        
85
        private Extent extent = null;
86
                
87
        public GMLFeaturesParser(IGeometriesFactory factory,XMLSchemaParser parser) throws Exception {
88
                super();
89
                this.factory = factory;
90
                this.parser = parser;
91
                initialize();
92
        }
93
        
94
        /**
95
         * Gets one iterator to retrieve all the 
96
         * GML features
97
         * @param file
98
         * File to parse
99
         * @return
100
         */
101
        public abstract IGMLFeaturesIterator getFeaturesReader() throws BaseException;        
102
        /**
103
         * It initializes the GML file. It parses all the GML code
104
         * that is located before the GML features
105
         * @throws GMLException
106
         */
107
        private void initialize() throws Exception{
108
                //It changes the namespace to "gml" for check all the features in the file
109
                parser.setSchema("gml");
110
                int currentTag;                
111
                                
112
                currentTag = parser.getEventType();                
113
                switch(currentTag){
114
                        case KXmlParser.START_TAG:
115
                                //This is the main tag of the document
116
                                documentRoot = parser.getName();
117
                                break;
118
                        case KXmlParser.END_TAG:                                
119
                                break;
120
                        case KXmlParser.TEXT:                   
121
                                break;
122
                }
123
                //now it parses the header of the file
124
                initializeHeader();
125
        }        
126
        
127
        /**
128
         * It initializes some GML fields like the BBOX, the imports,
129
         * etc. 
130
         * @throws GMLException
131
         * @throws BaseException 
132
         */
133
        public abstract void initializeHeader() throws BaseException;
134
                
135
        /**
136
         * @return Returns the extent.
137
         */
138
        public Extent getExtent() {
139
                return extent;
140
        }
141

    
142
        /**
143
         * @return Returns the documentRoot.
144
         */
145
        public String getDocumentRoot() {
146
                return documentRoot;
147
        }
148

    
149
        /**
150
         * @return Returns the factory.
151
         */
152
        public IGeometriesFactory getFactory() {
153
                return factory;
154
        }
155

    
156
        /**
157
         * @return Returns the parser.
158
         */
159
        public XMLSchemaParser getParser() {
160
                return parser;
161
        }
162

    
163
        /**
164
         * @param extent The extent to set.
165
         */
166
        public void setExtent(Extent extent) {
167
                this.extent = extent;
168
        }        
169
        
170
        /************************************************************************************
171
         * Class <Extent>                                                                                                                                        *
172
         * This class take the cords of reference where it will draw the shape                                *
173
         * Ussualy this references are indicated by the <boundedBy> tag.                                        *
174
         * <gml:boundedBy>                                                                                                                                        *
175
         *         <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#23030">                                *
176
         *                <gml:coordinates decimal="." cs="," ts=" ">                                                                        *
177
         *                -135.15989685058594,43.97196475963302 -41.46491900991063,76.32874354251143        *
178
         *                </gml:coordinates>                                                                                                                        *
179
         *         </gml:Box>                                                                                                                                                *
180
         * </gml:boundedBy>                                                                                                                                        *
181
         * **********************************************************************************/
182
        
183
        public static class Extent{
184
                private Rectangle2D extent = null;
185
                
186
                //it has the reference system.
187
                private String srs = null;
188
                
189
                public Extent(Rectangle2D extent, String srs) {
190
                        super();                        
191
                        this.extent = extent;
192
                        this.srs = srs;
193
                }
194
                /**
195
                 * @return Returns the extent.
196
                 */
197
                public Rectangle2D getExtent() {
198
                        return extent;
199
                }
200
                /**
201
                 * @return Returns the srs.
202
                 */
203
                public String getSrs() {
204
                        return srs;
205
                }
206
        }
207
}