FileDocCategorySizeDatePackage
PluggableArchivistsHelper.javaAPI DocGlassfish v2 API8919Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.archivist

PluggableArchivistsHelper

public class PluggableArchivistsHelper extends Object implements PluggableArchivists
author
Jerome Dochez

Fields Summary
private Archivist[]
archivists
private static com.sun.enterprise.util.i18n.StringManager
localStrings
string manager
Constructors Summary
public PluggableArchivistsHelper()
Creates a new instance of PluggableArchivistsHelper


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

return
a new Archivist implementation for the archive file type Supported J2EE modules are defined in the J2EE platform spec

        File f = new File(path);
        if (!f.exists()) {
            throw new FileNotFoundException(path);
        }
        AbstractArchive archive;
        if (f.isDirectory()) {
            archive = new FileArchive();
            ((FileArchive) archive).open(path);
        } else {
            archive = new InputJarArchive();
            ((InputJarArchive) archive).open(path);
        }
        Archivist archivist=null;
        try {            
            archivist = getArchivistForArchive(archive);
        } finally {        
            archive.close();
        }
        return archivist;        
    
public ArchivistgetArchivistForArchive(java.io.File jarFileOrDirectory)

return
a new Archivist implementation for the archive file type Supported J2EE modules are defined in the J2EE platform spec

        return getArchivistForArchive(jarFileOrDirectory.getAbsolutePath());        
    
public ArchivistgetArchivistForArchive(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)

return
a new Archivist implementation for the archive file type Supported J2EE modules are defined in the J2EE platform spec


        Archivist a = handles(archive);
        if (a != null) {
            try {
                Archivist archivist = (Archivist) a.getClass().newInstance();
                archivist.setPluggableArchivists(this);
                return archivist;
            } catch (Exception e) {
                DOLUtils.getDefaultLogger().log(
                Level.SEVERE, 
                "enterprise.deployment.backend.archivistInstantiationFailure",
                new Object[] {a.getClass(), archive});
                e.printStackTrace();
            }
        } else {
            String msg = localStrings.getString(
                "enterprise.deployment.unknown.application.type",
                archive.getArchiveUri());
            throw new IOException(msg);
        }
        return null;        
    
public synchronized ArchivistgetArchivistForType(javax.enterprise.deploy.shared.ModuleType type)

return
a new Archivist implementation for the type passed. Supported types are defined in the application.xml DTD

        
        for (int i=0;i<archivists.length;i++) {
            if (archivists[i].getModuleType().equals(type)) {
                try {
                    Archivist archivist = (Archivist) archivists[i].getClass().newInstance();                    
                    archivist.setPluggableArchivists(this);
                    return archivist;
                } catch (Exception  e) {
                    DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.archivistInstantiationFailure",
                                new Object[] {archivists[i].getClass(), type});                    
                    e.printStackTrace();
                }
            }
        }
        DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.archivistInstantiationFailure",
                                new Object[] {null, type});                    
        return null;                
    
public Archivist[]getRegisteredArchivists()

return
the array of registered archivists

        Archivist[] newArchivists = new Archivist[archivists.length+1];
        System.arraycopy(archivists, 0, newArchivists, 0, archivists.length);
        return newArchivists;        
    
private synchronized Archivisthandles(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)


        //first, check the existence of any deployment descriptors
        for (Archivist a : archivists) {
            if (a.hasStandardDeploymentDescriptor(archive) || 
                    a.hasRuntimeDeploymentDescriptor(archive)) {
                return a;
            }
        }

        // Java EE 5 Specification: Section EE.8.4.2.1

        //second, check file extension if any, excluding .jar as it needs
        //additional processing
        String uri = archive.getArchiveUri();
        File file = new File(uri);
        if (!file.isDirectory() && !uri.endsWith(Archivist.EJB_EXTENSION)) {
            for (Archivist a : archivists) {
                if (uri.endsWith(a.getArchiveExtension())) {
                    return a;
                }
            }
        }

        //finally, still not returned here, call for additional processing
        for (Archivist a : archivists) {
            if (a.postHandles(archive)) {
                return a;
            }
        }

        return null;
    
public synchronized voidregisterArchivist(Archivist archivist)
register a new type of archivist

param
Archivist to register...

        for (int i=0;i<archivists.length;i++) {
            if (archivists[i].getModuleType().equals(archivist.getModuleType())) {        
                // we are replacing an archivist
                archivists[i]=archivist;
                return;
            }
        }
        // if we end up here, it's a new archvist for a new type of archive...
        Archivist[] newArchivists = new Archivist[archivists.length+1];
        System.arraycopy(archivists, 0, newArchivists, 0, archivists.length);
        newArchivists[archivists.length]=archivist;
        archivists = newArchivists;