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