Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / geometries / MultiLineStrinsTypeBinding.java @ 11622

History | View | Annotate | Download (4.41 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.gml.GMLTags;
7
import org.gvsig.gpe.gml.GPEGmlParser;
8
import org.gvsig.gpe.gml.utils.CompareUtils;
9
import org.gvsig.gpe.gml.utils.GMLUtilsParser;
10
import org.kxml2.io.KXmlParser;
11
import org.xmlpull.v1.XmlPullParser;
12
import org.xmlpull.v1.XmlPullParserException;
13

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

    
127
                while (!endFeature){
128
                        switch(currentTag){
129
                        case KXmlParser.START_TAG:
130
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_LINESTRINGMEMBER)){
131
                                                Object lineString = LineStringMemberTypeBinding.parse(parser, handler);
132
                                                handler.getContentHandler().addLineStringToMultiLineString(lineString, multiLineString);
133
                                        }
134
                                        break;
135
                                case KXmlParser.END_TAG:
136
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_MULTILINESTRING)){                                                
137
                                                endFeature = true;        
138
                                                handler.getContentHandler().endMultiLineString(multiLineString);
139
                                        }
140
                                        break;
141
                                case KXmlParser.TEXT:                                        
142
                                        
143
                                        break;
144
                                }
145
                                if (!endFeature){                                        
146
                                        currentTag = parser.next();
147
                                        tag = parser.getName();
148
                                }
149
                        }                        
150
                return multiLineString;        
151
        }
152
}