Statistics
| Revision:

root / tags / v2_0_0_Build_2020 / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / schema / XMLTypesFactory.java @ 33910

History | View | Annotate | Download (6.79 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.compat.CompatLocator;
8
import org.gvsig.compat.lang.StringUtils;
9
import org.gvsig.remoteclient.wfs.schema.type.GMLGeometryType;
10
import org.gvsig.remoteclient.wfs.schema.type.IXMLType;
11
import org.gvsig.remoteclient.wfs.schema.type.XMLComplexType;
12
import org.gvsig.remoteclient.wfs.schema.type.XMLSimpleType;
13

    
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54
/* CVS MESSAGES:
55
 *
56
 * $Id: XMLTypesFactory.java 18290 2008-01-24 17:11:37Z jpiera $
57
 * $Log$
58
 * Revision 1.9  2007-02-05 13:20:13  jorpiell
59
 * A?adidos nuevos m?todos en la factoria.
60
 *
61
 * Revision 1.8  2006/12/29 17:15:48  jorpiell
62
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
63
 *
64
 * Revision 1.7  2006/12/22 11:25:44  csanchez
65
 * Nuevo parser GML 2.x para gml's sin esquema
66
 *
67
 * Revision 1.5  2006/10/11 11:21:00  jorpiell
68
 * Se escriben los tipos correctamente (no en mayusculas) para que las traducciones funcionen
69
 *
70
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
71
 * Soporte para features complejas.
72
 *
73
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
74
 * Cambios del 10 copiados al head
75
 *
76
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
77
 * Ya no se depende de geotools
78
 *
79
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
80
 * Se han hecho algunas modificaciones que necesitaba el WFS
81
 *
82
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
83
 * Primer commit del driver de Gml
84
 *
85
 *
86
 */
87
/**
88
 * GML and XML types factory. All the types that are
89
 * located in the schemas must be registered here
90
 * 
91
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
92
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
93
 * 
94
 */
95
public class XMLTypesFactory {
96
        private static Hashtable types = new Hashtable();
97
        private static final StringUtils stringUtils = CompatLocator.getStringUtils();
98
        
99
        static{
100
                types.put(XMLSimpleType.STRING.toUpperCase(),new XMLSimpleType(XMLSimpleType.STRING));
101
                types.put(XMLSimpleType.INTEGER.toUpperCase(),new XMLSimpleType(XMLSimpleType.INTEGER));
102
                types.put(XMLSimpleType.INT.toUpperCase(),new XMLSimpleType(XMLSimpleType.INT));
103
                types.put(XMLSimpleType.DOUBLE.toUpperCase(),new XMLSimpleType(XMLSimpleType.DOUBLE));
104
                types.put(XMLSimpleType.FLOAT.toUpperCase(),new XMLSimpleType(XMLSimpleType.FLOAT));
105
                types.put(XMLSimpleType.BOOLEAN.toUpperCase(),new XMLSimpleType(XMLSimpleType.BOOLEAN));
106
                types.put(XMLSimpleType.LONG.toUpperCase(),new XMLSimpleType(XMLSimpleType.LONG));
107
                types.put(XMLSimpleType.DECIMAL.toUpperCase(),new XMLSimpleType(XMLSimpleType.DECIMAL));
108
                types.put(GMLGeometryType.POINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.POINT));
109
                types.put(GMLGeometryType.MULTIPOINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOINT));
110
                types.put(GMLGeometryType.LINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.LINE));
111
                types.put(GMLGeometryType.MULTILINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTILINE));
112
                types.put(GMLGeometryType.POLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.POLYGON));
113
                types.put(GMLGeometryType.MULTIPOLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOLYGON));
114
                types.put(GMLGeometryType.GEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.GEOMETRY));
115
                types.put(GMLGeometryType.MULTIGEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIGEOMETRY));
116
                types.put(GMLGeometryType.SURFACE.toUpperCase(),new GMLGeometryType(GMLGeometryType.SURFACE));
117
                types.put(GMLGeometryType.MULTISURFACE.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTISURFACE));
118
        }
119
        
120
        /**
121
         * Gets a type by name
122
         * @param type
123
         * Type name
124
         * @return
125
         */
126
        public static IXMLType getType(String type){
127
                IXMLType xmlType = (IXMLType)types.get(type.toUpperCase());
128
                if (xmlType == null){
129
                        xmlType = getTypeWithOutNameSpace(type);                        
130
                }
131
                return xmlType;                
132
        }
133
        
134
        /**
135
         * This method is used to solve some mistakes. It doesn't
136
         * consider the namespace
137
         * @param type
138
         * @return
139
         */
140
        public static IXMLType getTypeWithOutNameSpace(String type){
141
                Set keys = types.keySet();
142
                Iterator it = keys.iterator();
143
                String[] typeParts = stringUtils.split(type, ":");
144
                String typeAux = type;
145
                if (typeParts.length > 1){
146
                        typeAux = typeParts[1];
147
                }
148
                while(it.hasNext()){
149
                        String key = (String)it.next();
150
                        String[] parts = stringUtils.split(key, ":");
151
                        if (parts.length == 1){
152
                                if (parts[0].compareTo(typeAux.toUpperCase())==0){
153
                                        return (IXMLType)types.get(key);
154
                                }
155
                        }else if (parts.length > 1){
156
                                if (parts[parts.length-1].compareTo(typeAux.toUpperCase())==0){
157
                                        return (IXMLType)types.get(key);
158
                                }
159
                        }
160
                }
161
                return null;
162
        }
163
        
164
        /**
165
         * Adds a new type
166
         * @param type
167
         * type to add 
168
         */
169
        private static void addType(IXMLType type){
170
                types.put(type.getName().toUpperCase(),type);
171
        }        
172
        
173
        /**
174
         * Adds a complex type
175
         * @param nameSpace
176
         * NameSpace where is located
177
         * @param name
178
         * Complex type name
179
         * @return
180
         */
181
        public static XMLComplexType addComplexType(String nameSpace,String name){
182
                XMLComplexType complexType = new XMLComplexType(name);
183
                addType(complexType);
184
                return complexType;
185
        }
186
        
187
        public static XMLSimpleType addSimpleType(String name,String type){
188
                XMLSimpleType simpleType = new XMLSimpleType(name,type);
189
                types.put(name.toUpperCase(),simpleType);
190
                return simpleType;
191
        }
192

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