svn-gvsig-desktop / tags / v10_RC2c / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / schemas / XMLSimpleType.java @ 8745
History | View | Annotate | Download (5.81 KB)
1 |
package org.gvsig.remoteClient.gml.schemas; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.remoteClient.gml.GMLException; |
6 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
7 |
import org.kxml2.io.KXmlParser; |
8 |
import org.xmlpull.v1.XmlPullParserException; |
9 |
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*/
|
50 |
/* CVS MESSAGES:
|
51 |
*
|
52 |
* $Id: XMLSimpleType.java 8745 2006-11-14 13:14:23Z $
|
53 |
* $Log$
|
54 |
* Revision 1.1.2.1 2006-09-19 12:23:15 jorpiell
|
55 |
* Ya no se depende de geotools
|
56 |
*
|
57 |
* Revision 1.2 2006/09/18 12:08:55 jorpiell
|
58 |
* Se han hecho algunas modificaciones que necesitaba el WFS
|
59 |
*
|
60 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell
|
61 |
* Primer commit del driver de Gml
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
/**
|
66 |
* A XS simple data type.
|
67 |
*
|
68 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
69 |
*/
|
70 |
public class XMLSimpleType implements IXMLType{ |
71 |
public static final String STRING = "XS:STRING"; |
72 |
public static final String INTEGER = "XS:INTEGER"; |
73 |
public static final String DOUBLE = "XS:DOUBLE"; |
74 |
public static final String FLOAT = "XS:FLOAT"; |
75 |
public static final String BOOLEAN = "XS:BOOLEAN"; |
76 |
public static final String LONG = "XS:LONG"; |
77 |
public static final String INT = "XS:INT"; |
78 |
|
79 |
private String type = null; |
80 |
private int totalDigits = 0; |
81 |
private int fractionDigits = 0; |
82 |
|
83 |
|
84 |
|
85 |
public XMLSimpleType(String type) { |
86 |
super();
|
87 |
this.type = type;
|
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
* @see org.gvsig.remoteClient.gml.IXMLType#getName()
|
93 |
*/
|
94 |
public String getName() { |
95 |
return type;
|
96 |
} |
97 |
|
98 |
/*
|
99 |
* (non-Javadoc)
|
100 |
* @see org.gvsig.remoteClient.gml.IXMLType#getType()
|
101 |
*/
|
102 |
public int getType() { |
103 |
return IXMLType.SIMPLE;
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* @return Returns the fractionDigits.
|
108 |
*/
|
109 |
public int getFractionDigits() { |
110 |
return fractionDigits;
|
111 |
} |
112 |
/**
|
113 |
* @param fractionDigits The fractionDigits to set.
|
114 |
*/
|
115 |
public void setFractionDigits(int fractionDigits) { |
116 |
this.fractionDigits = fractionDigits;
|
117 |
} |
118 |
/**
|
119 |
* @return Returns the totalDigits.
|
120 |
*/
|
121 |
public int getTotalDigits() { |
122 |
return totalDigits;
|
123 |
} |
124 |
/**
|
125 |
* @param totalDigits The totalDigits to set.
|
126 |
*/
|
127 |
public void setTotalDigits(int totalDigits) { |
128 |
this.totalDigits = totalDigits;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* @param type The type to set.
|
133 |
*/
|
134 |
public void setType(String type) { |
135 |
this.type = type;
|
136 |
} |
137 |
|
138 |
public Object getObject(String value)throws GMLException{ |
139 |
try{
|
140 |
if (type.equals(STRING)){
|
141 |
return value;
|
142 |
}else if (type.equals(INTEGER)){ |
143 |
return new Integer(value); |
144 |
}else if (type.equals(DOUBLE)){ |
145 |
return new Double(value); |
146 |
}else if (type.equals(FLOAT)){ |
147 |
return new Float(value); |
148 |
}else if (type.equals(BOOLEAN)){ |
149 |
return new Boolean(value); |
150 |
} |
151 |
}catch (Exception e){ |
152 |
throw new GMLException(GMLException.EXC_ATTRIB_WITH_INVALID_FORMAT); |
153 |
} |
154 |
return value;
|
155 |
} |
156 |
|
157 |
private void parseSimpleType(XMLSchemaParser parser) throws IOException, XmlPullParserException |
158 |
{ |
159 |
int currentTag;
|
160 |
boolean end = false; |
161 |
|
162 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SIMPLETYPE);
|
163 |
currentTag = parser.next(); |
164 |
|
165 |
while (!end)
|
166 |
{ |
167 |
switch(currentTag)
|
168 |
{ |
169 |
case KXmlParser.START_TAG:
|
170 |
if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION)==0) |
171 |
{ |
172 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
173 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.BASE) == 0){ |
174 |
setType(parser.getAttributeValue(i)); |
175 |
} |
176 |
} |
177 |
parseRestriction(parser); |
178 |
} |
179 |
break;
|
180 |
case KXmlParser.END_TAG:
|
181 |
if (parser.getName().compareTo(CapabilitiesTags.SIMPLETYPE) == 0) |
182 |
end = true;
|
183 |
break;
|
184 |
case KXmlParser.TEXT:
|
185 |
break;
|
186 |
} |
187 |
if (!end){
|
188 |
currentTag = parser.next(); |
189 |
} |
190 |
} |
191 |
} |
192 |
|
193 |
private void parseRestriction(XMLSchemaParser parser) throws IOException, XmlPullParserException |
194 |
{ |
195 |
int currentTag;
|
196 |
boolean end = false; |
197 |
|
198 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.RESTRICTION);
|
199 |
currentTag = parser.next(); |
200 |
|
201 |
while (!end)
|
202 |
{ |
203 |
switch(currentTag)
|
204 |
{ |
205 |
case KXmlParser.START_TAG:
|
206 |
if (parser.getName().compareTo(CapabilitiesTags.TOTAL_DIGITS)==0) |
207 |
{ |
208 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
209 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){ |
210 |
setTotalDigits(Integer.parseInt(parser.getAttributeValue(i)));
|
211 |
} |
212 |
} |
213 |
}else if (parser.getName().compareTo(CapabilitiesTags.FRACTION_DIGITS)==0){ |
214 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
215 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){ |
216 |
setFractionDigits(Integer.parseInt(parser.getAttributeValue(i)));
|
217 |
} |
218 |
} |
219 |
} |
220 |
break;
|
221 |
case KXmlParser.END_TAG:
|
222 |
if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION) == 0) |
223 |
end = true;
|
224 |
break;
|
225 |
case KXmlParser.TEXT:
|
226 |
break;
|
227 |
} |
228 |
if (!end){
|
229 |
currentTag = parser.next(); |
230 |
} |
231 |
} |
232 |
} |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
} |