root / branches / v1_9_0 / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / features / FeatureCollectionBinding.java @ 53
History | View | Annotate | Download (6.4 KB)
1 |
package org.gvsig.gpe.gml.parser.v2.features; |
---|---|
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.profiles.IBindingProfile; |
9 |
import org.gvsig.gpe.gml.utils.GMLObject; |
10 |
import org.gvsig.gpe.gml.utils.GMLTags; |
11 |
import org.gvsig.gpe.parser.IGPEContentHandler; |
12 |
import org.gvsig.gpe.xml.stream.EventType; |
13 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
14 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
15 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
16 |
import org.gvsig.gpe.xml.utils.XMLAttributesIterator; |
17 |
|
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib??ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: FeatureCollectionBinding.java 350 2008-01-09 12:53:07Z jpiera $
|
61 |
* $Log$
|
62 |
* Revision 1.2 2007/06/29 12:19:34 jorpiell
|
63 |
* The schema validation is made independently of the concrete writer
|
64 |
*
|
65 |
* Revision 1.1 2007/06/07 14:53:30 jorpiell
|
66 |
* Add the schema support
|
67 |
*
|
68 |
*
|
69 |
*/
|
70 |
/**
|
71 |
* This class parses the gml objects that has a gml:FeatureCollection type. Example:
|
72 |
* <p>
|
73 |
*
|
74 |
* <pre>
|
75 |
* <code>
|
76 |
* <gml:featureCollection>
|
77 |
* <gml:featureMember>
|
78 |
* </gml:featureMember>
|
79 |
* <gml:featureMember>
|
80 |
* </gml:featureMember>
|
81 |
* </gml:featureCollection>
|
82 |
* </code>
|
83 |
* </pre>
|
84 |
*
|
85 |
* </p>
|
86 |
*
|
87 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
88 |
*/
|
89 |
public class FeatureCollectionBinding { |
90 |
/**
|
91 |
* It parses a feature collection
|
92 |
*
|
93 |
* @param parser
|
94 |
* The XML parser
|
95 |
* @param handler
|
96 |
* The GPE parser that contains the content handler and the error handler
|
97 |
* @return A feature
|
98 |
* @throws XmlStreamException
|
99 |
* @throws IOException
|
100 |
*/
|
101 |
public Object parse(IXmlStreamReader parser, GPEDefaultGmlParser handler) |
102 |
throws XmlStreamException, IOException { |
103 |
|
104 |
if(!parser.getEventType().isTag()){
|
105 |
parser.nextTag(); |
106 |
} |
107 |
|
108 |
boolean endCollection = false; |
109 |
EventType currentTag; |
110 |
Object layer = null; |
111 |
|
112 |
final QName layerRootType = parser.getElementName(); |
113 |
|
114 |
XMLAttributesIterator attributesIterator = new XMLAttributesIterator(parser);
|
115 |
final IBindingProfile profile = handler.getProfile();
|
116 |
String fid = profile.getFeatureTypeBinding().getID(
|
117 |
attributesIterator.getAttributes()); |
118 |
|
119 |
final IGPEContentHandler contentHandler = handler.getContentHandler();
|
120 |
layer = contentHandler.startLayer(fid, layerRootType.getNamespaceURI(), |
121 |
null, null, null, attributesIterator, null, null); |
122 |
|
123 |
QName tag = parser.getElementName();
|
124 |
currentTag = parser.getEventType(); |
125 |
|
126 |
while (!endCollection) {
|
127 |
switch (currentTag.getCode()) {
|
128 |
case EventType.START_ELEMENT_CODE:
|
129 |
if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_NAME)) {
|
130 |
parser.next(); |
131 |
contentHandler.addNameToLayer(parser.getText(), layer); |
132 |
} else if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_DESCRIPTION)) { |
133 |
parser.next(); |
134 |
contentHandler.addDescriptionToLayer(parser.getText(), layer); |
135 |
} else if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_BOUNDEDBY)) { |
136 |
Object bbox = profile.getBoundedByTypeBinding().parse(parser,
|
137 |
handler); |
138 |
contentHandler.addBboxToLayer(bbox, layer); |
139 |
} else if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_FEATUREMEMBER)) { |
140 |
GMLObject object = (GMLObject) profile |
141 |
.getFeatureMemberTypeBinding().parse(parser, handler); |
142 |
|
143 |
if (object != null) { |
144 |
if (GMLObject.FEATURE == object.getType()) {
|
145 |
contentHandler |
146 |
.addFeatureToLayer(object.getObject(), layer); |
147 |
} else {
|
148 |
contentHandler.addParentLayerToLayer(layer, |
149 |
object.getObject()); |
150 |
} |
151 |
} |
152 |
} else if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_FEATUREMEMBERS)) { |
153 |
profile.getFeatureMembersTypeBinding().parse(parser, handler, |
154 |
layer); |
155 |
} else {
|
156 |
if (!(CompareUtils.compareWithNamespace(layerRootType, tag))) {
|
157 |
// Feature members
|
158 |
GMLObject object = (GMLObject) profile.getFeatureTypeBinding() |
159 |
.parse(parser, handler); |
160 |
contentHandler.addFeatureToLayer(object.getObject(), layer); |
161 |
} |
162 |
} |
163 |
break;
|
164 |
case EventType.END_ELEMENT_CODE:
|
165 |
if (CompareUtils.compareWithNamespace(tag, layerRootType)) {
|
166 |
endCollection = true;
|
167 |
contentHandler.endLayer(layer); |
168 |
} |
169 |
break;
|
170 |
case EventType.END_DOCUMENT_CODE:
|
171 |
endCollection = true;
|
172 |
break;
|
173 |
} |
174 |
if (!endCollection) {
|
175 |
currentTag = parser.nextTag(); |
176 |
tag = parser.getElementName(); |
177 |
} |
178 |
} |
179 |
return layer;
|
180 |
} |
181 |
} |