Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / factories / XMLTypesFactory.java @ 9917

History | View | Annotate | Download (5.72 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.types.GMLGeometryType;
8
import org.gvsig.remoteClient.gml.types.IXMLType;
9
import org.gvsig.remoteClient.gml.types.XMLComplexType;
10
import org.gvsig.remoteClient.gml.types.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 9917 2007-01-25 16:13:00Z jorpiell $
55
 * $Log$
56
 * Revision 1.1.2.5  2007-01-25 16:12:59  jorpiell
57
 * Se han sustituido las clases por las que hay en el nuevo driver de GML.
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(GMLGeometryType.POINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.POINT));
105
                types.put(GMLGeometryType.MULTIPOINT.toUpperCase(),new GMLGeometryType(GMLGeometryType.MULTIPOINT));
106
                types.put(GMLGeometryType.LINE.toUpperCase(),new GMLGeometryType(GMLGeometryType.LINE));
107
                types.put(GMLGeometryType.POLYGON.toUpperCase(),new GMLGeometryType(GMLGeometryType.POLYGON));
108
                types.put(GMLGeometryType.GEOMETRY.toUpperCase(),new GMLGeometryType(GMLGeometryType.GEOMETRY));
109
        }
110
        
111
        /**
112
         * Gets a type by name
113
         * @param type
114
         * Type name
115
         * @return
116
         */
117
        public static IXMLType getType(String type){
118
                IXMLType xmlType = (IXMLType)types.get(type.toUpperCase());
119
                if (xmlType == null){
120
                        xmlType = getTypeWithOutNameSpace(type);                        
121
                }
122
                return xmlType;                
123
        }
124
        
125
        /**
126
         * This method is used to solve some mistakes. It doesn't
127
         * consider the namespace
128
         * @param type
129
         * @return
130
         */
131
        public static IXMLType getTypeWithOutNameSpace(String type){
132
                Set keys = types.keySet();
133
                Iterator it = keys.iterator();
134
                while(it.hasNext()){
135
                        String key = (String)it.next();
136
                        String[] parts = key.split(":");
137
                        if (parts.length > 1){
138
                                if (parts[1].compareTo(type.toUpperCase())==0){
139
                                        return (IXMLType)types.get(key);
140
                                }
141
                        }
142
                }
143
                return null;
144
        }
145
        
146
        /**
147
         * Adds a new type
148
         * @param type
149
         * type to add 
150
         */
151
        private static void addType(IXMLType type){
152
                types.put(type.getName().toUpperCase(),type);
153
        }        
154
        
155
        /**
156
         * Adds a complex type
157
         * @param nameSpace
158
         * NameSpace where is located
159
         * @param name
160
         * Complex type name
161
         * @return
162
         */
163
        public static XMLComplexType addComplexType(String nameSpace,String name){
164
                XMLComplexType complexType = new XMLComplexType(nameSpace + ":" + name);
165
                addType(complexType);
166
                return complexType;
167
        }
168
        
169
        public static XMLSimpleType addSimpleType(String name,String type){
170
                XMLSimpleType simpleType = new XMLSimpleType(name,type);
171
                types.put(name.toUpperCase(),simpleType);
172
                return simpleType;
173
        }
174

    
175
        /**
176
         * Just for degug. It prints all the registred components.
177
         */
178
        public static void printTypes(){
179
                System.out.println("*** TIPOS ***");
180
                Object[] keys = types.keySet().toArray();
181
                for (int i=0 ; i<types.size() ; i++){
182
                        IXMLType type = (IXMLType)types.get(keys[i]);
183
                        System.out.print("NAME: " + type.getName());
184
                        System.out.print(" TYPE: " + type.getType() + "\n");
185
                }
186
        }
187
        
188
}