root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / schemas / XMLElement.java @ 8017
History | View | Annotate | Download (8 KB)
1 |
package org.gvsig.remoteClient.gml.schemas; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.remoteClient.gml.GMLTags; |
6 |
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory; |
7 |
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory; |
8 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
9 |
import org.kxml2.io.KXmlParser; |
10 |
import org.xmlpull.v1.XmlPullParserException; |
11 |
|
12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
13 |
*
|
14 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
15 |
*
|
16 |
* This program is free software; you can redistribute it and/or
|
17 |
* modify it under the terms of the GNU General Public License
|
18 |
* as published by the Free Software Foundation; either version 2
|
19 |
* of the License, or (at your option) any later version.
|
20 |
*
|
21 |
* This program is distributed in the hope that it will be useful,
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
* GNU General Public License for more details.
|
25 |
*
|
26 |
* You should have received a copy of the GNU General Public License
|
27 |
* along with this program; if not, write to the Free Software
|
28 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
29 |
*
|
30 |
* For more information, contact:
|
31 |
*
|
32 |
* Generalitat Valenciana
|
33 |
* Conselleria d'Infraestructures i Transport
|
34 |
* Av. Blasco Ib??ez, 50
|
35 |
* 46010 VALENCIA
|
36 |
* SPAIN
|
37 |
*
|
38 |
* +34 963862235
|
39 |
* gvsig@gva.es
|
40 |
* www.gvsig.gva.es
|
41 |
*
|
42 |
* or
|
43 |
*
|
44 |
* IVER T.I. S.A
|
45 |
* Salamanca 50
|
46 |
* 46005 Valencia
|
47 |
* Spain
|
48 |
*
|
49 |
* +34 963163400
|
50 |
* dac@iver.es
|
51 |
*/
|
52 |
/* CVS MESSAGES:
|
53 |
*
|
54 |
* $Id: XMLElement.java 8017 2006-10-10 12:52:28Z jorpiell $
|
55 |
* $Log$
|
56 |
* Revision 1.3 2006-10-10 12:52:28 jorpiell
|
57 |
* Soporte para features complejas.
|
58 |
*
|
59 |
* Revision 1.2 2006/08/29 08:43:13 jorpiell
|
60 |
* Dos peque?os cambios para tener en cuenta las referencias
|
61 |
*
|
62 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell
|
63 |
* Primer commit del driver de Gml
|
64 |
*
|
65 |
*
|
66 |
*/
|
67 |
/**
|
68 |
* A simple XSD element that represent an object
|
69 |
* with a type of data.
|
70 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
71 |
*/
|
72 |
public class XMLElement { |
73 |
private String name = null; |
74 |
private String reference = null; |
75 |
private IXMLType type = null; |
76 |
private String typeUnknown = null; |
77 |
private int minOccurs = -1; |
78 |
private int maxOccurs = -1; |
79 |
private int totalDigits = 0; |
80 |
private int fractionDigits = 0; |
81 |
|
82 |
public XMLElement(XMLSchemaParser parser) throws XmlPullParserException, IOException { |
83 |
super();
|
84 |
parse(parser); |
85 |
} |
86 |
|
87 |
public XMLElement(String name) { |
88 |
super();
|
89 |
this.name = name;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* @return Returns the maxOccurs.
|
94 |
*/
|
95 |
public int getMaxOccurs() { |
96 |
return maxOccurs;
|
97 |
} |
98 |
/**
|
99 |
* @param maxOccurs The maxOccurs to set.
|
100 |
*/
|
101 |
public void setMaxOccurs(int maxOccurs) { |
102 |
this.maxOccurs = maxOccurs;
|
103 |
} |
104 |
/**
|
105 |
* @return Returns the minOccurs.
|
106 |
*/
|
107 |
public int getMinOccurs() { |
108 |
return minOccurs;
|
109 |
} |
110 |
/**
|
111 |
* @param minOccurs The minOccurs to set.
|
112 |
*/
|
113 |
public void setMinOccurs(int minOccurs) { |
114 |
this.minOccurs = minOccurs;
|
115 |
} |
116 |
/**
|
117 |
* @return Returns the name.
|
118 |
*/
|
119 |
public String getName() { |
120 |
return name;
|
121 |
} |
122 |
/**
|
123 |
* @param name The name to set.
|
124 |
*/
|
125 |
public void setName(String name) { |
126 |
this.name = name;
|
127 |
} |
128 |
/**
|
129 |
* @return Returns the type.
|
130 |
*/
|
131 |
public IXMLType getEntityType() {
|
132 |
if (type != null){ |
133 |
return type;
|
134 |
} |
135 |
if (typeUnknown != null){ |
136 |
this.type = XMLTypesFactory.getType(typeUnknown);
|
137 |
} |
138 |
if ((type == null) && (typeUnknown != null)){ |
139 |
if (typeUnknown.split(":").length > 1){ |
140 |
this.type = XMLTypesFactory.getType(null + ":" + typeUnknown.split(":")[1]); |
141 |
} |
142 |
} |
143 |
return type;
|
144 |
|
145 |
} |
146 |
/**
|
147 |
* @param type The type to set.
|
148 |
*/
|
149 |
public void setEntityType(String type) { |
150 |
IXMLType xmlType = XMLTypesFactory.getType(type); |
151 |
if (xmlType == null){ |
152 |
String[] types = type.split(":"); |
153 |
if (types.length == 1){ |
154 |
xmlType = XMLTypesFactory.getType("XS:" + type);
|
155 |
} |
156 |
if (xmlType == null){ |
157 |
xmlType = XMLTypesFactory.getType("GML:" + type);
|
158 |
} |
159 |
if (xmlType == null){ |
160 |
typeUnknown = type; |
161 |
} |
162 |
} |
163 |
this.type = xmlType;
|
164 |
} |
165 |
|
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
* @see java.lang.Object#toString()
|
169 |
*/
|
170 |
public String toString(){ |
171 |
return name;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Parses the contents of the parser to extract the information
|
176 |
* about a XSD element
|
177 |
* @throws IOException
|
178 |
* @throws XmlPullParserException
|
179 |
*
|
180 |
*/
|
181 |
private void parse(XMLSchemaParser parser) throws XmlPullParserException, IOException{ |
182 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
183 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_NAME) == 0){ |
184 |
setName(parser.getAttributeValue(i)); |
185 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_TYPE) == 0){ |
186 |
setEntityType(parser.getAttributeValue(i)); |
187 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_MAXOCCURS) == 0){ |
188 |
try{
|
189 |
setMaxOccurs(Integer.parseInt(parser.getAttributeValue(i)));
|
190 |
}catch(NumberFormatException e){ |
191 |
setMaxOccurs(0);
|
192 |
} |
193 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_MINOCCURS) == 0){ |
194 |
try{
|
195 |
setMinOccurs(Integer.parseInt(parser.getAttributeValue(i)));
|
196 |
}catch(NumberFormatException e){ |
197 |
setMinOccurs(0);
|
198 |
} |
199 |
}else if (parser.getAttributeName(i).compareTo(CapabilitiesTags.ELEMENT_REF) == 0){ |
200 |
setReference(parser.getAttributeValue(i)); |
201 |
} |
202 |
} |
203 |
|
204 |
} |
205 |
|
206 |
private void parseSimpleType(XMLSchemaParser parser) throws IOException, XmlPullParserException |
207 |
{ |
208 |
int currentTag;
|
209 |
boolean end = false; |
210 |
currentTag = parser.getEventType(); |
211 |
|
212 |
while (!end)
|
213 |
{ |
214 |
switch(currentTag)
|
215 |
{ |
216 |
case KXmlParser.START_TAG:
|
217 |
if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION)==0){ |
218 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
219 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.BASE) == 0){ |
220 |
setEntityType(parser.getAttributeValue(i)); |
221 |
} |
222 |
} |
223 |
parseRestriction(parser); |
224 |
} |
225 |
break;
|
226 |
case KXmlParser.END_TAG:
|
227 |
if (parser.getName().compareTo(CapabilitiesTags.SIMPLETYPE) == 0) |
228 |
end = true;
|
229 |
break;
|
230 |
case KXmlParser.TEXT:
|
231 |
break;
|
232 |
} |
233 |
if (!end){
|
234 |
currentTag = parser.next(); |
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
private void parseRestriction(XMLSchemaParser parser) throws IOException, XmlPullParserException |
240 |
{ |
241 |
int currentTag;
|
242 |
boolean end = false; |
243 |
|
244 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.RESTRICTION);
|
245 |
currentTag = parser.next(); |
246 |
|
247 |
while (!end)
|
248 |
{ |
249 |
switch(currentTag)
|
250 |
{ |
251 |
case KXmlParser.START_TAG:
|
252 |
if (parser.getName().compareTo(CapabilitiesTags.TOTAL_DIGITS)==0) |
253 |
{ |
254 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
255 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){ |
256 |
setTotalDigits(Integer.parseInt(parser.getAttributeValue(i)));
|
257 |
} |
258 |
} |
259 |
}else if (parser.getName().compareTo(CapabilitiesTags.FRACTION_DIGITS)==0){ |
260 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
261 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){ |
262 |
setFractionDigits(Integer.parseInt(parser.getAttributeValue(i)));
|
263 |
} |
264 |
} |
265 |
} |
266 |
break;
|
267 |
case KXmlParser.END_TAG:
|
268 |
if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION) == 0) |
269 |
end = true;
|
270 |
break;
|
271 |
case KXmlParser.TEXT:
|
272 |
break;
|
273 |
} |
274 |
if (!end){
|
275 |
currentTag = parser.next(); |
276 |
} |
277 |
} |
278 |
} |
279 |
|
280 |
/**
|
281 |
* @return Returns the reference.
|
282 |
*/
|
283 |
public String getReference() { |
284 |
return reference;
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* @param reference The reference to set.
|
289 |
*/
|
290 |
public void setReference(String reference) { |
291 |
this.reference = reference;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* @return Returns the fractionDigits.
|
296 |
*/
|
297 |
public int getFractionDigits() { |
298 |
return fractionDigits;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* @param fractionDigits The fractionDigits to set.
|
303 |
*/
|
304 |
public void setFractionDigits(int fractionDigits) { |
305 |
this.fractionDigits = fractionDigits;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* @return Returns the totalDigits.
|
310 |
*/
|
311 |
public int getTotalDigits() { |
312 |
return totalDigits;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* @param totalDigits The totalDigits to set.
|
317 |
*/
|
318 |
public void setTotalDigits(int totalDigits) { |
319 |
this.totalDigits = totalDigits;
|
320 |
} |
321 |
|
322 |
|
323 |
} |