root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / features / ElementTypeBinding.java @ 19366
History | View | Annotate | Download (5.9 KB)
1 |
package org.gvsig.gpe.gml.parser.v2.features; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser; |
6 |
import org.gvsig.gpe.gml.utils.GMLGeometries; |
7 |
import org.gvsig.gpe.gml.utils.GMLUtilsParser; |
8 |
import org.gvsig.xmlschema.som.IXSElementDeclaration; |
9 |
import org.gvsig.xmlschema.utils.TypeUtils; |
10 |
import org.xmlpull.v1.XmlPullParser; |
11 |
import org.xmlpull.v1.XmlPullParserException; |
12 |
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
14 |
*
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
16 |
*
|
17 |
* This program is free software; you can redistribute it and/or
|
18 |
* modify it under the terms of the GNU General Public License
|
19 |
* as published by the Free Software Foundation; either version 2
|
20 |
* of the License, or (at your option) any later version.
|
21 |
*
|
22 |
* This program is distributed in the hope that it will be useful,
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25 |
* GNU General Public License for more details.
|
26 |
*
|
27 |
* You should have received a copy of the GNU General Public License
|
28 |
* along with this program; if not, write to the Free Software
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
30 |
*
|
31 |
* For more information, contact:
|
32 |
*
|
33 |
* Generalitat Valenciana
|
34 |
* Conselleria d'Infraestructures i Transport
|
35 |
* Av. Blasco Ib??ez, 50
|
36 |
* 46010 VALENCIA
|
37 |
* SPAIN
|
38 |
*
|
39 |
* +34 963862235
|
40 |
* gvsig@gva.es
|
41 |
* www.gvsig.gva.es
|
42 |
*
|
43 |
* or
|
44 |
*
|
45 |
* IVER T.I. S.A
|
46 |
* Salamanca 50
|
47 |
* 46005 Valencia
|
48 |
* Spain
|
49 |
*
|
50 |
* +34 963163400
|
51 |
* dac@iver.es
|
52 |
*/
|
53 |
/* CVS MESSAGES:
|
54 |
*
|
55 |
* $Id: ElementTypeBinding.java 350 2008-01-09 12:53:07Z jpiera $
|
56 |
* $Log$
|
57 |
* Revision 1.8 2007/06/14 13:50:05 jorpiell
|
58 |
* The schema jar name has been changed
|
59 |
*
|
60 |
* Revision 1.7 2007/06/07 14:53:30 jorpiell
|
61 |
* Add the schema support
|
62 |
*
|
63 |
* Revision 1.6 2007/05/18 10:41:01 csanchez
|
64 |
* Actualizaci?n libGPE-GML eliminaci?n de clases inecesarias
|
65 |
*
|
66 |
* Revision 1.5 2007/05/16 13:00:48 csanchez
|
67 |
* Actualizaci?n de libGPE-GML
|
68 |
*
|
69 |
* Revision 1.4 2007/05/15 09:51:59 jorpiell
|
70 |
* The namespace is deleted from the element name
|
71 |
*
|
72 |
* Revision 1.3 2007/05/15 09:35:09 jorpiell
|
73 |
* the tag names cant have blanc spaces
|
74 |
*
|
75 |
* Revision 1.2 2007/05/15 08:04:16 jorpiell
|
76 |
* If the element type is a geometry, the element value wiil be the toString geometry method
|
77 |
*
|
78 |
* Revision 1.1 2007/05/14 09:30:30 jorpiell
|
79 |
* Add the FeatureMember tag
|
80 |
*
|
81 |
*
|
82 |
*/
|
83 |
/**
|
84 |
* This class is used to parse some xml tags that
|
85 |
* represents a xml element.
|
86 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
87 |
* @see http://www.w3.org/XML/Schema
|
88 |
*/
|
89 |
public class ElementTypeBinding { |
90 |
|
91 |
/**
|
92 |
* It parses a xml element
|
93 |
* @param parser
|
94 |
* The XML parser
|
95 |
* @param handler
|
96 |
* The GPE parser that contains the content handler and
|
97 |
* the error handler
|
98 |
* @param feature
|
99 |
* The feature is needed to add the geometry
|
100 |
* @param parentElement
|
101 |
* The parent element
|
102 |
* @return
|
103 |
* A Element
|
104 |
* @throws XmlPullParserException
|
105 |
* @throws IOException
|
106 |
*/
|
107 |
public Object parse(XmlPullParser parser,GPEDefaultGmlParser handler, Object feature, Object parentElement, IXSElementDeclaration parentType) throws XmlPullParserException, IOException { |
108 |
boolean endFeature = false; |
109 |
boolean isGeometryTag = false; |
110 |
int currentTag;
|
111 |
Object element = null; |
112 |
Object value = null; |
113 |
Object geometry = null; |
114 |
boolean isInitialized = false; |
115 |
//Used to finish to parse the current element
|
116 |
String elementRootType = parser.getName();
|
117 |
String type = null; |
118 |
|
119 |
//Find the element type
|
120 |
IXSElementDeclaration elementType = null;
|
121 |
if (parentType != null){ |
122 |
elementType = parentType.getSubElementByName(elementRootType); |
123 |
if (elementType == null){ |
124 |
type = TypeUtils.getXSType(String.class);
|
125 |
}else{
|
126 |
type = elementType.getTypeName(); |
127 |
} |
128 |
}else{
|
129 |
type = TypeUtils.getXSType(String.class);
|
130 |
} |
131 |
|
132 |
String tag = parser.getName();
|
133 |
currentTag = parser.getEventType(); |
134 |
|
135 |
while (!endFeature){
|
136 |
switch(currentTag){
|
137 |
case XmlPullParser.START_TAG:
|
138 |
if (!(tag.compareTo(elementRootType)==0)){ |
139 |
//If is a geometry
|
140 |
if (GMLGeometries.isGML(tag)){
|
141 |
geometry = handler.getProfile().getGeometryBinding(). |
142 |
parse(parser, handler); |
143 |
handler.getContentHandler().addGeometryToFeature(geometry, feature); |
144 |
if (geometry==null){ |
145 |
System.out.println("\t\t\tGEOMETRIA VACIA"); |
146 |
//Warning geometria vacia
|
147 |
} |
148 |
isGeometryTag=true;
|
149 |
}else {
|
150 |
//If is not a geometry could be a complex feature
|
151 |
if (!isInitialized){
|
152 |
String elementName = getElementName(elementRootType);
|
153 |
element = handler.getContentHandler().startElement(GMLUtilsParser.removeBlancSymbol(elementName), |
154 |
null,
|
155 |
type, |
156 |
parentElement); |
157 |
isInitialized = true;
|
158 |
} |
159 |
handler.getProfile().getElementTypeBinding(). |
160 |
parse(parser, handler, feature, element, elementType); |
161 |
} |
162 |
} |
163 |
break;
|
164 |
case XmlPullParser.END_TAG:
|
165 |
if (tag.compareTo(elementRootType) == 0){ |
166 |
endFeature = true;
|
167 |
//If not is complex the element has not been created yet
|
168 |
if (!isInitialized){
|
169 |
String elementName = getElementName(elementRootType);
|
170 |
element = handler.getContentHandler().startElement(GMLUtilsParser.removeBlancSymbol(elementName), |
171 |
value, |
172 |
type, |
173 |
parentElement); |
174 |
isInitialized = true;
|
175 |
} |
176 |
handler.getContentHandler().endElement(element,isGeometryTag); |
177 |
} |
178 |
break;
|
179 |
case XmlPullParser.TEXT:
|
180 |
if (geometry == null){ |
181 |
value = TypeUtils.getValue(elementType, parser.getText()); |
182 |
} |
183 |
break;
|
184 |
} |
185 |
if (!endFeature){
|
186 |
currentTag = parser.next(); |
187 |
tag = parser.getName(); |
188 |
} |
189 |
} |
190 |
return element;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Removes the namespace from a element name
|
195 |
* @return
|
196 |
* The element name without namespace
|
197 |
*/
|
198 |
private static String getElementName(String element){ |
199 |
return element.substring(element.indexOf(":") + 1,element.length()); |
200 |
} |
201 |
} |