Statistics
| Revision:

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

History | View | Annotate | Download (4.18 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.utils.GMLTags;
9
import org.gvsig.gpe.xml.stream.EventType;
10
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
11
import org.gvsig.gpe.xml.stream.XmlStreamException;
12
import org.gvsig.gpe.xml.utils.CompareUtils;
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:BoundedByTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
57
 * $Log$
58
 * Revision 1.1  2007/05/14 09:31:06  jorpiell
59
 * Add the a new class to compare tags
60
 *
61
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
62
 * Add some methods to manage the multigeometries
63
 *
64
 *
65
 */
66
/**
67
 * It parses a gml:BoundingShapeType object. Example:
68
 * <p>
69
 * <pre>
70
 * <code>
71
 * &lt;gml:boundedBy&gt;
72
 * &lt;gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"&gt;
73
 * &lt;gml:coord&gt;&lt;gml:X&gt;0&lt;/gml:X&gt;&lt;gml:Y&gt;0&lt;/gml:Y&gt;&lt;/gml:coord&gt;
74
 * &lt;gml:coord&gt;&lt;gml:X&gt;50&lt;/gml:X&gt;&lt;gml:Y&gt;50&lt;/gml:Y&gt;&lt;/gml:coord&gt;
75
 * &lt;/gml:Box&gt;
76
 * &lt;/gml:boundedBy&gt;
77
 * </code>
78
 * </pre>
79
 * </p> 
80
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
81
 */
82
public class BoundedByTypeBinding {
83
        
84
        /**
85
         * It parses the gml:shapeType tag
86
         * @param parser
87
         * The XML parser
88
         * @param handler
89
         * The GPE parser that contains the content handler and
90
         * the error handler
91
         * @return
92
         * The Bounding box
93
         * @throws XmlStreamException
94
         * @throws IOException
95
         */
96
        public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException {
97

    
98
        parser.require(EventType.START_ELEMENT, GMLTags.GML_BOUNDEDBY);
99
        
100
                boolean endFeature = false;
101
                EventType currentTag;
102
                Object bbox = null;                
103

    
104
                parser.nextTag();
105

    
106
                QName tag = parser.getElementName();
107
                currentTag = parser.getEventType();
108

    
109
        while (!endFeature) {
110
            switch (currentTag.getCode()) {
111
            case EventType.START_ELEMENT_CODE:
112
                bbox = parseTag(parser, handler, tag);
113
                parser.require(EventType.END_ELEMENT, tag);
114
                break;
115
            case EventType.END_ELEMENT_CODE:
116
                if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_BOUNDEDBY)) {
117
                    endFeature = true;
118
                }
119
                break;
120
            }
121
            if (!endFeature) {
122
                currentTag = parser.nextTag();
123
                tag = parser.getElementName();
124
            }
125
        }
126
        parser.require(EventType.END_ELEMENT, GMLTags.GML_BOUNDEDBY);
127
                return bbox;        
128
        }
129
        
130
        /**
131
         * Parses the tag
132
         * @param parser
133
         * @param handler
134
         * @param tag
135
         * @return
136
         * @throws XmlStreamException
137
         * @throws IOException
138
         */
139
        protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag) throws XmlStreamException, IOException{
140
                Object bbox = null;
141
                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_BOX)){
142
                        bbox = handler.getProfile().getBoxTypeBinding().parse(parser, handler);
143
                }
144
                return bbox;
145
        }
146
}