Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / KmlParsersFactory.java @ 18284

History | View | Annotate | Download (3.57 KB)

1
package org.gvsig.gpe.kml.parser;
2

    
3
import java.util.Hashtable;
4

    
5
import org.gvsig.exceptions.BaseException;
6
import org.gvsig.gpe.kml.GPEDeafultKmlParser;
7
import org.gvsig.gpe.kml.KmlTags;
8
import org.gvsig.gpe.kml.exceptions.KmlImpossibleCreateParser;
9
import org.xmlpull.v1.XmlPullParser;
10

    
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: KmlParsersFactory.java 366 2008-01-10 09:09:38Z jpiera $
55
 * $Log$
56
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
57
 * Refactoring of some package names
58
 *
59
 * Revision 1.3  2007/05/08 09:28:17  jorpiell
60
 * Add comments to create javadocs
61
 *
62
 * Revision 1.2  2007/05/02 11:46:50  jorpiell
63
 * Writing tests updated
64
 *
65
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
66
 * Add KML reading support
67
 *
68
 * Revision 1.2  2007/04/12 10:21:52  jorpiell
69
 * Add the writers
70
 *
71
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
72
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
73
 *
74
 * Revision 1.1  2007/02/28 11:48:31  csanchez
75
 * *** empty log message ***
76
 *
77
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
78
 * A?adidos los proyectos de kml y gml antiguos
79
 *
80
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
81
 * A?adido el driver de KML
82
 *
83
 *
84
 */
85
/**
86
 * This class is used to register the differnet kml 
87
 * parsers
88
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
89
 */
90
public class KmlParsersFactory {        
91
        private static Hashtable supportedVersions = new Hashtable();        
92
        
93
        static {
94
                supportedVersions.put("http://earth.google.com/kml/2.1",KmlParserV2_1.class);        
95
                supportedVersions.put(KmlTags.UNKNOWN_VERSION,KmlParserV2_1.class);                
96
        }
97
        
98
        /**
99
         * To create a new KML parser
100
         * @param nameSpace
101
         * KML namespace used to determine the parser to use
102
         * @param parser
103
         * XML parser used to parse the XML
104
         * @param handler
105
         * GPE parser tha contains the handlers
106
         * @return
107
         * A KML parser
108
         * @throws BaseException
109
         */
110
        public AbstractKmlParser createParser(String nameSpace,XmlPullParser parser, GPEDeafultKmlParser handler) throws BaseException{
111
                Class clazz = (Class) supportedVersions.get(nameSpace);
112
                if (clazz == null){
113
                        clazz = (Class) supportedVersions.get(KmlTags.UNKNOWN_VERSION);
114
                }
115
                if (clazz != null){
116
                        Class [] args = {XmlPullParser.class,GPEDeafultKmlParser.class};
117
                        Object [] params = {parser,handler};
118
                        try {
119
                                return (AbstractKmlParser)clazz.getConstructor(args).newInstance(params);
120
                        } catch (Exception e) {
121
                                throw new KmlImpossibleCreateParser(nameSpace,e);
122
                        }
123
                }
124
                return null ;                
125
        }
126
        
127
        
128
}