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