00001 00026 package org.objectweb.jonas_lib.loader.locator; 00027 00028 import java.io.IOException; 00029 import java.net.URL; 00030 import java.util.Enumeration; 00031 import java.util.List; 00032 import java.util.Vector; 00033 import java.util.jar.JarFile; 00034 import java.util.zip.ZipEntry; 00035 00042 public class JarFileLocator extends Locator { 00043 00047 private JarFile file = null; 00048 00056 public JarFileLocator(URL jar) throws IOException { 00057 String filename = jar.getFile(); 00058 file = new JarFile(filename); 00059 } 00060 00068 public boolean hasFile(String path) { 00069 00070 ZipEntry entry = file.getEntry(path); 00071 return (entry != null); 00072 } 00073 00081 public boolean hasDirectory(String path) { 00082 00083 boolean found = false; 00084 for (Enumeration e = file.entries(); e.hasMoreElements() && !found;) { 00085 ZipEntry entry = (ZipEntry) e.nextElement(); 00086 if (entry.getName().startsWith(path)) { 00087 return true; 00088 } 00089 } 00090 00091 return false; 00092 } 00093 00101 public List listContent(String path) { 00102 00103 List libs = new Vector(); 00104 for (Enumeration e = file.entries(); e.hasMoreElements();) { 00105 ZipEntry entry = (ZipEntry) e.nextElement(); 00106 if (entry.getName().startsWith(path)) { 00107 libs.add(entry.getName()); 00108 } 00109 } 00110 00111 return libs; 00112 } 00113 00114 }