root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / FeatureCollectionBinding.java @ 12418
History | View | Annotate | Download (4.56 KB)
1 | 12071 | jorpiell | package org.gvsig.gpe.gml.bindings; |
---|---|---|---|
2 | |||
3 | import java.io.IOException; |
||
4 | import java.util.Hashtable; |
||
5 | |||
6 | import org.gvsig.gpe.gml.GMLTags; |
||
7 | import org.gvsig.gpe.gml.GPEGmlParser; |
||
8 | import org.gvsig.gpe.gml.bindings.geometries.BoundedByTypeBinding; |
||
9 | import org.gvsig.gpe.gml.utils.CompareUtils; |
||
10 | import org.gvsig.gpe.gml.utils.GMLUtilsParser; |
||
11 | import org.xmlpull.v1.XmlPullParser; |
||
12 | import org.xmlpull.v1.XmlPullParserException; |
||
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$
|
||
57 | * $Log$
|
||
58 | 12418 | jorpiell | * Revision 1.2 2007-06-29 12:19:34 jorpiell
|
59 | * The schema validation is made independently of the concrete writer
|
||
60 | *
|
||
61 | * Revision 1.1 2007/06/07 14:53:30 jorpiell
|
||
62 | 12071 | jorpiell | * Add the schema support
|
63 | *
|
||
64 | *
|
||
65 | */
|
||
66 | /**
|
||
67 | * This class parses the gml objects that has a
|
||
68 | * gml:FeatureCollection type. Example:
|
||
69 | * <p>
|
||
70 | * <pre>
|
||
71 | * <code>
|
||
72 | * <gml:featureCollection>
|
||
73 | * <gml:featureMember>
|
||
74 | * </gml:featureMember>
|
||
75 | * <gml:featureMember>
|
||
76 | * </gml:featureMember>
|
||
77 | * </gml:featureCollection>
|
||
78 | * </code>
|
||
79 | * </pre>
|
||
80 | * </p>
|
||
81 | * @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
||
82 | */
|
||
83 | public class FeatureCollectionBinding { |
||
84 | /**
|
||
85 | * It parses a feature collection
|
||
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 | * A feature
|
||
93 | * @throws XmlPullParserException
|
||
94 | * @throws IOException
|
||
95 | */
|
||
96 | public static Object parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException { |
||
97 | boolean endCollection = false; |
||
98 | int currentTag;
|
||
99 | Object layer = null; |
||
100 | //Used to finish to parse the current feature collection
|
||
101 | String layerRootType = parser.getName();
|
||
102 | |||
103 | Hashtable attributes = GMLUtilsParser.getAttributes(parser);
|
||
104 | String fid = FeatureTypeBinding.getID(attributes);
|
||
105 | |||
106 | layer = handler.getContentHandler().startLayer(fid, null, null, null, null, null, null); |
||
107 | |||
108 | String tag = parser.getName();
|
||
109 | currentTag = parser.getEventType(); |
||
110 | |||
111 | while (!endCollection){
|
||
112 | switch(currentTag){
|
||
113 | case XmlPullParser.START_TAG:
|
||
114 | if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_NAME)){
|
||
115 | parser.next(); |
||
116 | handler.getContentHandler().addNameToLayer(parser.getText(), layer); |
||
117 | }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_DESCRIPTION)){ |
||
118 | parser.next(); |
||
119 | handler.getContentHandler().addDescriptionToLayer(parser.getText(), layer); |
||
120 | }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_BOUNDEDBY)){ |
||
121 | Object bbox = BoundedByTypeBinding.parse(parser, handler);
|
||
122 | handler.getContentHandler().addBboxToLayer(bbox, layer); |
||
123 | }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_FEATUREMEMBER)){ |
||
124 | Object feature = FeatureMemberTypeBinding.parse(parser, handler);
|
||
125 | handler.getContentHandler().addFeatureToLayer(feature, layer); |
||
126 | }else{
|
||
127 | if (!(layerRootType.compareTo(tag) == 0)){ |
||
128 | //Feature members
|
||
129 | Object feature = FeatureTypeBinding.parse(parser, handler);
|
||
130 | handler.getContentHandler().addFeatureToLayer(feature, layer); |
||
131 | } |
||
132 | } |
||
133 | break;
|
||
134 | case XmlPullParser.END_TAG:
|
||
135 | if (tag.compareTo(layerRootType) == 0){ |
||
136 | endCollection = true;
|
||
137 | handler.getContentHandler().endLayer(layer); |
||
138 | } |
||
139 | break;
|
||
140 | case XmlPullParser.TEXT:
|
||
141 | |||
142 | break;
|
||
143 | 12418 | jorpiell | case XmlPullParser.END_DOCUMENT:
|
144 | endCollection = true;
|
||
145 | break;
|
||
146 | 12071 | jorpiell | } |
147 | if (!endCollection){
|
||
148 | currentTag = parser.next(); |
||
149 | tag = parser.getName(); |
||
150 | } |
||
151 | } |
||
152 | return layer;
|
||
153 | } |
||
154 | } |