root / trunk / libraries / libGPE / src / org / gvsig / gpe / GPERegister.java @ 11265
History | View | Annotate | Download (7 KB)
1 |
package org.gvsig.gpe; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.Hashtable; |
6 |
import java.util.Iterator; |
7 |
|
8 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
9 |
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*/
|
50 |
/* CVS MESSAGES:
|
51 |
*
|
52 |
* $Id: GPERegister.java 11265 2007-04-19 11:56:03Z csanchez $
|
53 |
* $Log$
|
54 |
* Revision 1.10 2007-04-19 11:50:20 csanchez
|
55 |
* Actualizacion protoripo libGPE
|
56 |
*
|
57 |
* Revision 1.9 2007/04/19 07:23:20 jorpiell
|
58 |
* Add the add methods to teh contenhandler and change the register mode
|
59 |
*
|
60 |
* Revision 1.8 2007/04/18 12:54:45 csanchez
|
61 |
* Actualizacion protoripo libGPE
|
62 |
*
|
63 |
* Revision 1.7 2007/04/17 07:53:55 jorpiell
|
64 |
* Before to start a new parsing process, the initialize method of the content handlers is throwed
|
65 |
*
|
66 |
* Revision 1.6 2007/04/17 06:26:54 jorpiell
|
67 |
* Fixed one problem with a index
|
68 |
*
|
69 |
* Revision 1.5 2007/04/14 16:06:13 jorpiell
|
70 |
* The writer handler has been updated
|
71 |
*
|
72 |
* Revision 1.4 2007/04/12 17:06:42 jorpiell
|
73 |
* First GML writing tests
|
74 |
*
|
75 |
* Revision 1.3 2007/04/11 11:10:27 jorpiell
|
76 |
* Cambiado el nombre de getDriver a GetParser
|
77 |
*
|
78 |
* Revision 1.2 2007/04/11 08:54:24 jorpiell
|
79 |
* A?adidos algunos comentarios
|
80 |
*
|
81 |
* Revision 1.1 2007/04/11 08:52:55 jorpiell
|
82 |
* Se puede registrar una clase por nombre
|
83 |
*
|
84 |
* Revision 1.1 2007/04/11 08:22:41 jorpiell
|
85 |
* GPE clase para registrar los drivers
|
86 |
*
|
87 |
*
|
88 |
*/
|
89 |
/**
|
90 |
* This class is used to register the GPE parsers. All the
|
91 |
* parsers must be registered in this class before to be
|
92 |
* used for the consumer application
|
93 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
94 |
*/
|
95 |
public class GPERegister { |
96 |
private static Hashtable parsers = new Hashtable(); |
97 |
private static Hashtable writers = new Hashtable(); |
98 |
|
99 |
/**
|
100 |
* Adds a new GPE parser
|
101 |
* @param name
|
102 |
* Driver name. It must be written like FORMAT VERSION
|
103 |
* @param description
|
104 |
* Driver description. Just a descriptive text
|
105 |
* @param clazz
|
106 |
* The parser class
|
107 |
* @throws NoSuchMethodException
|
108 |
* @throws InvocationTargetException
|
109 |
* @throws IllegalAccessException
|
110 |
* @throws InstantiationException
|
111 |
* @throws SecurityException
|
112 |
* @throws IllegalArgumentException
|
113 |
*/
|
114 |
public static void addGpeParser(String name, String description,Class clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
115 |
if (clazz != null){ |
116 |
GPEParser parser = (GPEParser)clazz.getConstructor(null).newInstance(null); |
117 |
parsers.put(name, parser); |
118 |
} |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Adds a new GPEWriterHandler
|
123 |
* @param name
|
124 |
* Driver name. It must be written like FORMAT VERSION
|
125 |
* @param description
|
126 |
* Driver description. Just a descriptive text
|
127 |
* @param clazz
|
128 |
* The parser class
|
129 |
* @throws NoSuchMethodException
|
130 |
* @throws InvocationTargetException
|
131 |
* @throws IllegalAccessException
|
132 |
* @throws InstantiationException
|
133 |
* @throws SecurityException
|
134 |
* @throws IllegalArgumentException
|
135 |
*/
|
136 |
public static void addGpeWriterHandler(String name, String description,Class clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
137 |
if (clazz != null){ |
138 |
GPEWriterHandler parser = (GPEWriterHandler)clazz.getConstructor(null).newInstance(null); |
139 |
writers.put(name, parser); |
140 |
} |
141 |
} |
142 |
|
143 |
/**
|
144 |
* Create a new parser from a name
|
145 |
* @param name
|
146 |
* @param contenHandler
|
147 |
* @param errorHandler
|
148 |
* @throws NoSuchMethodException
|
149 |
* @throws InvocationTargetException
|
150 |
* @throws IllegalAccessException
|
151 |
* @throws InstantiationException
|
152 |
* @throws SecurityException
|
153 |
* @throws IllegalArgumentException
|
154 |
* @return
|
155 |
* Null if the parser doesn't exist
|
156 |
*/
|
157 |
public static GPEParser createParser(String name) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
158 |
Object parser = parsers.get(name);
|
159 |
if (parser != null){ |
160 |
return (GPEParser)parser.getClass().getConstructor(null).newInstance(null); |
161 |
} |
162 |
return null; |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Gets the parser that can open the file (if it exists)
|
167 |
* @param file
|
168 |
* File to open
|
169 |
* @return
|
170 |
* Null if the driver doesn't exist
|
171 |
* @throws NoSuchMethodException
|
172 |
* @throws InvocationTargetException
|
173 |
* @throws IllegalAccessException
|
174 |
* @throws InstantiationException
|
175 |
* @throws SecurityException
|
176 |
* @throws IllegalArgumentException
|
177 |
*/
|
178 |
public static GPEParser createParser(File file) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
179 |
Iterator keys = parsers.keySet().iterator();
|
180 |
while (keys.hasNext()){
|
181 |
String key = (String)keys.next(); |
182 |
GPEParser parser = (GPEParser)parsers.get(key); |
183 |
if (parser.accept(file)){
|
184 |
return createParser(key);
|
185 |
} |
186 |
} |
187 |
return null; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Create a new content writer from a name
|
192 |
* @param name
|
193 |
* @param contenHandler
|
194 |
* @param errorHandler
|
195 |
* @throws NoSuchMethodException
|
196 |
* @throws InvocationTargetException
|
197 |
* @throws IllegalAccessException
|
198 |
* @throws InstantiationException
|
199 |
* @throws SecurityException
|
200 |
* @throws IllegalArgumentException
|
201 |
*/
|
202 |
public static GPEWriterHandler createWriter(String name) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
203 |
Object writer = writers.get(name);
|
204 |
if (writer != null){ |
205 |
return (GPEWriterHandler)writer.getClass().getConstructor(null).newInstance(null); |
206 |
} |
207 |
return null; |
208 |
} |
209 |
|
210 |
|
211 |
/**
|
212 |
* Return true if exists a driver that can open the file
|
213 |
* @param file
|
214 |
* File to open
|
215 |
* @return
|
216 |
* true if the driver exists
|
217 |
*/
|
218 |
public static boolean accept(File file){ |
219 |
Iterator keys = parsers.keySet().iterator();
|
220 |
while (keys.hasNext()){
|
221 |
GPEParser parser = (GPEParser)parsers.get(keys.next()); |
222 |
if (parser.accept(file)){
|
223 |
return true; |
224 |
} |
225 |
} |
226 |
return false; |
227 |
} |
228 |
} |