Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_1_RELEASE / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / factories / XMLTypesFactory.java @ 9531

History | View | Annotate | Download (5.42 KB)

1
package org.gvsig.remoteClient.gml.factories;
2

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

    
7
import org.gvsig.remoteClient.gml.schemas.GMLGeometryType;
8
import org.gvsig.remoteClient.gml.schemas.IXMLType;
9
import org.gvsig.remoteClient.gml.schemas.XMLComplexType;
10
import org.gvsig.remoteClient.gml.schemas.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 9531 2007-01-03 17:07:37Z  $
55
 * $Log$
56
 * Revision 1.1.2.4  2006-11-27 11:10:32  jorpiell
57
 * A?adido el Poligono como tipo
58
 *
59
 * Revision 1.1.2.3  2006/11/17 11:38:03  ppiqueras
60
 * Corregidos bugs y a?adida nueva funcionalidad. Del HEAD.
61
 *
62
 * Revision 1.5  2006/10/11 11:21:00  jorpiell
63
 * Se escriben los tipos correctamente (no en mayusculas) para que las traducciones funcionen
64
 *
65
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
66
 * Soporte para features complejas.
67
 *
68
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
69
 * Cambios del 10 copiados al head
70
 *
71
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
72
 * Ya no se depende de geotools
73
 *
74
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
75
 * Se han hecho algunas modificaciones que necesitaba el WFS
76
 *
77
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
78
 * Primer commit del driver de Gml
79
 *
80
 *
81
 */
82
/**
83
 * GML and XML types factory. All the types that are
84
 * located in the schemas must be registered here
85
 * 
86
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
87
 */
88
public class XMLTypesFactory {
89
        private static Hashtable types = new Hashtable();
90
                
91
        static{
92
                types.put(XMLSimpleType.STRING.toUpperCase(),new XMLSimpleType(XMLSimpleType.STRING));
93
                types.put(XMLSimpleType.INTEGER.toUpperCase(),new XMLSimpleType(XMLSimpleType.INTEGER));
94
                types.put(XMLSimpleType.INT.toUpperCase(),new XMLSimpleType(XMLSimpleType.INT));
95
                types.put(XMLSimpleType.DOUBLE.toUpperCase(),new XMLSimpleType(XMLSimpleType.DOUBLE));
96
                types.put(XMLSimpleType.FLOAT.toUpperCase(),new XMLSimpleType(XMLSimpleType.FLOAT));
97
                types.put(XMLSimpleType.BOOLEAN.toUpperCase(),new XMLSimpleType(XMLSimpleType.BOOLEAN));
98
                types.put(XMLSimpleType.LONG.toUpperCase(),new XMLSimpleType(XMLSimpleType.LONG));
99
                types.put(GMLGeometryType.POINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.POINT));
100
                types.put(GMLGeometryType.MULTIPOINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOINT));
101
                types.put(GMLGeometryType.LINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.LINE));
102
                types.put(GMLGeometryType.POLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.POLYGON));
103
                types.put(GMLGeometryType.MULTIPOLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOLYGON));
104
                types.put(GMLGeometryType.GEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.GEOMETRY));
105
        }
106
        
107
        /**
108
         * Gets a type by name
109
         * @param type
110
         * Type name
111
         * @return
112
         */
113
        public static IXMLType getType(String type){
114
                IXMLType xmlType = (IXMLType)types.get(type.toUpperCase());
115
                if (xmlType == null){
116
                        xmlType = getTypeWithOutNameSpace(type);
117
                }
118
                return xmlType;                
119
        }
120
        
121
        /**
122
         * This method is used to solve some mistakes. It doesn't
123
         * consider the namespace
124
         * @param type
125
         * @return
126
         */
127
        public static IXMLType getTypeWithOutNameSpace(String type){
128
                Set keys = types.keySet();
129
                Iterator it = keys.iterator();
130
                while(it.hasNext()){
131
                        String key = (String)it.next();
132
                        String[] parts = key.split(":");
133
                        if (parts.length > 1){
134
                                if (parts[1].compareTo(type.toUpperCase())==0){
135
                                        return (IXMLType)types.get(key);
136
                                }
137
                        }
138
                }
139
                return null;
140
        }
141
        
142
        /**
143
         * Adds a new type
144
         * @param type
145
         * type to add 
146
         */
147
        private static void addType(IXMLType type){
148
                types.put(type.getName().toUpperCase(),type);
149
        }        
150
        
151
        /**
152
         * Adds a complex type
153
         * @param nameSpace
154
         * NameSpace where is located
155
         * @param name
156
         * Complex type name
157
         * @return
158
         */
159
        public static XMLComplexType addComplexType(String nameSpace,String name){
160
                XMLComplexType complexType = new XMLComplexType(nameSpace + ":" + name);
161
                addType(complexType);
162
                return complexType;
163
        }
164

    
165
        /**
166
         * Just for degug. It prints all the registred components.
167
         */
168
        public static void printTypes(){
169
                System.out.println("*** TIPOS ***");
170
                Object[] keys = types.keySet().toArray();
171
                for (int i=0 ; i<types.size() ; i++){
172
                        IXMLType type = (IXMLType)types.get(keys[i]);
173
                        System.out.print("NAME: " + type.getName());
174
                        System.out.print(" TYPE: " + type.getType() + "\n");
175
                }
176
        }
177
        
178
}