svn-gvsig-desktop / trunk / libraries / libGPE / src / org / gvsig / gpe / GPERegister.java @ 11213
History | View | Annotate | Download (4.66 KB)
1 |
package org.gvsig.gpe; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
8 |
|
9 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
10 |
*
|
11 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
12 |
*
|
13 |
* This program is free software; you can redistribute it and/or
|
14 |
* modify it under the terms of the GNU General Public License
|
15 |
* as published by the Free Software Foundation; either version 2
|
16 |
* of the License, or (at your option) any later version.
|
17 |
*
|
18 |
* This program is distributed in the hope that it will be useful,
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
* GNU General Public License for more details.
|
22 |
*
|
23 |
* You should have received a copy of the GNU General Public License
|
24 |
* along with this program; if not, write to the Free Software
|
25 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
26 |
*
|
27 |
* For more information, contact:
|
28 |
*
|
29 |
* Generalitat Valenciana
|
30 |
* Conselleria d'Infraestructures i Transport
|
31 |
* Av. Blasco Ib??ez, 50
|
32 |
* 46010 VALENCIA
|
33 |
* SPAIN
|
34 |
*
|
35 |
* +34 963862235
|
36 |
* gvsig@gva.es
|
37 |
* www.gvsig.gva.es
|
38 |
*
|
39 |
* or
|
40 |
*
|
41 |
* IVER T.I. S.A
|
42 |
* Salamanca 50
|
43 |
* 46005 Valencia
|
44 |
* Spain
|
45 |
*
|
46 |
* +34 963163400
|
47 |
* dac@iver.es
|
48 |
*/
|
49 |
/* CVS MESSAGES:
|
50 |
*
|
51 |
* $Id: GPERegister.java 11213 2007-04-17 06:26:54Z jorpiell $
|
52 |
* $Log$
|
53 |
* Revision 1.6 2007-04-17 06:26:54 jorpiell
|
54 |
* Fixed one problem with a index
|
55 |
*
|
56 |
* Revision 1.5 2007/04/14 16:06:13 jorpiell
|
57 |
* The writer handler has been updated
|
58 |
*
|
59 |
* Revision 1.4 2007/04/12 17:06:42 jorpiell
|
60 |
* First GML writing tests
|
61 |
*
|
62 |
* Revision 1.3 2007/04/11 11:10:27 jorpiell
|
63 |
* Cambiado el nombre de getDriver a GetParser
|
64 |
*
|
65 |
* Revision 1.2 2007/04/11 08:54:24 jorpiell
|
66 |
* A?adidos algunos comentarios
|
67 |
*
|
68 |
* Revision 1.1 2007/04/11 08:52:55 jorpiell
|
69 |
* Se puede registrar una clase por nombre
|
70 |
*
|
71 |
* Revision 1.1 2007/04/11 08:22:41 jorpiell
|
72 |
* GPE clase para registrar los drivers
|
73 |
*
|
74 |
*
|
75 |
*/
|
76 |
/**
|
77 |
* This class is used to register the GPE parsers. All the
|
78 |
* parsers must be registered in this class before to be
|
79 |
* used for the consumer application
|
80 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
81 |
*/
|
82 |
public class GPERegister { |
83 |
private static ArrayList parsers = new ArrayList(); |
84 |
|
85 |
/**
|
86 |
* Adds a new GPE parser
|
87 |
* @param driver
|
88 |
*/
|
89 |
public static void addGpeDriver(GPEParser parser){ |
90 |
parsers.add(parser); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Adds a new GPE parser
|
95 |
* @param calssName
|
96 |
* Class name for the GPE parser
|
97 |
* @param contentHandler
|
98 |
* Consummer content handler
|
99 |
* @param errorsHanlder
|
100 |
* Consumer errorsHandler
|
101 |
* @throws ClassNotFoundException
|
102 |
* @throws NoSuchMethodException
|
103 |
* @throws InvocationTargetException
|
104 |
* @throws IllegalAccessException
|
105 |
* @throws InstantiationException
|
106 |
* @throws SecurityException
|
107 |
* @throws IllegalArgumentException
|
108 |
*/
|
109 |
public static void addGpeDriver(String className, |
110 |
GPEContentHandler contentHandler, |
111 |
GPEErrorHandler errorsHanlder) throws ClassNotFoundException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
112 |
Class [] args = {GPEContentHandler.class,GPEErrorHandler.class}; |
113 |
Object [] params = {contentHandler,errorsHanlder}; |
114 |
|
115 |
Class clazz = Class.forName(className); |
116 |
if (clazz != null){ |
117 |
GPEParser parser = (GPEParser)clazz.getConstructor(args).newInstance(params); |
118 |
parsers.add(parser); |
119 |
} |
120 |
} |
121 |
|
122 |
|
123 |
|
124 |
/**
|
125 |
* Return true if exists a driver that can open the file
|
126 |
* @param file
|
127 |
* File to open
|
128 |
* @return
|
129 |
* true if the driver exists
|
130 |
*/
|
131 |
public static boolean accept(File file){ |
132 |
for (int i=0 ; i<parsers.size() ; i++){ |
133 |
GPEParser parser = (GPEParser)parsers.get(i); |
134 |
if (parser.accept(file)){
|
135 |
return true; |
136 |
} |
137 |
} |
138 |
return false; |
139 |
} |
140 |
|
141 |
/**
|
142 |
* Gets the parser that can open the file (if it exists)
|
143 |
* @param file
|
144 |
* File to open
|
145 |
* @return
|
146 |
* Null if the driver doesn't exist
|
147 |
*/
|
148 |
public static GPEParser getParser(File file){ |
149 |
for (int i=0 ; i<parsers.size() ; i++){ |
150 |
GPEParser parser = (GPEParser)parsers.get(i); |
151 |
if (parser.accept(file)){
|
152 |
return parser;
|
153 |
} |
154 |
} |
155 |
return null; |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Gets the writer that is used to write the file
|
160 |
* @param format
|
161 |
* File format
|
162 |
* @return
|
163 |
* Null if the writer doesn't exist
|
164 |
*/
|
165 |
public static GPEWriterHandler getWriter(String format){ |
166 |
for (int i=0 ; i<parsers.size() ; i++){ |
167 |
GPEParser parser = (GPEParser)parsers.get(i); |
168 |
String[] formats = parser.getFormats(); |
169 |
for (int j=0 ; j<formats.length ; j++){ |
170 |
if (formats[j].toUpperCase().equals(format.toUpperCase())){
|
171 |
return parser.getWriter(format);
|
172 |
} |
173 |
} |
174 |
} |
175 |
return null; |
176 |
} |
177 |
|
178 |
} |