Statistics
| Revision:

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

History | View | Annotate | Download (4.47 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:BoxTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
59
 * $Log$
60
 * Revision 1.5  2007/05/24 07:29:47  csanchez
61
 * A?adidos Alias GML2
62
 *
63
 * Revision 1.4  2007/05/14 11:18:51  jorpiell
64
 * ProjectionFactory updated
65
 *
66
 * Revision 1.3  2007/05/14 09:31:06  jorpiell
67
 * Add the a new class to compare tags
68
 *
69
 * Revision 1.2  2007/05/08 10:24:16  jorpiell
70
 * Add comments to create javadocs
71
 *
72
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
73
 * Add some methods to manage the multigeometries
74
 *
75
 *
76
 */
77
/**
78
 * It parses a gml:BoxType object. Example:
79
 * <p>
80
 * <pre>
81
 * <code>
82
 * &lt;gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"&gt;
83
 * &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;
84
 * &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;
85
 * &lt;/gml:Box&gt;
86
 * </code>
87
 * </pre>
88
 * </p> 
89
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
90
 */
91
public class BoxTypeBinding extends GeometryBinding{
92

    
93
        /**
94
         * It parses the gml:Box tag
95
         * @param parser
96
         * The XML parser
97
         * @param handler
98
         * The GPE parser that contains the content handler and
99
         * the error handler
100
         * @return
101
         * The Bounding box
102
         * @throws XmlStreamException
103
         * @throws IOException
104
         */
105
        public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException {
106

    
107
        parser.require(EventType.START_ELEMENT, GMLTags.GML_BOX);
108
        
109
                boolean endFeature = false;
110
                EventType currentTag;
111
                Object bbox = null;                
112

    
113
                super.setAtributtes(parser, handler.getErrorHandler());
114

    
115
                QName tag = parser.getElementName();
116
                currentTag = parser.getEventType();
117

    
118
                while (!endFeature){
119
                        switch(currentTag.getCode()){
120
                        case EventType.START_ELEMENT_CODE:
121
                                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORDINATES)){
122
                                        CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding();
123
                                        coordinatesIterator.initialize(parser, handler,GMLTags.GML_BOX);
124
                                        bbox = handler.getContentHandler().startBbox(id,
125
                                                        coordinatesIterator,
126
                                                        srsName);
127
                                }else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORD)){
128
                                        CoordTypeIterator coordinatesIterator = handler.getProfile().getCoordTypeBinding();
129
                                        coordinatesIterator.initialize(parser, handler,GMLTags.GML_BOX);
130
                                        bbox = handler.getContentHandler().startBbox(id,
131
                                                        coordinatesIterator,                                                                
132
                                                        srsName);
133
                                }
134
                                break;
135
                        case EventType.END_ELEMENT_CODE:
136
                                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_BOX)){                                                
137
                                        endFeature = true;
138
                                        handler.getContentHandler().endBbox(bbox);
139
                                }
140
                                break;
141
                        }                
142
                        if (!endFeature){                                        
143
                                currentTag = parser.nextTag();
144
                                tag = parser.getElementName();
145
                        }
146
                }                        
147
                return bbox;        
148
        }
149
}