Statistics
| Revision:

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

History | View | Annotate | Download (4.61 KB)

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

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser;
6
import org.gvsig.gpe.gml.utils.CompareUtils;
7
import org.gvsig.gpe.gml.utils.GMLTags;
8
import org.kxml2.io.KXmlParser;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id:MultiGeometryTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
55
 * $Log$
56
 * Revision 1.5  2007/05/14 11:18:51  jorpiell
57
 * ProjectionFactory updated
58
 *
59
 * Revision 1.4  2007/05/14 09:52:53  jorpiell
60
 * Nullpointer exception fixed
61
 *
62
 * Revision 1.3  2007/05/14 09:31:06  jorpiell
63
 * Add the a new class to compare tags
64
 *
65
 * Revision 1.2  2007/05/08 10:24:16  jorpiell
66
 * Add comments to create javadocs
67
 *
68
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
69
 * Add some methods to manage the multigeometries
70
 *
71
 *
72
 */
73
/**
74
 * It parses a gml:MultiGeometryType object. Example:
75
 * <p>
76
 * <pre>
77
 * <code> 
78
 * &lt;MultiGeometry gid="c731" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"&gt;
79
 * &lt;geometryMember&gt;
80
 * &lt;Point gid="P6776"&gt;
81
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
82
 * &lt;/Point&gt;
83
 * &lt;/geometryMember&gt;
84
 * &lt;geometryMember&gt;
85
 * &lt;LineString gid="L21216"&gt;
86
 * &lt;coord&gt;&lt;X&gt;0.0&lt;/X&gt;&lt;Y&gt;0.0&lt;/Y&gt;&lt;/coord&gt;
87
 * &lt;coord&gt;&lt;X&gt;0.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
88
 * &lt;coord&gt;&lt;X&gt;100.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
89
 * &lt;/LineString&gt;
90
 * &lt;/geometryMember&gt;
91
 * &lt;geometryMember&gt;
92
 * &lt;Polygon gid="_877789"&gt;
93
 * &lt;outerBoundaryIs&gt;
94
 * &lt;LinearRing&gt;
95
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
96
 * &lt;/LinearRing&gt;
97
 * &lt;/outerBoundaryIs&gt;
98
 * &lt;/Polygon&gt;
99
 * &lt;/geometryMember&gt;
100
 * &lt;/MultiGeometry&gt;
101
 * </code>
102
 * </pre>
103
 * </p> 
104
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
105
 */
106
public class MultiGeometryTypeBinding extends GeometryBinding{
107
        
108
        /**
109
         * It parses the gml:MultiGeometry tag
110
         * @param parser
111
         * The XML parser
112
         * @param handler
113
         * The GPE parser that contains the content handler and
114
         * the error handler
115
         * @return
116
         * A multigeometry
117
         * @throws XmlPullParserException
118
         * @throws IOException
119
         */
120
        public Object parse(XmlPullParser parser,GPEDefaultGmlParser handler) throws XmlPullParserException, IOException {
121
                boolean endFeature = false;
122
                int currentTag;
123
                Object multiGeometry = null;                
124
                
125
                super.setAtributtes(parser, handler.getErrorHandler());
126
                
127
                multiGeometry = handler.getContentHandler().startMultiGeometry(id, srsName);
128
                
129
                String tag = parser.getName();
130
                currentTag = parser.getEventType();
131

    
132
                while (!endFeature){
133
                        switch(currentTag){
134
                        case KXmlParser.START_TAG:
135
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_GEOMETRYMEMBER)){
136
                                                Object geometry = handler.getProfile().getGeometryMemberTypeBinding().
137
                                                parse(parser, handler);
138
                                                handler.getContentHandler().addGeometryToMultiGeometry(geometry, multiGeometry);
139
                                        }
140
                                        break;
141
                                case KXmlParser.END_TAG:
142
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTIGEOMETRY)){                                                
143
                                                endFeature = true;        
144
                                                handler.getContentHandler().endMultiGeometry(multiGeometry);
145
                                        }
146
                                        break;
147
                                case KXmlParser.TEXT:                                        
148
                                        
149
                                        break;
150
                                }
151
                                if (!endFeature){                                        
152
                                        currentTag = parser.next();
153
                                        tag = parser.getName();
154
                                }
155
                        }                        
156
                return multiGeometry;        
157
        }
158
}