Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / schemas / XMLSimpleType.java @ 7716

History | View | Annotate | Download (5.89 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 7716 2006-10-02 08:34:22Z jorpiell $
53
 * $Log$
54
 * Revision 1.3  2006-10-02 08:33:49  jorpiell
55
 * Cambios del 10 copiados al head
56
 *
57
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
58
 * Ya no se depende de geotools
59
 *
60
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
61
 * Se han hecho algunas modificaciones que necesitaba el WFS
62
 *
63
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
64
 * Primer commit del driver de Gml
65
 *
66
 *
67
 */
68
/**
69
 * A XS simple data type.
70
 * 
71
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
72
 */
73
public class XMLSimpleType implements IXMLType{
74
        public static final String STRING = "XS:STRING";
75
        public static final String INTEGER = "XS:INTEGER";
76
        public static final String DOUBLE = "XS:DOUBLE";
77
        public static final String FLOAT = "XS:FLOAT";
78
        public static final String BOOLEAN = "XS:BOOLEAN";
79
        public static final String LONG = "XS:LONG";
80
        public static final String INT = "XS:INT";
81
        
82
        private String type = null;
83
        private int totalDigits = 0;
84
        private int fractionDigits = 0;
85
        
86
        
87
        
88
        public XMLSimpleType(String type) {
89
                super();
90
                this.type = type;
91
        }
92

    
93
        /*
94
         *  (non-Javadoc)
95
         * @see org.gvsig.remoteClient.gml.IXMLType#getName()
96
         */
97
        public String getName() {
98
                return type;
99
        }
100
        
101
        /*
102
         *  (non-Javadoc)
103
         * @see org.gvsig.remoteClient.gml.IXMLType#getType()
104
         */
105
        public int getType() {
106
                return IXMLType.SIMPLE;
107
        }
108
        
109
        /**
110
         * @return Returns the fractionDigits.
111
         */
112
        public int getFractionDigits() {
113
                return fractionDigits;
114
        }
115
        /**
116
         * @param fractionDigits The fractionDigits to set.
117
         */
118
        public void setFractionDigits(int fractionDigits) {
119
                this.fractionDigits = fractionDigits;
120
        }
121
        /**
122
         * @return Returns the totalDigits.
123
         */
124
        public int getTotalDigits() {
125
                return totalDigits;
126
        }
127
        /**
128
         * @param totalDigits The totalDigits to set.
129
         */
130
        public void setTotalDigits(int totalDigits) {
131
                this.totalDigits = totalDigits;
132
        }
133

    
134
        /**
135
         * @param type The type to set.
136
         */
137
        public void setType(String type) {
138
                this.type = type;        
139
        }        
140

    
141
        public Object getObject(String value)throws GMLException{
142
                try{
143
                        if (type.equals(STRING)){
144
                                return value;
145
                        }else if (type.equals(INTEGER)){
146
                                return new Integer(value);
147
                        }else if (type.equals(DOUBLE)){
148
                                return new Double(value);
149
                        }else if (type.equals(FLOAT)){
150
                                return new Float(value);
151
                        }else if (type.equals(BOOLEAN)){
152
                                return new Boolean(value);
153
                        }
154
                }catch (Exception e){
155
                        throw new GMLException(GMLException.EXC_ATTRIB_WITH_INVALID_FORMAT);
156
                }
157
                return value;
158
        }
159
        
160
        private void parseSimpleType(XMLSchemaParser parser) throws IOException, XmlPullParserException
161
        {   
162
                int currentTag;
163
                boolean end = false;
164
                
165
                parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SIMPLETYPE);
166
                currentTag = parser.next();
167
                
168
                while (!end) 
169
                {
170
                        switch(currentTag)
171
                        {
172
                        case KXmlParser.START_TAG:
173
                                if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION)==0)
174
                                {
175
                                        for (int i=0 ; i<parser.getAttributeCount() ; i++){
176
                                                if (parser.getAttributeName(i).compareTo(CapabilitiesTags.BASE) == 0){
177
                                                        setType(parser.getAttributeValue(i));
178
                                                }
179
                                        }
180
                                        parseRestriction(parser);
181
                                }   
182
                                break;
183
                        case KXmlParser.END_TAG:
184
                                if (parser.getName().compareTo(CapabilitiesTags.SIMPLETYPE) == 0)
185
                                        end = true;
186
                                break;
187
                        case KXmlParser.TEXT:                   
188
                                break;
189
                        }
190
                        if (!end){
191
                                currentTag = parser.next();
192
                        }        
193
                }
194
        }
195
        
196
        private void parseRestriction(XMLSchemaParser parser) throws IOException, XmlPullParserException
197
        {   
198
                int currentTag;
199
                boolean end = false;
200
                
201
                parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.RESTRICTION);
202
                currentTag = parser.next();
203
                
204
                while (!end) 
205
                {
206
                        switch(currentTag)
207
                        {
208
                        case KXmlParser.START_TAG:
209
                                if (parser.getName().compareTo(CapabilitiesTags.TOTAL_DIGITS)==0)
210
                                {
211
                                        for (int i=0 ; i<parser.getAttributeCount() ; i++){
212
                                                if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){
213
                                                        setTotalDigits(Integer.parseInt(parser.getAttributeValue(i)));
214
                                                }
215
                                        }
216
                                }else if (parser.getName().compareTo(CapabilitiesTags.FRACTION_DIGITS)==0){
217
                                        for (int i=0 ; i<parser.getAttributeCount() ; i++){
218
                                                if (parser.getAttributeName(i).compareTo(CapabilitiesTags.VALUE) == 0){
219
                                                        setFractionDigits(Integer.parseInt(parser.getAttributeValue(i)));
220
                                                }
221
                                        }
222
                                }
223
                                break;
224
                        case KXmlParser.END_TAG:
225
                                if (parser.getName().compareTo(CapabilitiesTags.RESTRICTION) == 0)
226
                                        end = true;
227
                                break;
228
                        case KXmlParser.TEXT:                   
229
                                break;
230
                        }
231
                        if (!end){
232
                                currentTag = parser.next();
233
                        }        
234
                }
235
        }
236

    
237

    
238
        
239
        
240
        
241
        
242
}