Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / kml / KmlParsersFactory.java @ 12043

History | View | Annotate | Download (3.35 KB)

1
package org.gvsig.remoteClient.kml;
2

    
3
import java.util.Hashtable;
4

    
5
import org.gvsig.exceptions.BaseException;
6
import org.gvsig.remoteClient.gml.engine.AbstractFeaturesParser;
7
import org.gvsig.remoteClient.gml.engine.IFeaturesParser;
8
import org.gvsig.remoteClient.gml.engine.readers.IReaderFile;
9
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
10
import org.gvsig.remoteClient.kml.exceptions.KmlImpossibleCreateParser;
11
import org.gvsig.remoteClient.kml.warnings.NotNamespaceParserWarning;
12
import org.gvsig.remoteClient.kml.warnings.WarningsContainer;
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: KmlParsersFactory.java 10269 2007-02-12 13:51:08Z jorpiell $
57
 * $Log$
58
 * Revision 1.1  2007-02-12 13:49:18  jorpiell
59
 * A?adido el driver de KML
60
 *
61
 *
62
 */
63
/**
64
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
65
 */
66
public class KmlParsersFactory {
67
        private WarningsContainer warnings = null;
68
        private static Hashtable supportedVersions = new Hashtable();
69
        private static Hashtable parserVersions = new Hashtable();
70
        
71
        
72
        
73
        static {
74
                supportedVersions.put("http://earth.google.com/kml/2.1",KmlFeaturesParser.class);        
75
                supportedVersions.put("http://earth.google.com/kml/2.0",KmlFeaturesParser.class);                
76
                supportedVersions.put("unknown",KmlFeaturesParser.class);                
77
        }
78
        
79
        public IFeaturesParser createParser(String nameSpace, IGeometriesFactory factory, IReaderFile reader) throws BaseException{
80
                Class clazz = (Class) supportedVersions.get(nameSpace);
81
                if (clazz == null){
82
                        clazz = (Class) supportedVersions.get("unknown");
83
                        //WARNING VERSION NOT SUPPORTED OR NOT SPECIFIED
84
                        warnings.setElement(new NotNamespaceParserWarning(nameSpace));
85
                }
86
                if (clazz != null){
87
                        //Utilizamos un interfaz con los tipos y las geometrias b?sicas de GML
88
                        //?Otra opcion seria parsear el schemas de opengis, para obtener los tipos b?sicos?
89
                        Class [] args = {IReaderFile.class,IGeometriesFactory.class};
90
                        Object [] params = {reader,factory};
91
                        //pasamos el parser con el que estamos leyendo el gml y el interfaz de geometrias
92
                        //para continuar con la comprobaci?n del fichero GML
93
                        try {
94
                                return (AbstractFeaturesParser)clazz.getConstructor(args).newInstance(params);
95
                        } catch (Exception e) {
96
                                throw new KmlImpossibleCreateParser(nameSpace,e);
97
                        }
98
                }
99
                return null ;                
100
        }
101
        
102
        
103
}