Statistics
| Revision:

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

History | View | Annotate | Download (5.59 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.profiles.IBindingProfile;
9
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordTypeIterator;
10
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordinatesTypeIterator;
11
import org.gvsig.gpe.gml.utils.GMLTags;
12
import org.gvsig.gpe.parser.IGPEContentHandler;
13
import org.gvsig.gpe.xml.stream.EventType;
14
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
15
import org.gvsig.gpe.xml.stream.XmlStreamException;
16
import org.gvsig.gpe.xml.utils.CompareUtils;
17

    
18
import com.sun.corba.se.impl.orb.ParserTable;
19

    
20
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
21
 *
22
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
23
 *
24
 * This program is free software; you can redistribute it and/or
25
 * modify it under the terms of the GNU General Public License
26
 * as published by the Free Software Foundation; either version 2
27
 * of the License, or (at your option) any later version.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 * GNU General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU General Public License
35
 * along with this program; if not, write to the Free Software
36
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
37
 *
38
 * For more information, contact:
39
 *
40
 *  Generalitat Valenciana
41
 *   Conselleria d'Infraestructures i Transport
42
 *   Av. Blasco Ib??ez, 50
43
 *   46010 VALENCIA
44
 *   SPAIN
45
 *
46
 *      +34 963862235
47
 *   gvsig@gva.es
48
 *      www.gvsig.gva.es
49
 *
50
 *    or
51
 *
52
 *   IVER T.I. S.A
53
 *   Salamanca 50
54
 *   46005 Valencia
55
 *   Spain
56
 *
57
 *   +34 963163400
58
 *   dac@iver.es
59
 */
60
/* CVS MESSAGES:
61
 *
62
 * $Id:PointTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
63
 * $Log$
64
 * Revision 1.6  2007/05/24 07:29:47  csanchez
65
 * A?adidos Alias GML2
66
 *
67
 * Revision 1.5  2007/05/15 07:30:38  jorpiell
68
 * Add the geometryProperties tags
69
 *
70
 * Revision 1.4  2007/05/14 11:18:51  jorpiell
71
 * ProjectionFactory updated
72
 *
73
 * Revision 1.3  2007/05/14 09:31:05  jorpiell
74
 * Add the a new class to compare tags
75
 *
76
 * Revision 1.2  2007/05/08 10:24:16  jorpiell
77
 * Add comments to create javadocs
78
 *
79
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
80
 * Add some methods to manage the multigeometries
81
 *
82
 * Revision 1.1  2007/05/07 07:06:46  jorpiell
83
 * Add a constructor with the name and the description fields
84
 *
85
 *
86
 */
87
/**
88
 * It parses a gml:PointType object. Example:
89
 * <p>
90
 * <pre>
91
 * <code>
92
 * &lt;Point gid="P6776"&gt;
93
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
94
 * &lt;/Point&gt;
95
 * </code>
96
 * </pre>
97
 * </p> 
98
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
99
 */
100
public class PointTypeBinding extends GeometryBinding{
101

    
102
        /**
103
         * It parses the gml:Point tag
104
         * @param parser
105
         * The XML parser
106
         * @param handler
107
         * The GPE parser that contains the content handler and
108
         * the error handler
109
         * @return
110
         * A point
111
         * @throws XmlStreamException
112
         * @throws IOException
113
         */
114
        public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException {
115
            
116
            parser.require(EventType.START_ELEMENT, GMLTags.GML_POINT);
117
            
118
                super.setAtributtes(parser, handler.getErrorHandler());
119

    
120
                parser.nextTag();
121

    
122
                Object point = parseTag(parser, handler, id, srsName);
123
                
124
                parser.require(EventType.END_ELEMENT, null, null);
125
                if(!GMLTags.GML_POINT.equals(parser.getElementName())){
126
                    parser.nextTag();
127
                    parser.require(EventType.END_ELEMENT, GMLTags.GML_POINT);
128
                }
129
                
130
                return point;        
131
        }
132

    
133
        /**
134
         * It parses a tag
135
         * @param parser
136
         * @param handler
137
         * @param tag
138
         * @param id
139
         * @param srsName
140
         * @return
141
         * @throws XmlStreamException
142
         * @throws IOException
143
         */
144
        protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, String id, String srsName) throws XmlStreamException, IOException{
145
            parser.require(EventType.START_ELEMENT, null, null);
146
            final QName coordinatesTag = parser.getElementName();
147
                Object point = null;
148

    
149
                final IBindingProfile profile = handler.getProfile();
150
        final IGPEContentHandler contentHandler = handler.getContentHandler();
151
        if (CompareUtils.compareWithNamespace(coordinatesTag, GMLTags.GML_COORDINATES)) {
152
            
153
            CoordinatesTypeIterator coordinatesIterator = profile.getCoordinatesTypeBinding();
154
            coordinatesIterator.initialize(parser, handler, GMLTags.GML_POINT);
155
            point = contentHandler.startPoint(id, coordinatesIterator, srsName);
156
            
157
            parser.require(EventType.END_ELEMENT, GMLTags.GML_COORDINATES);
158
            
159
        } else if (CompareUtils.compareWithNamespace(coordinatesTag, GMLTags.GML_COORD)) {
160
            CoordTypeIterator coordinatesIterator = profile.getCoordTypeBinding();
161
            coordinatesIterator.initialize(parser, handler, GMLTags.GML_POINT);
162
            
163
            parser.require(EventType.START_ELEMENT, GMLTags.GML_COORD);
164

    
165
            point = contentHandler.startPoint(id, coordinatesIterator, srsName);
166
            
167
            QName elementName = parser.getElementName();
168
            EventType eventType = parser.getEventType();
169
            
170
            parser.require(EventType.END_ELEMENT, GMLTags.GML_COORD);
171
        }else{
172
            throw new IllegalArgumentException("Unknown coordinates tag, expected one of gml:coordinates, gml:coords");
173
        }
174
        
175
        parser.require(EventType.END_ELEMENT, coordinatesTag);
176

    
177
                return point;
178
        }
179
}