Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / geometries / GeometryBinding.java @ 11720

History | View | Annotate | Download (6.75 KB)

1
package org.gvsig.gpe.gml.bindings.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.GMLProjectionFactory;
8
import org.gvsig.gpe.gml.GMLTags;
9
import org.gvsig.gpe.gml.GPEGmlParser;
10
import org.gvsig.gpe.gml.utils.CompareUtils;
11
import org.kxml2.io.KXmlParser;
12
import org.xmlpull.v1.XmlPullParser;
13
import org.xmlpull.v1.XmlPullParserException;
14

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

    
108
                String tag = parser.getName();
109
                currentTag = parser.getEventType();
110

    
111

    
112
                switch(currentTag){
113
                case KXmlParser.START_TAG:
114
                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINTMEMBER)){
115
                                geometry = PointMemberTypeBinding.parse(parser, handler);
116
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINT)){
117
                                geometry = PointTypeBinding.parse(parser, handler);
118
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINTPROPERTY)){
119
                                geometry = PointPropertyTypeBinding.parse(parser, handler);
120
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRINGMEMBER)){
121
                                geometry = LineStringMemberTypeBinding.parse(parser, handler);
122
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRING)){
123
                                geometry = LineStringTypeBinding.parse(parser, handler);
124
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINEARRING)){
125
                                geometry = LinearRingTypeBinding.parse(parser, handler);
126
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRINGPROPERTY)){
127
                                geometry = LineStringPropertyTypeBinding.parse(parser, handler);
128
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGONMEMBER)){
129
                                geometry = PolygonMemberTypeBinding.parse(parser, handler);
130
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGON)){
131
                                geometry = PolygonTypeBinding.parse(parser, handler);
132
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POLYGONPROPERTY)){
133
                                geometry = PolygonPropertyTypeBinding.parse(parser, handler);
134
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_GEOMETRYMEMBER)){
135
                                geometry = GeometryMemberTypeBinding.parse(parser, handler);
136
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_GEOMETRYPROPERTY)){
137
                                geometry = GeometryPropertyTypeBinding.parse(parser, handler);
138
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOINT)){
139
                                geometry = MultiPointTypeBinding.parse(parser, handler);
140
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOINTPROPERTY)){
141
                                geometry = MultiPointPropertyTypeBinding.parse(parser, handler);
142
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILINESTRING)){
143
                                geometry = MultiLineStringTypeBinding.parse(parser, handler);
144
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILINESTRINGPROPERTY)){
145
                                geometry = MultiLineStringPropertyTypeBinding.parse(parser, handler);
146
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOLYGON)){
147
                                geometry = MultiPolygonTypeBinding.parse(parser, handler);
148
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIPOLYGONPROPERTY)){
149
                                geometry = MultiPolygonPropertyTypeBinding.parse(parser, handler);
150
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIGEOMETRY)){
151
                                geometry = MultiGeometryTypeBinding.parse(parser, handler);
152
                        }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIGEOMETRYPROPERTY)){
153
                                geometry = MultiGeometryPropertyTypeBinding.parse(parser, handler);
154
                        }
155
                        break;
156
                }                                        
157
                return geometry;        
158
        }
159
        
160
        /**
161
         * It returns a the geometry id attribute
162
         * @param hash
163
         * Hashtable with the XML attributes
164
         * @return
165
         * The id
166
         */
167
        public static String getID(Hashtable hash){
168
                Object obj = hash.get(GMLTags.GML_GID);
169
                if (obj != null){
170
                        return (String)obj;
171
                }
172
                return null;
173
        }        
174
        
175
        /**
176
         * It returns a the geometry srs attribute
177
         * @param hash
178
         * Hashtable with the XML attributes
179
         * @param errorHandler
180
         * To add posible errors
181
         * @return
182
         * The srs
183
         */
184
        public static String getSrs(Hashtable hash, GPEErrorHandler errorHandler){
185
                Object obj = hash.get(GMLTags.GML_SRS_NAME);
186
                if (obj != null){
187
                        return GMLProjectionFactory.fromGMLToGPE((String)obj, errorHandler);
188
                }
189
                return null;
190
        }
191
        
192
}