root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / features / FeatureCollectionBinding.java @ 19712
History | View | Annotate | Download (5.23 KB)
1 |
package org.gvsig.gpe.gml.parser.v2.features; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.Hashtable; |
5 |
|
6 |
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser; |
7 |
import org.gvsig.gpe.gml.utils.GMLObject; |
8 |
import org.gvsig.gpe.gml.utils.GMLTags; |
9 |
import org.gvsig.gpe.gml.utils.GMLUtilsParser; |
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 |
import org.gvsig.gpe.xml.utils.XMLTags; |
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: FeatureCollectionBinding.java 350 2008-01-09 12:53:07Z jpiera $
|
58 |
* $Log$
|
59 |
* Revision 1.2 2007/06/29 12:19:34 jorpiell
|
60 |
* The schema validation is made independently of the concrete writer
|
61 |
*
|
62 |
* Revision 1.1 2007/06/07 14:53:30 jorpiell
|
63 |
* Add the schema support
|
64 |
*
|
65 |
*
|
66 |
*/
|
67 |
/**
|
68 |
* This class parses the gml objects that has a
|
69 |
* gml:FeatureCollection type. Example:
|
70 |
* <p>
|
71 |
* <pre>
|
72 |
* <code>
|
73 |
* <gml:featureCollection>
|
74 |
* <gml:featureMember>
|
75 |
* </gml:featureMember>
|
76 |
* <gml:featureMember>
|
77 |
* </gml:featureMember>
|
78 |
* </gml:featureCollection>
|
79 |
* </code>
|
80 |
* </pre>
|
81 |
* </p>
|
82 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
83 |
*/
|
84 |
public class FeatureCollectionBinding { |
85 |
/**
|
86 |
* It parses a feature collection
|
87 |
* @param parser
|
88 |
* The XML parser
|
89 |
* @param handler
|
90 |
* The GPE parser that contains the content handler and
|
91 |
* the error handler
|
92 |
* @return
|
93 |
* A feature
|
94 |
* @throws XmlStreamException
|
95 |
* @throws IOException
|
96 |
*/
|
97 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
98 |
boolean endCollection = false; |
99 |
int currentTag;
|
100 |
Object layer = null; |
101 |
//Used to finish to parse the current feature collection
|
102 |
String layerRootType = parser.getName();
|
103 |
while ((XMLTags.XML_ANNOTATION.equals(layerRootType))){
|
104 |
//Annotation value...
|
105 |
parser.next(); |
106 |
//Annotation close tag
|
107 |
parser.next(); |
108 |
//Next tag
|
109 |
parser.next(); |
110 |
layerRootType = parser.getName(); |
111 |
} |
112 |
|
113 |
Hashtable attributes = GMLUtilsParser.getAttributes(parser);
|
114 |
String fid = handler.getProfile().getFeatureTypeBinding().getID(attributes);
|
115 |
|
116 |
layer = handler.getContentHandler().startLayer(fid, null, null, null, null, null, null); |
117 |
|
118 |
String tag = parser.getName();
|
119 |
currentTag = parser.getEventType(); |
120 |
|
121 |
while (!endCollection){
|
122 |
switch(currentTag){
|
123 |
case IXmlStreamReader.START_ELEMENT:
|
124 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_NAME)){
|
125 |
parser.next(); |
126 |
handler.getContentHandler().addNameToLayer(parser.getText(), layer); |
127 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_DESCRIPTION)){ |
128 |
parser.next(); |
129 |
handler.getContentHandler().addDescriptionToLayer(parser.getText(), layer); |
130 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_BOUNDEDBY)){ |
131 |
Object bbox = handler.getProfile().getBoundedByTypeBinding().
|
132 |
parse(parser, handler); |
133 |
handler.getContentHandler().addBboxToLayer(bbox, layer); |
134 |
}else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_FEATUREMEMBER)){ |
135 |
GMLObject object = (GMLObject)handler.getProfile().getFeatureMemberTypeBinding(). |
136 |
parse(parser, handler); |
137 |
if (object.getType() == GMLObject.FEATURE){
|
138 |
handler.getContentHandler().addFeatureToLayer(object.getObject(), layer); |
139 |
}else{
|
140 |
handler.getContentHandler().addParentLayerToLayer(layer, object.getObject()); |
141 |
} |
142 |
}else{
|
143 |
if (!(layerRootType.compareTo(tag) == 0)){ |
144 |
//Feature members
|
145 |
GMLObject object =(GMLObject)handler.getProfile().getFeatureTypeBinding().parse(parser, handler); |
146 |
handler.getContentHandler().addFeatureToLayer(object.getObject(), layer); |
147 |
} |
148 |
} |
149 |
break;
|
150 |
case IXmlStreamReader.END_ELEMENT:
|
151 |
if (tag.compareTo(layerRootType) == 0){ |
152 |
endCollection = true;
|
153 |
handler.getContentHandler().endLayer(layer); |
154 |
} |
155 |
break;
|
156 |
case IXmlStreamReader.CHARACTERS:
|
157 |
|
158 |
break;
|
159 |
case IXmlStreamReader.END_DOCUMENT:
|
160 |
endCollection = true;
|
161 |
break;
|
162 |
} |
163 |
if (!endCollection){
|
164 |
currentTag = parser.next(); |
165 |
tag = parser.getName(); |
166 |
} |
167 |
} |
168 |
return layer;
|
169 |
} |
170 |
} |