root / branches / v1_9_0 / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / PolygonTypeBinding.java @ 53
History | View | Annotate | Download (5.36 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.parser.ICoordinateIterator; |
10 |
import org.gvsig.gpe.xml.stream.EventType; |
11 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
12 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
13 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id:PolygonTypeBinding.java 195 2007-11-26 09:02:22Z jpiera $
|
58 |
* $Log$
|
59 |
* Revision 1.4 2007/05/14 11:18:51 jorpiell
|
60 |
* ProjectionFactory updated
|
61 |
*
|
62 |
* Revision 1.3 2007/05/14 09:31:06 jorpiell
|
63 |
* Add the a new class to compare tags
|
64 |
*
|
65 |
* Revision 1.2 2007/05/08 10:24:16 jorpiell
|
66 |
* Add comments to create javadocs
|
67 |
*
|
68 |
* Revision 1.1 2007/05/07 12:58:42 jorpiell
|
69 |
* Add some methods to manage the multigeometries
|
70 |
*
|
71 |
* Revision 1.1 2007/05/07 07:06:46 jorpiell
|
72 |
* Add a constructor with the name and the description fields
|
73 |
*
|
74 |
*
|
75 |
*/
|
76 |
/**
|
77 |
* It parses a gml:PolygonType object. Example:
|
78 |
* <p>
|
79 |
* <pre>
|
80 |
* <code>
|
81 |
* <Polygon gid="_877789">
|
82 |
* <outerBoundaryIs>
|
83 |
* <LinearRing>
|
84 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
85 |
* </LinearRing>
|
86 |
* </outerBoundaryIs>
|
87 |
* </Polygon>
|
88 |
* </code>
|
89 |
* </pre>
|
90 |
* </p>
|
91 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
92 |
*/
|
93 |
public class PolygonTypeBinding extends GeometryBinding{ |
94 |
protected Object polygon = null; |
95 |
|
96 |
/**
|
97 |
* It parses the gml:Polygon tag
|
98 |
* @param parser
|
99 |
* The XML parser
|
100 |
* @param handler
|
101 |
* The GPE parser that contains the content handler and
|
102 |
* the error handler
|
103 |
* @return
|
104 |
* A polygon
|
105 |
* @throws XmlStreamException
|
106 |
* @throws IOException
|
107 |
*/
|
108 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
109 |
|
110 |
parser.require(EventType.START_ELEMENT, null, null); |
111 |
|
112 |
boolean endFeature = false; |
113 |
EventType currentTag; |
114 |
|
115 |
super.setAtributtes(parser, handler.getErrorHandler());
|
116 |
|
117 |
QName tag = parser.getElementName();
|
118 |
currentTag = parser.getEventType(); |
119 |
|
120 |
while (!endFeature){
|
121 |
switch(currentTag.getCode()){
|
122 |
case EventType.START_ELEMENT_CODE:
|
123 |
polygon = parseTag(parser, handler, tag, id, srsName); |
124 |
break;
|
125 |
case EventType.END_ELEMENT_CODE:
|
126 |
endFeature = parseLastTag(parser, handler, tag); |
127 |
if (endFeature){
|
128 |
handler.getContentHandler().endPolygon(polygon); |
129 |
} |
130 |
break;
|
131 |
case EventType.VALUE_STRING_CODE:
|
132 |
|
133 |
break;
|
134 |
} |
135 |
if (!endFeature){
|
136 |
currentTag = parser.nextTag(); |
137 |
tag = parser.getElementName(); |
138 |
} |
139 |
} |
140 |
|
141 |
return polygon;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* It parses the XML tag
|
146 |
* @param parser
|
147 |
* @param handler
|
148 |
* @param tag
|
149 |
* @param id
|
150 |
* @param srsName
|
151 |
* @return
|
152 |
* @throws XmlStreamException
|
153 |
* @throws IOException
|
154 |
*/
|
155 |
protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag, String id, String srsName) throws XmlStreamException, IOException{ |
156 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_OUTERBOUNDARYIS)){
|
157 |
OuterBoundaryIsTypeBinding coordinatesBinding = handler.getProfile().getOuterBoundaryIsTypeBinding(); |
158 |
ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler); |
159 |
this.polygon = handler.getContentHandler().startPolygon(id,
|
160 |
coordinatesIterator, |
161 |
srsName); |
162 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_INNERBOUNDARYIS)){ |
163 |
InnerBoundaryIsTypeBinding coordinatesBinding = handler.getProfile().getInnerBoundaryIsTypeBinding(); |
164 |
ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler); |
165 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(null, |
166 |
coordinatesIterator, |
167 |
srsName); |
168 |
handler.getContentHandler().endInnerPolygon(innerPolygon); |
169 |
handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,this.polygon);
|
170 |
} |
171 |
return polygon;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Parses the last tag
|
176 |
* @param parser
|
177 |
* @param handler
|
178 |
* @param tag
|
179 |
* @return
|
180 |
*/
|
181 |
protected boolean parseLastTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag){ |
182 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_POLYGON)){
|
183 |
return true; |
184 |
} |
185 |
return false; |
186 |
} |
187 |
} |