Statistics
| Revision:

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

History | View | Annotate | Download (3.86 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: PointTypeBinding.java 11622 2007-05-14 11:23:12Z jorpiell $
57
 * $Log$
58
 * Revision 1.4  2007-05-14 11:18:51  jorpiell
59
 * ProjectionFactory updated
60
 *
61
 * Revision 1.3  2007/05/14 09:31:05  jorpiell
62
 * Add the a new class to compare tags
63
 *
64
 * Revision 1.2  2007/05/08 10:24:16  jorpiell
65
 * Add comments to create javadocs
66
 *
67
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
68
 * Add some methods to manage the multigeometries
69
 *
70
 * Revision 1.1  2007/05/07 07:06:46  jorpiell
71
 * Add a constructor with the name and the description fields
72
 *
73
 *
74
 */
75
/**
76
 * It parses a gml:PointType object. Example:
77
 * <p>
78
 * <pre>
79
 * <code>
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
 * </code>
84
 * </pre>
85
 * </p> 
86
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
87
 */
88
public class PointTypeBinding {
89
        
90
        /**
91
         * It parses the gml:Point tag
92
         * @param parser
93
         * The XML parser
94
         * @param handler
95
         * The GPE parser that contains the content handler and
96
         * the error handler
97
         * @return
98
         * A point
99
         * @throws XmlPullParserException
100
         * @throws IOException
101
         */
102
        public static Object parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException {
103
                boolean endFeature = false;
104
                int currentTag;
105
                Object point = null;                
106
                
107
                Hashtable attributes = GMLUtilsParser.getAttributes(parser);                
108
                String srsName = GeometryBinding.getSrs(attributes,handler.getErrorHandler());
109
                String id = GeometryBinding.getID(attributes);
110
                
111
                String tag = parser.getName();
112
                currentTag = parser.getEventType();
113

    
114
                while (!endFeature){
115
                        switch(currentTag){
116
                        case KXmlParser.START_TAG:
117
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_COORDINATES)){
118
                                                double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler);
119
                                                point = handler.getContentHandler().startPoint(id,
120
                                                                        coordinates[0][0],
121
                                                                        coordinates[1][0],
122
                                                                        coordinates[2][0],
123
                                                                        srsName);
124
                                        }
125
                                        break;
126
                                case KXmlParser.END_TAG:
127
                                        if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_POINT)){                                                
128
                                                endFeature = true;
129
                                                handler.getContentHandler().endPoint(point);
130
                                        }
131
                                        break;
132
                                case KXmlParser.TEXT:                                        
133
                                        
134
                                        break;
135
                                }
136
                                if (!endFeature){                                        
137
                                        currentTag = parser.next();
138
                                        tag = parser.getName();
139
                                }
140
                        }                        
141
                return point;        
142
        }
143
}