Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
EasyBeans Copyright (C) 2009 Bull S.A.S. Contact: easybeans@ow2.org This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------- $Id: BundleArchive.java 3603 2008-07-04 15:43:00Z gaellalire $ --------------------------------------------------------------------------
 

Copyright (c) 1998, 2008 Oracle. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 which accompanies this distribution. The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php. Contributors: Oracle - initial API and implementation from Oracle TopLink /
 
 package org.eclipse.persistence.internal.jpa.deployment;
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
This is an implementation of 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(s):
Sanjeeb.Sahoo@Sun.COM
 
 public class DirectoryArchive implements Archive {
     /*
      * Implementation Note: This class does not have any dependency on TopLink
      * or GlassFish implementation classes. Please retain this searation.
      */

    
The directory this archive represents.
 
     private File directory;

    
The URL representation of this archive.
 
     private URL rootURL;

    
The file entries that this archive contains.
 
     private List<Stringentries = new ArrayList<String>();
 
     private Logger logger;
 
     public DirectoryArchive(File directorythrows MalformedURLException {
         this(directory.);
     }
 
     public DirectoryArchive(File directoryLogger logger)
             throws MalformedURLException {
         logger.entering("DirectoryArchive""DirectoryArchive",
                         new Object[]{directory});
         this. = 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.toURI().toURL();
        logger.logp(."DirectoryArchive""DirectoryArchive",
                "rootURL = {0}");
        init(this.this.); // initialize entries
    }
    private void init(File topFile 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(."/"// NOI18N
                    .substring(top.getPath().length() + 1);
            if (isWar() && entryName.endsWith(".class")) {
                if (entryName.startsWith()) {
                    entryName = entryName.substring(.length() + 1);
                }
            }
            .add(entryName);
        }
        File[] subDirs = directory.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        for (File subDir : subDirs) {
            init(topsubDir); // recursion
        }
    }
    public Iterator<StringgetEntries() {
        return .iterator();
    }
    public InputStream getEntry(String entryPaththrows IOException {
        File f = getFile(entryPath);
        InputStream is = f.exists() ? new FileInputStream(f) : null;
        return is;
    }
    public URL getEntryAsURL(String entryPaththrows IOException {
        File f = getFile(entryPath);
        URL url = f.exists() ? f.toURI().toURL() : null;
        return url;
    }
    public URL getRootURL() {
        return ;
    }
    private File getFile(String entryPath) {
        if (isWar() && entryPath.endsWith(".class")) {
            entryPath =  + entryPath;
        }
        File f = new File(entryPath);
        return f;
    }
    private static final String WEBINF_CLASSES = "WEB-INF/classes";
    private boolean isWar() {
        return .getName().endsWith(".war");
    }
New to GrepCode? Check out our FAQ X