Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteClient / wfs / schema / XMLTypesFactory.java @ 28543

History | View | Annotate | Download (6.61 KB)

1
package org.gvsig.remoteClient.wfs.schema;
2

    
3
import java.util.Hashtable;
4
import java.util.Iterator;
5
import java.util.Set;
6

    
7
import org.gvsig.remoteClient.wfs.schema.type.GMLGeometryType;
8
import org.gvsig.remoteClient.wfs.schema.type.IXMLType;
9
import org.gvsig.remoteClient.wfs.schema.type.XMLComplexType;
10
import org.gvsig.remoteClient.wfs.schema.type.XMLSimpleType;
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: XMLTypesFactory.java 18290 2008-01-24 17:11:37Z jpiera $
55
 * $Log$
56
 * Revision 1.9  2007-02-05 13:20:13  jorpiell
57
 * A?adidos nuevos m?todos en la factoria.
58
 *
59
 * Revision 1.8  2006/12/29 17:15:48  jorpiell
60
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
61
 *
62
 * Revision 1.7  2006/12/22 11:25:44  csanchez
63
 * Nuevo parser GML 2.x para gml's sin esquema
64
 *
65
 * Revision 1.5  2006/10/11 11:21:00  jorpiell
66
 * Se escriben los tipos correctamente (no en mayusculas) para que las traducciones funcionen
67
 *
68
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
69
 * Soporte para features complejas.
70
 *
71
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
72
 * Cambios del 10 copiados al head
73
 *
74
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
75
 * Ya no se depende de geotools
76
 *
77
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
78
 * Se han hecho algunas modificaciones que necesitaba el WFS
79
 *
80
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
81
 * Primer commit del driver de Gml
82
 *
83
 *
84
 */
85
/**
86
 * GML and XML types factory. All the types that are
87
 * located in the schemas must be registered here
88
 * 
89
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
90
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
91
 * 
92
 */
93
public class XMLTypesFactory {
94
        private static Hashtable types = new Hashtable();
95
                
96
        static{
97
                types.put(XMLSimpleType.STRING.toUpperCase(),new XMLSimpleType(XMLSimpleType.STRING));
98
                types.put(XMLSimpleType.INTEGER.toUpperCase(),new XMLSimpleType(XMLSimpleType.INTEGER));
99
                types.put(XMLSimpleType.INT.toUpperCase(),new XMLSimpleType(XMLSimpleType.INT));
100
                types.put(XMLSimpleType.DOUBLE.toUpperCase(),new XMLSimpleType(XMLSimpleType.DOUBLE));
101
                types.put(XMLSimpleType.FLOAT.toUpperCase(),new XMLSimpleType(XMLSimpleType.FLOAT));
102
                types.put(XMLSimpleType.BOOLEAN.toUpperCase(),new XMLSimpleType(XMLSimpleType.BOOLEAN));
103
                types.put(XMLSimpleType.LONG.toUpperCase(),new XMLSimpleType(XMLSimpleType.LONG));
104
                types.put(XMLSimpleType.DECIMAL.toUpperCase(),new XMLSimpleType(XMLSimpleType.DECIMAL));
105
                types.put(GMLGeometryType.POINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.POINT));
106
                types.put(GMLGeometryType.MULTIPOINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOINT));
107
                types.put(GMLGeometryType.LINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.LINE));
108
                types.put(GMLGeometryType.MULTILINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTILINE));
109
                types.put(GMLGeometryType.POLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.POLYGON));
110
                types.put(GMLGeometryType.MULTIPOLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOLYGON));
111
                types.put(GMLGeometryType.GEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.GEOMETRY));
112
                types.put(GMLGeometryType.MULTIGEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIGEOMETRY));
113
                types.put(GMLGeometryType.SURFACE.toUpperCase(),new GMLGeometryType(GMLGeometryType.SURFACE));
114
                types.put(GMLGeometryType.MULTISURFACE.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTISURFACE));
115
        }
116
        
117
        /**
118
         * Gets a type by name
119
         * @param type
120
         * Type name
121
         * @return
122
         */
123
        public static IXMLType getType(String type){
124
                IXMLType xmlType = (IXMLType)types.get(type.toUpperCase());
125
                if (xmlType == null){
126
                        xmlType = getTypeWithOutNameSpace(type);                        
127
                }
128
                return xmlType;                
129
        }
130
        
131
        /**
132
         * This method is used to solve some mistakes. It doesn't
133
         * consider the namespace
134
         * @param type
135
         * @return
136
         */
137
        public static IXMLType getTypeWithOutNameSpace(String type){
138
                Set keys = types.keySet();
139
                Iterator it = keys.iterator();
140
                String[] typeParts = type.split(":");
141
                String typeAux = type;
142
                if (typeParts.length > 1){
143
                        typeAux = typeParts[1];
144
                }
145
                while(it.hasNext()){
146
                        String key = (String)it.next();
147
                        String[] parts = key.split(":");
148
                        if (parts.length == 1){
149
                                if (parts[0].compareTo(typeAux.toUpperCase())==0){
150
                                        return (IXMLType)types.get(key);
151
                                }
152
                        }else if (parts.length > 1){
153
                                if (parts[parts.length-1].compareTo(typeAux.toUpperCase())==0){
154
                                        return (IXMLType)types.get(key);
155
                                }
156
                        }
157
                }
158
                return null;
159
        }
160
        
161
        /**
162
         * Adds a new type
163
         * @param type
164
         * type to add 
165
         */
166
        private static void addType(IXMLType type){
167
                types.put(type.getName().toUpperCase(),type);
168
        }        
169
        
170
        /**
171
         * Adds a complex type
172
         * @param nameSpace
173
         * NameSpace where is located
174
         * @param name
175
         * Complex type name
176
         * @return
177
         */
178
        public static XMLComplexType addComplexType(String nameSpace,String name){
179
                XMLComplexType complexType = new XMLComplexType(name);
180
                addType(complexType);
181
                return complexType;
182
        }
183
        
184
        public static XMLSimpleType addSimpleType(String name,String type){
185
                XMLSimpleType simpleType = new XMLSimpleType(name,type);
186
                types.put(name.toUpperCase(),simpleType);
187
                return simpleType;
188
        }
189

    
190
        /**
191
         * Just for degug. It prints all the registred components.
192
         */
193
        public static void printTypes(){
194
                System.out.println("*** TIPOS ***");
195
                Object[] keys = types.keySet().toArray();
196
                for (int i=0 ; i<types.size() ; i++){
197
                        IXMLType type = (IXMLType)types.get(keys[i]);
198
                        System.out.print("NAME: " + type.getName());
199
                        System.out.print(" TYPE: " + type.getType() + "\n");
200
                }
201
        }
202
        
203
}