Revision 14134 trunk/libraries/libRaster/src/org/gvsig/raster/RasterLibrary.java
RasterLibrary.java | ||
---|---|---|
19 | 19 |
package org.gvsig.raster; |
20 | 20 |
|
21 | 21 |
import java.io.File; |
22 |
import java.io.FileFilter; |
|
23 |
import java.io.IOException; |
|
24 |
import java.net.MalformedURLException; |
|
25 |
import java.net.URL; |
|
22 | 26 |
import java.util.ArrayList; |
27 |
import java.util.Enumeration; |
|
28 |
import java.util.Hashtable; |
|
29 |
import java.util.jar.JarException; |
|
30 |
import java.util.zip.ZipEntry; |
|
31 |
import java.util.zip.ZipException; |
|
32 |
import java.util.zip.ZipFile; |
|
23 | 33 |
|
34 |
import org.apache.log4j.Logger; |
|
24 | 35 |
import org.gvsig.raster.dataset.io.ErmapperDriver; |
25 | 36 |
import org.gvsig.raster.dataset.io.ErmapperWriter; |
26 | 37 |
import org.gvsig.raster.dataset.io.GdalDriver; |
... | ... | |
105 | 116 |
* otros ya existentes. Estos pueden ser drivers o filtros. |
106 | 117 |
*/ |
107 | 118 |
public static String[] pathExtensions = {"./"}; |
119 |
|
|
120 |
private static Hashtable clasesJar = new Hashtable(); |
|
121 |
|
|
108 | 122 |
/** |
109 | 123 |
* Ejecuta las acciones necesarias para arrancar la librer?a. |
110 | 124 |
*/ |
... | ... | |
144 | 158 |
StatisticsListManager.register(); |
145 | 159 |
PanSharpeningListManager.register(); |
146 | 160 |
// Registrar los nuevos filtros del directorio |
147 |
registerExtensions();
|
|
161 |
//registerClasses();
|
|
148 | 162 |
|
149 | 163 |
//Limpiamos el directorio temporal |
150 | 164 |
RasterLibrary.cleanUpTempFiles(); |
... | ... | |
190 | 204 |
* registrar? todos las clases registrables. En este momento hay posibilidad |
191 | 205 |
* de registro de drivers y filtros. |
192 | 206 |
*/ |
193 |
private static void registerExtensions() { |
|
207 |
private static void registerClasses() throws Exception { |
|
208 |
RasterClassLoader loader = new RasterClassLoader(); |
|
209 |
|
|
210 |
//Cargamos sobre jarList todos los File correspondientes a los jar contenidos en pathExtensions |
|
211 |
File[] jarList = null; |
|
194 | 212 |
for (int iPath = 0; iPath < pathExtensions.length; iPath++) { |
195 |
File files = new File(pathExtensions[iPath]); |
|
196 |
if (files.isDirectory()) { |
|
197 |
// TODO:FUNCIONALIDAD: Descubrimiento de drivers y filtros registrables. |
|
213 |
File directory = new File(pathExtensions[iPath]); |
|
214 |
if (directory.isDirectory() && directory.canRead()) { |
|
215 |
jarList = directory.listFiles(new FileFilter() { |
|
216 |
public boolean accept(File pathname) { |
|
217 |
return (pathname.getName().toUpperCase().endsWith(".JAR")); |
|
218 |
} |
|
219 |
}); |
|
198 | 220 |
} |
199 | 221 |
} |
222 |
|
|
223 |
//Creamos las URL |
|
224 |
URL[] urls = new URL[jarList.length]; |
|
225 |
|
|
226 |
for (int j = 0; j < jarList.length; j++) { |
|
227 |
try { |
|
228 |
urls[j] = new URL("file:" + jarList[j]); |
|
229 |
} catch (MalformedURLException e) { |
|
230 |
Logger.getLogger(RasterLibrary.class.getName()).debug("Error formando la URL, jar incorrecto", e); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
//Comprobamos que no haya clases repetidas |
|
235 |
ZipFile[] jarFiles = new ZipFile[jarList.length]; |
|
236 |
for (int i = 0; i < jarList.length; i++) { |
|
237 |
try { |
|
238 |
jarFiles[i] = new ZipFile(jarList[i].getPath()); |
|
239 |
|
|
240 |
Enumeration entradas = jarFiles[i].entries(); |
|
241 |
|
|
242 |
while (entradas.hasMoreElements()) { |
|
243 |
ZipEntry file = (ZipEntry) entradas.nextElement(); |
|
244 |
String fileName = file.getName(); |
|
245 |
|
|
246 |
if (!fileName.toLowerCase().endsWith(".class")) |
|
247 |
continue; |
|
248 |
|
|
249 |
fileName = fileName.substring(0, fileName.length() - 6).replace('/', '.'); |
|
250 |
|
|
251 |
if (clasesJar.get(fileName) != null) { |
|
252 |
throw new JarException("CLASES REPETIDAS: " + fileName + " " + " en " + |
|
253 |
jarFiles[i].getName() + " y en " + ((ZipFile) clasesJar.get(fileName)).getName()); |
|
254 |
} |
|
255 |
|
|
256 |
clasesJar.put(fileName, jarFiles[i]); |
|
257 |
} |
|
258 |
} catch (ZipException e) { |
|
259 |
throw new IOException(" Jar: " + jarList[i].getPath() + ": " + jarFiles[i]); |
|
260 |
} catch (IOException e) { |
|
261 |
throw e; |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
200 | 265 |
} |
201 | 266 |
} |
Also available in: Unified diff