FileDocCategorySizeDatePackage
DeploymentPlanArchive.javaAPI DocGlassfish v2 API9628Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.deploy.shared

DeploymentPlanArchive

public class DeploymentPlanArchive extends AbstractArchive
This AbstractArchive offers an abstraction for jsr88 deployment plan as defined for the SJES Application Server.
author
Jerome Dochez

Fields Summary
JarFile
jarFile
String
archiveUri
Vector
elements
String
subArchiveUri
Constructors Summary
public DeploymentPlanArchive()
Creates a new instance of DeploymentPlanArchive package private

    
                  
      
    
Methods Summary
public voidclose()
Closes the current jar file

        if (jarFile!=null) {
            jarFile.close();
            jarFile=null;
        }
    
public voidcloseEntry()
Closes the output jar file entry

        // nothing to do
    
public voidcloseEntry(AbstractArchive sub)
Closes the output sub archive entry

       
        // nothing to do...
    
public booleandelete()
Deletes the underlying jar file

        File f = new File(archiveUri);
        if (f.exists()) {
            return FileUtils.deleteFile(f);
        }
        return false;
    
public java.util.Enumerationentries()

return
an Enumeration of entries for this archive

        // Deployment Plan are organized flatly, 
        
        if (elements==null) {
            synchronized(this) {
                elements = new Vector();
                for (Enumeration e = jarFile.entries();e.hasMoreElements();) {
                    ZipEntry ze = (ZipEntry) e.nextElement();
                    if (!ze.isDirectory() && !ze.getName().equals(
                            JarFile.MANIFEST_NAME)) {
                        elements.add(ze.getName());
                    }
                }
            }
        }

        Vector entries = new Vector();
        for (Enumeration e = elements.elements();e.hasMoreElements();) {
            
            String entryName = (String) e.nextElement();
            
            String mangledName = entryName;
            String prefix = "META-INF/";
            if (entryName.indexOf("sun-web.xml")!=-1) {
                prefix = "WEB-INF/";
            }  
            if (subArchiveUri != null && entryName.startsWith(subArchiveUri)) {
                mangledName = mangledName.substring(subArchiveUri.length()+1);
            }
            if (entryName.endsWith(".dbschema")) {
                mangledName = mangledName.replaceAll("#", "/");
            } else {
                mangledName = prefix + mangledName;
            }
            
            if (subArchiveUri==null) {
                // top level archive
                if ((entryName.indexOf(".jar.")!=-1) || 
                    (entryName.indexOf(".war.")!=-1) || 
                    (entryName.indexOf(".rar."))!=-1) {
                    
                    // this element is in a sub archive
                    continue;
                }
                entries.add(mangledName);            
            } else {
                // this is a sub archive
                if (entryName.startsWith(subArchiveUri)) {
                    entries.add(mangledName);
                }
            }             
        } 
        return entries.elements();
    
public java.util.Enumerationentries(java.util.Enumeration embeddedArchives)

return
an Enumeration of entries not including entries from the subarchives

        return entries();
    
public booleanexists()

return
true if the underlying archive exists

        File f = new File(archiveUri);
        return f.exists();
    
public longgetArchiveSize()
Get the size of the archive

return
tje the size of this archive or -1 on error

        if(getArchiveUri() == null) {
            return -1;
        }
        File tmpFile = new File(getArchiveUri());
        return(tmpFile.length());
    
public java.lang.StringgetArchiveUri()

return
the archive URI

        return archiveUri;
    
private java.io.InputStreamgetElement(java.lang.String name)

        if (elements.contains(name)) {
            return jarFile.getInputStream(jarFile.getEntry(name));
        } else {
            return null;
        }
    
public AbstractArchivegetEmbeddedArchive(java.lang.String name)

return
a sub archive giving the name

        if (jarFile==null) {
            return null;
        }
        DeploymentPlanArchive dpArchive = new DeploymentPlanArchive();
        dpArchive.jarFile = new JarFile(archiveUri);
        dpArchive.archiveUri = archiveUri + File.separator + name;
        dpArchive.subArchiveUri = name;
        dpArchive.elements = elements;
        return dpArchive;        
    
public java.io.InputStreamgetEntry(java.lang.String name)

return
an input stream giving its entry name


        // we are just interested in the file name, not the 
        // relative path
        if (name.endsWith(".dbschema")) {
            name = name.replaceAll("/", "#");
        } else {
            name = name.substring(name.lastIndexOf('/")+1);
        }
        
        if (subArchiveUri==null) {
            // we are at the "top level"
            
            return getElement(name);
        } else {
            // we are in a sub archive...
            // now let's mangle the name...
            String mangledName = subArchiveUri + "." + 
                name;
            return getElement(mangledName);
            
        }        
    
public java.util.jar.ManifestgetManifest()

return
the manifest

        // no manifest in DeploymentPlan
        return new Manifest();
    
public java.net.URIgetURI()

return
the URI for this archive

        File f = new File(archiveUri);
        try {
            return new URI("jar://" + f.toURI().getSchemeSpecificPart());
        } catch(java.net.URISyntaxException e) {
            return null;
        }
    
public voidopen(java.lang.String path)
Open an existing DeploymentPlan archive and return a abstraction for reading from it.

param
the path to the archive

        archiveUri = path;
        File f = new File(path);
        if (f.exists()) {
            jarFile = new JarFile(f);
        }
    
public java.io.OutputStreamputNextEntry(java.lang.String name)
Add an entry to the archive

        // not supported for now.
        throw new UnsupportedOperationException();
    
public booleanrenameTo(java.lang.String name)
rename the underlying archive

        File f = new File(archiveUri);
        boolean result = FileUtils.renameFile(f, new File(name));
        if (result) {
            archiveUri = name;
        }
        return result;