Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / GMLFeaturesParser.java @ 9729

History | View | Annotate | Download (5.18 KB)

1
package org.gvsig.remoteClient.gml;
2

    
3
import java.awt.geom.Rectangle2D;
4

    
5
import org.gvsig.exceptions.BaseException;
6
import org.gvsig.remoteClient.gml.exceptions.GMLException;
7
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
8
import org.gvsig.remoteClient.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 9729 2007-01-15 13:11:17Z csanchez $
54
 * $Log$
55
 * Revision 1.3  2007-01-15 13:11:00  csanchez
56
 * Sistema de Warnings y Excepciones adaptado a BasicException
57
 *
58
 * Revision 1.2  2006/12/22 11:25:44  csanchez
59
 * Nuevo parser GML 2.x para gml's sin esquema
60
 *
61
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
62
 * Primer commit del driver de Gml
63
 *
64
 *
65
 */
66
/**
67
 * This class has all the methods that a GML parser
68
 * must implement. It has methods to parse some data and
69
 * methods to get info about the GML file
70
 * 
71
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
72
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
73
 * 
74
 */
75
public abstract class GMLFeaturesParser {
76
        private XMLSchemaParser parser = null;
77
        private IGeometriesFactory factory = null;
78
        private String documentRoot = null;        
79
        private Extent extent = null;
80
                
81
        public GMLFeaturesParser(IGeometriesFactory factory,XMLSchemaParser parser) throws Exception {
82
                super();
83
                this.factory = factory;
84
                this.parser = parser;
85
                initialize();
86
        }
87
        
88
        /**
89
         * Gets one iterator to retrieve all the 
90
         * GML features
91
         * @param file
92
         * File to parse
93
         * @return
94
         */
95
        public abstract IGMLFeaturesIterator getFeaturesReader() throws BaseException;        
96
        /**
97
         * It initializes the GML file. It parses all the GML code
98
         * that is located before the GML features
99
         * @throws GMLException
100
         */
101
        private void initialize() throws Exception{
102
                //It changes the namespace to "gml" for check all the features in the file
103
                parser.setSchema("gml");
104
                int currentTag;                
105
                                
106
                currentTag = parser.getEventType();                
107
                switch(currentTag){
108
                        case KXmlParser.START_TAG:
109
                                //This is the main tag of the document
110
                                documentRoot = parser.getName();
111
                                break;
112
                        case KXmlParser.END_TAG:                                
113
                                break;
114
                        case KXmlParser.TEXT:                   
115
                                break;
116
                }
117
                //now it parses the header of the file
118
                initializeHeader();
119
        }        
120
        
121
        /**
122
         * It initializes some GML fields like the BBOX, the imports,
123
         * etc. 
124
         * @throws GMLException
125
         * @throws BaseException 
126
         */
127
        public abstract void initializeHeader() throws BaseException;
128
                
129
        /**
130
         * @return Returns the extent.
131
         */
132
        public Extent getExtent() {
133
                return extent;
134
        }
135

    
136
        /**
137
         * @return Returns the documentRoot.
138
         */
139
        public String getDocumentRoot() {
140
                return documentRoot;
141
        }
142

    
143
        /**
144
         * @return Returns the factory.
145
         */
146
        public IGeometriesFactory getFactory() {
147
                return factory;
148
        }
149

    
150
        /**
151
         * @return Returns the parser.
152
         */
153
        public XMLSchemaParser getParser() {
154
                return parser;
155
        }
156

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