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