Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / factories / XMLTypesFactory.java @ 8017

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

    
155
        /**
156
         * Just for degug. It prints all the registred components.
157
         */
158
        public static void printTypes(){
159
                System.out.println("*** TIPOS ***");
160
                Object[] keys = types.keySet().toArray();
161
                for (int i=0 ; i<types.size() ; i++){
162
                        IXMLType type = (IXMLType)types.get(keys[i]);
163
                        System.out.print("NAME: " + type.getName());
164
                        System.out.print(" TYPE: " + type.getType() + "\n");
165
                }
166
        }
167
        
168
}