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