FileDocCategorySizeDatePackage
DirectoryArchive.javaAPI DocGlassfish v2 API5449Thu Jul 26 10:51:00 BST 2007oracle.toplink.essentials.ejb.cmp3.persistence

DirectoryArchive

public class DirectoryArchive extends Object implements Archive
This is an implementation of {@link Archive} when container returns a file: url that refers to a directory that contains an exploded jar file. e.g. file:/tmp/a_ear/ejb_jar
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private File
directory
The directory this archive represents.
private URL
rootURL
The URL representation of this archive.
private List
entries
The file entries that this archive contains.
private Logger
logger
Constructors Summary
public DirectoryArchive(File directory)


         
        this(directory, Logger.global);
    
public DirectoryArchive(File directory, Logger logger)

        logger.entering("DirectoryArchive", "DirectoryArchive",
                        new Object[]{directory});
        this.logger = logger;
        if (!directory.isDirectory()) {
            // should never reach here, hence the msg is not internationalized.
            throw new IllegalArgumentException(directory +
                    " is not a directory." + // NOI18N
                    "If it is a jar file, then use JarFileArchive."); // NOI18N
        }
        this.directory = directory;
        rootURL = directory.toURI().toURL();
        logger.logp(Level.FINER, "DirectoryArchive", "DirectoryArchive",
                "rootURL = {0}", rootURL);
        init(this.directory, this.directory); // initialize entries
    
Methods Summary
public java.util.IteratorgetEntries()

        return entries.iterator();
    
public java.io.InputStreamgetEntry(java.lang.String entryPath)

        File f = getFile(entryPath);
        InputStream is = f.exists() ? new FileInputStream(f) : null;
        return is;
    
public java.net.URLgetEntryAsURL(java.lang.String entryPath)

        File f = getFile(entryPath);
        URL url = f.exists() ? f.toURI().toURL() : null;
        return url;
    
private java.io.FilegetFile(java.lang.String entryPath)

        File f = new File(directory, entryPath);
        return f;
    
public java.net.URLgetRootURL()

        return rootURL;
    
private voidinit(java.io.File top, java.io.File directory)

        File[] dirFiles = directory.listFiles();
        for (File file : dirFiles) {
            if (file.isDirectory()) {
                continue; // exclude dir entries
            }

            // add only the relative path from the top.
            // note: we use unix style path
            String entryName = file.getPath().replace(File.separator, "/") // NOI18N
                    .substring(top.getPath().length() + 1);
            entries.add(entryName);
        }
        File[] subDirs = directory.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        for (File subDir : subDirs) {
            init(top, subDir); // recursion
        }