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

ArchiveFactory

public class ArchiveFactory extends Object implements AbstractArchiveFactory
This implementation of the AbstractArchiveFactory interface is capable of creating the right abstraction of the Archive interface depending on the protocol used in the URL.
author
Jerome Dochez

Fields Summary
Constructors Summary
public ArchiveFactory()
Creates a new instance of ArchiveFactory

    
Methods Summary
public AbstractArchivecreateArchive(java.lang.String path)

        try {
            /*
             *Use the expanded constructor so illegal characters (such as embedded blanks) in the path 
             *will be encoded.
             */
            return createArchive(prepareArchiveURI(path));
        } catch(java.net.URISyntaxException e) {
            return null;
        }
    
public AbstractArchivecreateArchive(java.net.URI path)
Creates a new archivist using the URL as the path. The URL protocol will define the type of desired archive (jar, file, etc)

param
url to the archive
return
the apropriate archive

        
        String protocol = path.getScheme();
        if (protocol.equals("file")) {
            FileArchive output = new FileArchive();
            output.create(path.getPath());        
            return output;             
        } else 
        if (protocol.equals("jar")) {
            OutputJarArchive ja =  new OutputJarArchive();
            ja.create(path.getPath());
            return ja;            
        } else 
        throw new MalformedURLException("Protocol not supported : " + protocol);        
    
public AbstractArchiveopenArchive(java.lang.String path)

        try {
            return openArchive(prepareArchiveURI(path));
        } catch(java.net.URISyntaxException e) {
            return null;
        }
    
public AbstractArchiveopenArchive(java.net.URI path)
Opens an existing archivist using the URL as the path. The URL protocol will defines the type of desired archive (jar, file, memory, etc...)

param
url to the existing archive
return
the appropriate archive

        
        String protocol = path.getScheme();
        if (protocol.equals("file")) {
            FileArchive input = new FileArchive();
            input.open(path.getPath());        
            return input;            
        } else 
        if (protocol.equals("jar")) {
            InputJarArchive ja = new InputJarArchive();
            ja.open(path.getPath());
            return ja;           
        } else
/*        if (protocol.equals("mem")) {
            MemoryMappedArchive mapped = new MemoryMappedArchive();
            mapped.open(path.getPath());
            return mapped;            
        }*/
        throw new MalformedURLException("Protocol not supported : " + protocol);    
    
static java.net.URIprepareArchiveURI(java.lang.String path)
Create a URI for the jar specified by the path string.

The steps used here correctly encode "illegal" characters - such as embedded blanks - in the path string that otherwise would render the URI unusable. The URI constructor that accepts just the path string does not perform this encoding.

param
path string for the archive
return
URI with any necessary encoding of special characters

       
        File archiveFile = new File(path);
        URI archiveURI = archiveFile.toURI();
        String scheme = (archiveFile.isDirectory() ? "file" : "jar");
        URI answer = new URI(scheme, null /* authority */, archiveURI.getPath(), null /* query */, null /* fragment */);
        return answer;