Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / GeometryBinding.java @ 19366

History | View | Annotate | Download (9.92 KB)

1
package org.gvsig.gpe.gml.parser.v2.geometries;
2

    
3
import java.io.IOException;
4
import java.util.Hashtable;
5

    
6
import org.gvsig.gpe.GPEErrorHandler;
7
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser;
8
import org.gvsig.gpe.gml.utils.CompareUtils;
9
import org.gvsig.gpe.gml.utils.GMLProjectionFactory;
10
import org.gvsig.gpe.gml.utils.GMLTags;
11
import org.gvsig.gpe.gml.utils.GMLUtilsParser;
12
import org.kxml2.io.KXmlParser;
13
import org.xmlpull.v1.XmlPullParser;
14
import org.xmlpull.v1.XmlPullParserException;
15

    
16
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
17
 *
18
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
19
 *
20
 * This program is free software; you can redistribute it and/or
21
 * modify it under the terms of the GNU General Public License
22
 * as published by the Free Software Foundation; either version 2
23
 * of the License, or (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
33
 *
34
 * For more information, contact:
35
 *
36
 *  Generalitat Valenciana
37
 *   Conselleria d'Infraestructures i Transport
38
 *   Av. Blasco Ib??ez, 50
39
 *   46010 VALENCIA
40
 *   SPAIN
41
 *
42
 *      +34 963862235
43
 *   gvsig@gva.es
44
 *      www.gvsig.gva.es
45
 *
46
 *    or
47
 *
48
 *   IVER T.I. S.A
49
 *   Salamanca 50
50
 *   46005 Valencia
51
 *   Spain
52
 *
53
 *   +34 963163400
54
 *   dac@iver.es
55
 */
56
/* CVS MESSAGES:
57
 *
58
 * $Id:GeometryBinding.java 195 2007-11-26 09:02:22Z jpiera $
59
 * $Log$
60
 * Revision 1.7  2007/05/24 07:29:47  csanchez
61
 * A?adidos Alias GML2
62
 *
63
 * Revision 1.6  2007/05/18 10:41:01  csanchez
64
 * Actualizaci?n libGPE-GML eliminaci?n de clases inecesarias
65
 *
66
 * Revision 1.5  2007/05/15 11:55:11  jorpiell
67
 * MultiGeometry is now supported
68
 *
69
 * Revision 1.4  2007/05/15 07:30:38  jorpiell
70
 * Add the geometryProperties tags
71
 *
72
 * Revision 1.3  2007/05/14 11:18:51  jorpiell
73
 * ProjectionFactory updated
74
 *
75
 * Revision 1.2  2007/05/14 09:31:06  jorpiell
76
 * Add the a new class to compare tags
77
 *
78
 * Revision 1.1  2007/05/08 10:24:16  jorpiell
79
 * Add comments to create javadocs
80
 *
81
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
82
 * Add some methods to manage the multigeometries
83
 *
84
 * Revision 1.1  2007/05/07 07:06:46  jorpiell
85
 * Add a constructor with the name and the description fields
86
 *
87
 *
88
 */
89
/**
90
 * This class parses a geometry. It is also used 
91
 * to get the attributes for a GML geometry. 
92
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
93
 */
94
public class GeometryBinding {
95
        protected String srsName = null;
96
        protected String id = null;
97
        
98
        /**
99
         * It parses the gml:Geometry tag
100
         * @param parser
101
         * The XML parser
102
         * @param handler
103
         * The GPE parser that contains the content handler and
104
         * the error handler
105
         * @return
106
         * A geometry
107
         * @throws XmlPullParserException
108
         * @throws IOException
109
         */
110
        public Object parse(XmlPullParser parser,GPEDefaultGmlParser handler) throws XmlPullParserException, IOException {
111
                int currentTag;
112
                Object geometry = null;                
113

    
114
                String tag = parser.getName();
115
                currentTag = parser.getEventType();
116

    
117

    
118
                switch(currentTag){
119
                case KXmlParser.START_TAG:
120
                        geometry = parseTag(parser, handler, tag);
121
                        break;
122
                }                                        
123
                return geometry;        
124
        }
125
        
126
        /**
127
         * It parses an XML tag
128
         * @param parser
129
         * @param handler
130
         * @param tag
131
         * @return
132
         * @throws XmlPullParserException
133
         * @throws IOException
134
         */
135
        protected Object parseTag(XmlPullParser parser,GPEDefaultGmlParser handler, String tag) throws XmlPullParserException, IOException{
136
                Object geometry = null;
137
                //PROPERTIES
138
                if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_GEOMETRYPROPERTY)){
139
                        geometry = handler.getProfile().getGeometryPropertyTypeBinding().
140
                        parse(parser, handler);
141
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINTPROPERTY)){
142
                        geometry = handler.getProfile().getPointPropertyTypeBinding().
143
                        parse(parser, handler);
144
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRINGPROPERTY)){
145
                        geometry = handler.getProfile().getLineStringPropertyTypeBinding().
146
                        parse(parser, handler);
147
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGONPROPERTY)){
148
                        geometry = handler.getProfile().getPolygonPropertyTypeBinding().
149
                        parse(parser, handler);
150
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOINTPROPERTY)){
151
                        geometry = handler.getProfile().getMultiPointPropertyTypeBinding().
152
                        parse(parser, handler);
153
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILINESTRINGPROPERTY)){
154
                        geometry = handler.getProfile().getMultiLineStringPropertyTypeBinding().
155
                        parse(parser, handler);
156
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOLYGONPROPERTY)){
157
                        geometry = handler.getProfile().getMultiPolygonPropertyTypeBinding().
158
                        parse(parser, handler);
159
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIGEOMETRYPROPERTY)){
160
                        geometry = handler.getProfile().getMultiGeometryPropertyTypeBinding().
161
                        parse(parser, handler);
162
                }
163
                //GEOMETRIES
164
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINTMEMBER)){
165
                        geometry = handler.getProfile().getPointMemberTypeBinding().
166
                        parse(parser, handler);
167
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINT)){
168
                        geometry = handler.getProfile().getPointTypeBinding().
169
                        parse(parser, handler);
170
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRINGMEMBER)){
171
                        geometry = handler.getProfile().getLineStringMemberTypeBinding().
172
                        parse(parser, handler);
173
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRING)){
174
                        geometry = handler.getProfile().getLineStringTypeBinding().
175
                        parse(parser, handler);
176
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINEARRING)){
177
                        geometry = handler.getProfile().getLinearRingTypeBinding().
178
                        parse(parser, handler);
179
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGONMEMBER)){
180
                        geometry = handler.getProfile().getPointMemberTypeBinding().
181
                        parse(parser, handler);
182
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGON)){
183
                        geometry = handler.getProfile().getPolygonTypeBinding().
184
                        parse(parser, handler);
185
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_GEOMETRYMEMBER)){
186
                        geometry = handler.getProfile().getGeometryMemberTypeBinding().
187
                        parse(parser, handler);
188
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOINT)){
189
                        geometry = handler.getProfile().getMultiPointTypeBinding().
190
                        parse(parser, handler);
191
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILINESTRING)){
192
                        geometry = handler.getProfile().getMultiLineStringTypeBinding().
193
                        parse(parser, handler);
194
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOLYGON)){
195
                        geometry = handler.getProfile().getMultiPolygonTypeBinding().
196
                        parse(parser, handler);
197
                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIGEOMETRY)){
198
                        geometry = handler.getProfile().getMultiGeometryTypeBinding().
199
                        parse(parser, handler);
200
                }
201
                //POINT PROPERTY ALIASES
202
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LOCATION) ||
203
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_CENTEROF) ||
204
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POSITION)){
205
                        geometry = handler.getProfile().getPointTypeBinding().
206
                        parse(parser, handler);
207
                }
208
                //LINESTRING PROPERTY ALIASES
209
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_EDGEOF) ||
210
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_CENTERLINEOF)){
211
                        geometry = handler.getProfile().getLineStringPropertyTypeBinding().
212
                        parse(parser, handler);
213
                }
214
                //POLYGON PROPERTY ALIASES
215
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_EXTENTOF) ||
216
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_COVERAGE)){
217
                        geometry = handler.getProfile().getPolygonPropertyTypeBinding().
218
                        parse(parser, handler);
219
                }
220
                //MULTIPOINT PROPERTY ALIASES
221
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILOCATION) ||
222
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOSITION)){
223
                        geometry = handler.getProfile().getMultiPointPropertyTypeBinding().
224
                        parse(parser, handler);
225
                }
226
                //MULTILINESTRING PROPERTY ALIASES
227
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIEDGEOF) ||
228
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTICENTERLINEOF)){
229
                        geometry =handler.getProfile().getMultiLineStringPropertyTypeBinding().
230
                        parse(parser, handler);
231
                }
232
                //MULTIPOLYGON PROPERTY ALIASES
233
                else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIEXTENTOF) ||
234
                                CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTICOVERAGE)){
235
                        geometry = handler.getProfile().getMultiPolygonTypeBinding().
236
                        parse(parser, handler);
237
                }
238
                return geometry;
239
        }
240
        
241
        /**
242
         * This method has to be invoked by all the geometries
243
         * before to make the parse process. It retrieves
244
         * the common geometry attributes
245
         * @param parser
246
         * The root geometry tag
247
         * @param errorHandler
248
         * To add the errors
249
         */
250
        protected void setAtributtes(XmlPullParser parser, GPEErrorHandler errorHandler){
251
                Hashtable attributes = GMLUtilsParser.getAttributes(parser);
252
                Object objId = attributes.get(GMLTags.GML_GID);
253
                if (objId != null){
254
                        id = (String)objId;
255
                }else{
256
                        id = null;
257
                }
258
                Object objSrs = attributes.get(GMLTags.GML_SRS_NAME);
259
                if (objSrs != null){
260
                        srsName = GMLProjectionFactory.fromGMLToGPE((String)objSrs, errorHandler);
261
                }else{
262
                        srsName = null;
263
                }
264
        }
265
        
266
        /**
267
         * It returns a the geometry id attribute
268
         * @return
269
         * The id
270
         */
271
        public String getID(){
272
                return id;
273
        }        
274

    
275
        /**
276
         * It returns a the geometry srs attribute
277
         * @return
278
         * The srs
279
         */
280
        public String getSrs(){
281
                return srsName;
282
        }
283

    
284
}