root / branches / v1_9_0 / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / PolygonMemberTypeBinding.java @ 53
History | View | Annotate | Download (4.5 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:PolygonMemberTypeBinding.java 195 2007-11-26 09:02:22Z jpiera $
|
57 |
* $Log$
|
58 |
* Revision 1.2 2007/05/14 09:31:05 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:polygonMemberType object. Example:
|
68 |
* <p>
|
69 |
* <pre>
|
70 |
* <code>
|
71 |
* <polygonMember>
|
72 |
* <Polygon gid="_877789">
|
73 |
* <outerBoundaryIs>
|
74 |
* <LinearRing>
|
75 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
76 |
* </LinearRing>
|
77 |
* </outerBoundaryIs>
|
78 |
* </Polygon>
|
79 |
* </polygonMember>
|
80 |
* </code>
|
81 |
* </pre>
|
82 |
* </p>
|
83 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
84 |
*/
|
85 |
public class PolygonMemberTypeBinding { |
86 |
|
87 |
/**
|
88 |
* It parses the gml:PolygonMember tag
|
89 |
* @param parser
|
90 |
* The XML parser
|
91 |
* @param handler
|
92 |
* The GPE parser that contains the content handler and
|
93 |
* the error handler
|
94 |
* @return
|
95 |
* A polygon
|
96 |
* @throws XmlStreamException
|
97 |
* @throws IOException
|
98 |
*/
|
99 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
100 |
|
101 |
parser.require(EventType.START_ELEMENT, GMLTags.GML_NAMESPACE_URI, null);
|
102 |
|
103 |
QName tag = parser.getElementName();
|
104 |
|
105 |
if (!(GMLTags.GML_POLYGONMEMBER.getLocalPart().equals(tag.getLocalPart()) || GMLTags.GML_SURFACEMEMBER
|
106 |
.getLocalPart().equals(tag.getLocalPart()))) { |
107 |
throw new IllegalStateException( |
108 |
"Expected gml:PolygonMember or gml:SurfaceMember, but got " + tag);
|
109 |
} |
110 |
|
111 |
boolean endFeature = false; |
112 |
EventType currentTag; |
113 |
Object polygon = null; |
114 |
|
115 |
currentTag = parser.getEventType(); |
116 |
|
117 |
while (!endFeature){
|
118 |
switch(currentTag.getCode()){
|
119 |
case EventType.START_ELEMENT_CODE:
|
120 |
polygon = parseTag(parser, handler, tag); |
121 |
break;
|
122 |
case EventType.END_ELEMENT_CODE:
|
123 |
endFeature = parseLastTag(parser, handler, tag); |
124 |
break;
|
125 |
} |
126 |
if (!endFeature){
|
127 |
currentTag = parser.nextTag(); |
128 |
tag = parser.getElementName(); |
129 |
} |
130 |
} |
131 |
return polygon;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* It parses the XML tag
|
136 |
* @param parser
|
137 |
* @param handler
|
138 |
* @param tag
|
139 |
* @param id
|
140 |
* @param srsName
|
141 |
* @return
|
142 |
* @throws XmlStreamException
|
143 |
* @throws IOException
|
144 |
*/
|
145 |
protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag) throws XmlStreamException, IOException{ |
146 |
Object polygon = null; |
147 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_POLYGON)){
|
148 |
polygon = handler.getProfile().getPolygonTypeBinding().parse(parser, handler); |
149 |
} |
150 |
return polygon;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Parses the last tag
|
155 |
* @param parser
|
156 |
* @param handler
|
157 |
* @param tag
|
158 |
* @return
|
159 |
*/
|
160 |
protected boolean parseLastTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag){ |
161 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_POLYGONMEMBER)){
|
162 |
return true; |
163 |
} |
164 |
return false; |
165 |
} |
166 |
} |