svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / KmlParsersFactory.java @ 11157
History | View | Annotate | Download (3.62 KB)
1 | 10637 | jorpiell | package org.gvsig.gpe.kml; |
---|---|---|---|
2 | |||
3 | import java.util.Hashtable; |
||
4 | |||
5 | import org.gvsig.exceptions.BaseException; |
||
6 | import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
||
7 | import org.gvsig.gpe.kml.engine.AbstractFeaturesParser; |
||
8 | import org.gvsig.gpe.kml.engine.IFeaturesParser; |
||
9 | import org.gvsig.gpe.kml.engine.IReaderFile; |
||
10 | import org.gvsig.gpe.kml.exceptions.KmlImpossibleCreateParser; |
||
11 | 11157 | jorpiell | import org.gvsig.gpe.kml.warnings.NotNamespaceParserWarning; |
12 | import org.gvsig.gpe.kml.warnings.WarningsContainer; |
||
13 | 10637 | jorpiell | |
14 | |||
15 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
16 | *
|
||
17 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
18 | *
|
||
19 | * This program is free software; you can redistribute it and/or
|
||
20 | * modify it under the terms of the GNU General Public License
|
||
21 | * as published by the Free Software Foundation; either version 2
|
||
22 | * of the License, or (at your option) any later version.
|
||
23 | *
|
||
24 | * This program is distributed in the hope that it will be useful,
|
||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
27 | * GNU General Public License for more details.
|
||
28 | *
|
||
29 | * You should have received a copy of the GNU General Public License
|
||
30 | * along with this program; if not, write to the Free Software
|
||
31 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
32 | *
|
||
33 | * For more information, contact:
|
||
34 | *
|
||
35 | * Generalitat Valenciana
|
||
36 | * Conselleria d'Infraestructures i Transport
|
||
37 | * Av. Blasco Ib??ez, 50
|
||
38 | * 46010 VALENCIA
|
||
39 | * SPAIN
|
||
40 | *
|
||
41 | * +34 963862235
|
||
42 | * gvsig@gva.es
|
||
43 | * www.gvsig.gva.es
|
||
44 | *
|
||
45 | * or
|
||
46 | *
|
||
47 | * IVER T.I. S.A
|
||
48 | * Salamanca 50
|
||
49 | * 46005 Valencia
|
||
50 | * Spain
|
||
51 | *
|
||
52 | * +34 963163400
|
||
53 | * dac@iver.es
|
||
54 | */
|
||
55 | /* CVS MESSAGES:
|
||
56 | *
|
||
57 | * $Id$
|
||
58 | * $Log$
|
||
59 | 11157 | jorpiell | * Revision 1.2 2007-04-12 10:21:52 jorpiell
|
60 | * Add the writers
|
||
61 | *
|
||
62 | * Revision 1.1 2007/03/07 08:19:10 jorpiell
|
||
63 | 10637 | jorpiell | * Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
64 | *
|
||
65 | * Revision 1.1 2007/02/28 11:48:31 csanchez
|
||
66 | * *** empty log message ***
|
||
67 | *
|
||
68 | * Revision 1.1 2007/02/20 10:53:20 jorpiell
|
||
69 | * A?adidos los proyectos de kml y gml antiguos
|
||
70 | *
|
||
71 | * Revision 1.1 2007/02/12 13:49:18 jorpiell
|
||
72 | * A?adido el driver de KML
|
||
73 | *
|
||
74 | *
|
||
75 | */
|
||
76 | /**
|
||
77 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
78 | */
|
||
79 | public class KmlParsersFactory { |
||
80 | private WarningsContainer warnings = null; |
||
81 | private static Hashtable supportedVersions = new Hashtable(); |
||
82 | private static Hashtable parserVersions = new Hashtable(); |
||
83 | |||
84 | |||
85 | |||
86 | static {
|
||
87 | supportedVersions.put("http://earth.google.com/kml/2.1",KmlFeaturesParser.class);
|
||
88 | supportedVersions.put("http://earth.google.com/kml/2.0",KmlFeaturesParser.class);
|
||
89 | supportedVersions.put("unknown",KmlFeaturesParser.class);
|
||
90 | } |
||
91 | |||
92 | public IFeaturesParser createParser(String nameSpace, IGeometriesFactory factory, IReaderFile reader) throws BaseException{ |
||
93 | Class clazz = (Class) supportedVersions.get(nameSpace); |
||
94 | if (clazz == null){ |
||
95 | clazz = (Class) supportedVersions.get("unknown"); |
||
96 | //WARNING VERSION NOT SUPPORTED OR NOT SPECIFIED
|
||
97 | warnings.setElement(new NotNamespaceParserWarning(nameSpace));
|
||
98 | } |
||
99 | if (clazz != null){ |
||
100 | //Utilizamos un interfaz con los tipos y las geometrias b?sicas de GML
|
||
101 | //?Otra opcion seria parsear el schemas de opengis, para obtener los tipos b?sicos?
|
||
102 | Class [] args = {IReaderFile.class,IGeometriesFactory.class}; |
||
103 | Object [] params = {reader,factory}; |
||
104 | //pasamos el parser con el que estamos leyendo el gml y el interfaz de geometrias
|
||
105 | //para continuar con la comprobaci?n del fichero GML
|
||
106 | try {
|
||
107 | return (AbstractFeaturesParser)clazz.getConstructor(args).newInstance(params);
|
||
108 | } catch (Exception e) { |
||
109 | throw new KmlImpossibleCreateParser(nameSpace,e); |
||
110 | } |
||
111 | } |
||
112 | return null ; |
||
113 | } |
||
114 | |||
115 | |||
116 | } |