DirLocator.java

00001 
00026 package org.objectweb.jonas_lib.loader.locator;
00027 
00028 import java.io.File;
00029 import java.io.IOException;
00030 import java.net.URL;
00031 import java.util.List;
00032 import java.util.Vector;
00033 
00040 public class DirLocator extends Locator {
00041 
00045     private File file = null;
00046 
00054     public DirLocator(URL jar) throws IOException {
00055         String filename = jar.getFile();
00056         file = new File(filename);
00057         if (!file.exists()) {
00058             throw new IOException("File " + file + " does not exists.");
00059         }
00060         if (!file.isDirectory()) {
00061             throw new IOException("File " + file + " is not a directory.");
00062         }
00063     }
00064 
00072     public boolean hasFile(String path) {
00073 
00074         File child = new File(file, path);
00075         return (child.exists() && child.isFile());
00076     }
00077 
00085     public boolean hasDirectory(String path) {
00086 
00087         File child = new File(file, path);
00088         return (child.exists() && child.isDirectory());
00089     }
00090 
00098     public List listContent(String path) {
00099 
00100         File child = new File(file, path);
00101         List libs = new Vector();
00102         // List directory content
00103         if (child.isDirectory()) {
00104             addContent(child, libs);
00105         }
00106 
00107         return libs;
00108     }
00109 
00117     private void addContent(File f, List l) {
00118         File[] childs = f.listFiles();
00119         if (childs != null) {
00120             for (int i = 0; i < childs.length; i++) {
00121                 if (childs[i].isDirectory()) {
00122                     addContent(childs[i], l);
00123                 } else if (childs[i].isFile()) {
00124                     l.add(childs[i].getPath().substring(file.getPath().length()));
00125                 }
00126             }
00127         }
00128     }
00129 
00130 }

Generated on Tue Feb 15 15:05:55 2005 for JOnAS by  doxygen 1.3.9.1