Statistics
| Revision:

root / branches / v1_9_0 / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / LineStringTypeBinding.java @ 53

History | View | Annotate | Download (5.42 KB)

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

    
3
import java.io.IOException;
4

    
5
import javax.xml.namespace.QName;
6

    
7
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser;
8
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordTypeIterator;
9
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordinatesTypeIterator;
10
import org.gvsig.gpe.gml.utils.GMLTags;
11
import org.gvsig.gpe.xml.stream.EventType;
12
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
13
import org.gvsig.gpe.xml.stream.XmlStreamException;
14
import org.gvsig.gpe.xml.utils.CompareUtils;
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:LineStringTypeBinding.java 195 2007-11-26 09:02:22Z jpiera $
59
 * $Log$
60
 * Revision 1.6  2007/05/18 10:41:01  csanchez
61
 * Actualizaci?n libGPE-GML eliminaci?n de clases inecesarias
62
 *
63
 * Revision 1.5  2007/05/14 11:18:51  jorpiell
64
 * ProjectionFactory updated
65
 *
66
 * Revision 1.4  2007/05/14 09:31:06  jorpiell
67
 * Add the a new class to compare tags
68
 *
69
 * Revision 1.3  2007/05/08 10:24:16  jorpiell
70
 * Add comments to create javadocs
71
 *
72
 * Revision 1.2  2007/05/07 12:58:42  jorpiell
73
 * Add some methods to manage the multigeometries
74
 *
75
 * Revision 1.1  2007/05/07 07:06:46  jorpiell
76
 * Add a constructor with the name and the description fields
77
 *
78
 *
79
 */
80
/**
81
 *  A LineString is a special curve that consists of a
82
 *  single segment with linear interpolation. It is defined
83
 *  by two or more coordinate tuples, with linear interpolation
84
 *  between them.
85
 *  It parses a gml:LineStringType object. Example:
86
 * <p>
87
 * <pre>
88
 * <code>
89
 * &lt;LineString&gt;
90
 * &lt;coord&gt;&lt;X&gt;56.1&lt;/X&gt;&lt;Y&gt;0.45&lt;/Y&gt;&lt;/coord&gt;
91
 * &lt;coord&gt;&lt;X&gt;67.23&lt;/X&gt;&lt;Y&gt;0.98&lt;/Y&gt;&lt;/coord&gt;
92
 * &lt;/LineString&gt;
93
 * </code>
94
 * </pre>
95
 * </p> 
96
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
97
 */
98
public class LineStringTypeBinding extends GeometryBinding{
99
        
100
        /**
101
         * It parses the gml:LineQName tag
102
         * @param parser
103
         * The XML parser
104
         * @param handler
105
         * The GPE parser that contains the content handler and
106
         * the error handler
107
         * @return
108
         * A line
109
         * @throws XmlStreamException
110
         * @throws IOException
111
         */
112
        public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException {
113
            
114
            parser.require(EventType.START_ELEMENT, GMLTags.GML_LINESTRING);
115
            
116
                boolean endFeature = false;
117
                EventType currentTag;
118
                Object lineString = null;
119
                        
120
                super.setAtributtes(parser, handler.getErrorHandler());
121

    
122
                QName tag = parser.getElementName();
123
                currentTag = parser.getEventType();
124

    
125
                while (!endFeature){
126
                        switch(currentTag.getCode()){
127
                        case EventType.START_ELEMENT_CODE:
128
                            currentTag = parser.nextTag();
129
                            tag = parser.getElementName();
130
                                lineString = parseTag(parser, handler, tag, id, srsName);
131
                                 return lineString;
132
                        case EventType.END_ELEMENT_CODE:
133
                                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_LINESTRING)){        
134
                                        endFeature = true;
135
                                        handler.getContentHandler().endLineString(lineString);
136
                                }
137
                                break;
138
                        }
139
                        /*GR: no obligo a terminar de parsear todo, para que... si tenemos random access :)
140
                        if (!endFeature){                                        
141
                                currentTag = parser.nextTag();
142
                                tag = parser.getElementName();
143
                        }
144
                        */
145
                }                
146

    
147
                return lineString;        
148
        }
149
        
150
        /**
151
         * It parses next tag
152
         * @param parser
153
         * @param handler
154
         * @param tag
155
         * @param id
156
         * @param srsName
157
         * @return
158
         * @throws XmlStreamException
159
         * @throws IOException
160
         */
161
        protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag, String id, String srsName) throws XmlStreamException, IOException{
162
                Object lineString = null;
163
                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORDINATES)){
164
                        CoordinatesTypeIterator coordinatesIteartor = handler.getProfile().getCoordinatesTypeBinding();
165
                        coordinatesIteartor.initialize(parser, handler,GMLTags.GML_LINESTRING);
166
                        lineString = handler.getContentHandler().startLineString(id,
167
                                        coordinatesIteartor,                                                                
168
                                        srsName);                                                
169
                }else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORD)){
170
                        CoordTypeIterator coordinatesIteartor = handler.getProfile().getCoordTypeBinding();
171
                        coordinatesIteartor.initialize(parser, handler,GMLTags.GML_LINESTRING);
172
                        lineString = handler.getContentHandler().startLineString(id,
173
                                        coordinatesIteartor,                                                                
174
                                        srsName);                        
175
                }
176
                return lineString;
177
        }
178
}