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

WebArchivist

public class WebArchivist extends Archivist
This module is responsible for reading and write web applications archive files (war).
author
Jerome Dochez
version

Fields Summary
private com.sun.enterprise.deployment.WebBundleDescriptor
descriptor
com.sun.enterprise.deployment.io.DeploymentDescriptorFile
standardDD
The DeploymentDescriptorFile handlers we are delegating for XML i/o
Constructors Summary
public WebArchivist()
Creates new WebArchivist

    

        
      
    
Methods Summary
protected java.lang.StringgetArchiveExtension()

        return WEB_EXTENSION;
    
public com.sun.enterprise.deployment.io.DeploymentDescriptorFilegetConfigurationDDFile()

return
if exists the DeploymentDescriptorFile responsible for handling the configuration deployment descriptors

        return new WebRuntimeDDFile();
    
public com.sun.enterprise.deployment.DescriptorgetDefaultBundleDescriptor()

return
a default BundleDescriptor for this archivist

        WebBundleDescriptor webBundleDesc =
            DOLLoadingContextFactory.getDefaultWebBundleDescriptor();
        return webBundleDesc;
    
public com.sun.enterprise.deployment.DescriptorgetDescriptor()

return
the Descriptor for this archvist

        return descriptor;
    
public java.util.VectorgetLibraries(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)

return
a list of libraries included in the archivist

        
        Enumeration<String> entries = archive.entries();
        if (entries==null)
            return null;
        
        Vector libs = new Vector();        
        while (entries.hasMoreElements()) {
            
            String entryName = entries.nextElement();
            if (!entryName.startsWith("WEB-INF/lib")) {
                continue; // not in WEB-INF...
            }
            if (entryName.endsWith(".jar")) {
                libs.add(entryName);
            }            
        }
        return libs;
    
public javax.enterprise.deploy.shared.ModuleTypegetModuleType()

return
the module type handled by this archivist as defined in the application DTD

        return ModuleType.WAR;
    
public com.sun.enterprise.deployment.io.DeploymentDescriptorFilegetStandardDDFile()

return
the DeploymentDescriptorFile responsible for handling standard deployment descriptor

        return standardDD;
    
public java.lang.StringgetWebServicesDeploymentDescriptorPath()

return
the location of the web services related deployment descriptor file inside this archive or null if this archive does not support webservices implementation.

        return DescriptorConstants.WEB_WEBSERVICES_JAR_ENTRY;
    
protected booleanpostHandles(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive)
In the case of web archive, the super handles() method should be able to make a unique identification. If not, then the archive is definitely not a war.

        return false;
    
protected voidpostOpen(com.sun.enterprise.deployment.RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
perform any post deployment descriptor reading action

param
descriptor the deployment descriptor for the module
param
archive the module archive

        super.postOpen(descriptor, archive);
        WebBundleDescriptor webBundle = (WebBundleDescriptor) descriptor;
        ModuleContentValidator mdv = new ModuleContentValidator(archive);
        webBundle.visit(mdv);
    
public voidreadPersistenceDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive, com.sun.enterprise.deployment.Descriptor descriptor)

        if(logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, "WebArchivist",
                    "readPersistenceDeploymentDescriptors", "archive = {0}",
                    archive.getURI());
        }
        Map<String, Archive> subArchives = new HashMap<String, Archive>();
        Enumeration entries = archive.entries();
        final String CLASSES_DIR = "WEB-INF/classes/";
        final String LIB_DIR = "WEB-INF/lib/";
        final String JAR_EXT = ".jar";
        try {
            final String pathOfPersistenceXMLInsideClassesDir =
                    CLASSES_DIR+DescriptorConstants.PERSISTENCE_DD_ENTRY;
            while(entries.hasMoreElements()){
                final String nextEntry = String.class.cast(entries.nextElement());
                if(pathOfPersistenceXMLInsideClassesDir.equals(nextEntry)) {
                    subArchives.put(CLASSES_DIR, archive.getSubArchive(CLASSES_DIR));
                } else if (nextEntry.startsWith(LIB_DIR) && nextEntry.endsWith(JAR_EXT)) {
                    String jarFile = nextEntry.substring(LIB_DIR.length(), nextEntry.length()-JAR_EXT.length());
                    if(jarFile.indexOf('/") == -1) { // to avoid WEB-INF/lib/foo/bar.jar
                        // this jarFile is directly inside WEB-INF/lib directory
                        subArchives.put(nextEntry, archive.getSubArchive(nextEntry));
                    } else {
                        if(logger.isLoggable(Level.FINE)) {
                            logger.logp(Level.FINE, "WebArchivist",
                                    "readPersistenceDeploymentDescriptors",
                                    "skipping {0} as it exists inside a directory in {1}.",
                                    new Object[]{nextEntry, LIB_DIR});
                        }
                        continue;
                    }
                }
            }
            for(Map.Entry<String, Archive> pathToArchiveEntry : subArchives.entrySet()) {
                readPersistenceDeploymentDescriptor(pathToArchiveEntry.getValue(), pathToArchiveEntry.getKey(), descriptor);
            }
        } finally {
            for(Archive subArchive : subArchives.values()) {
                subArchive.close();
            }
        }
    
public voidsetDescriptor(com.sun.enterprise.deployment.Descriptor descriptor)
Archivist read XML deployment descriptors and keep the parsed result in the DOL descriptor instances. Sets the descriptor for a particular Archivst type

        if (descriptor instanceof WebBundleDescriptor) {
            this.descriptor = (WebBundleDescriptor) descriptor;
        } else {
            if (descriptor instanceof Application) {
                // this is acceptable if the application actually represents 
                // a standalone module
                java.util.Set webBundles = ((Application) descriptor).getWebBundleDescriptors();
                if (webBundles.size()>0) {
                    this.descriptor = (WebBundleDescriptor) webBundles.iterator().next();
                    if (this.descriptor.getModuleDescriptor().isStandalone()) 
                        return;
                    else 
                        this.descriptor=null;
                }      
            }
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.descriptorFailure", new Object[] {this});
            throw new RuntimeException("Error setting descriptor " + descriptor + " in " + this);
        }
    
public voidvalidate(java.lang.ClassLoader aClassLoader)
validates the DOL Objects associated with this archivist, usually it requires that a class loader being set on this archivist or passed as a parameter

        ClassLoader cl = aClassLoader;
        if (cl==null) {
            cl = classLoader;
        }
        if (cl==null) {
            return;
        }
        descriptor.setClassLoader(cl);
        descriptor.visit((WebBundleVisitor) new ApplicationValidator());