FileDocCategorySizeDatePackage
ApplicationClientJarMaker.javaAPI DocGlassfish v2 API10176Mon Jul 16 13:12:00 BST 2007com.sun.enterprise.deployment.backend

ApplicationClientJarMaker

public class ApplicationClientJarMaker extends Object implements com.sun.enterprise.deployment.interfaces.ClientJarMaker
This class is responsible for creating an appclient jar file that will be used by the appclient container to run the appclients for the deployed application.
author
Jerome Dochez

Fields Summary
protected Properties
props
Constructors Summary
public ApplicationClientJarMaker(Properties props)
Default constructor for this stateless object

param
props are the implementation properties (if any)

        this.props = props;
    
Methods Summary
public voidcreate(com.sun.enterprise.deployment.RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target, com.sun.enterprise.util.zip.ZipItem[] stubs, java.util.Properties props)
creates the appclient container jar file

param
descriptor is the loaded module's deployment descriptor
param
source is the abstract archive for the source module deployed
param
target is the abstract archive for the desired appclient container jar file
param
stubs are the stubs generated by the deployment codegen
param
props is a properties collection to pass implementation parameters
throws
IOException when the jar file creation fail

        create(descriptor, source, null, target, stubs, props);
    
public voidcreate(com.sun.enterprise.deployment.RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive source2, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target, com.sun.enterprise.util.zip.ZipItem[] stubs, java.util.Properties props)
creates the appclient container jar file

param
descriptor is the loaded module's deployment descriptor
param
source is the abstract archive for the source module deployed
param
source is the abstract archive for the generated xml directory
param
target is the abstract archive for the desired appclient container jar file
param
stubs are the stubs generated by the deployment codegen
param
props is a properties collection to pass implementation parameters
throws
IOException when the jar file creation fail


        // in all cases we copy the stubs file in the target archive
        ClientJarMakerUtils.populateStubs(target, stubs);

        //@@@ this block will not be called if we use ModuleClientMaker
        if (!descriptor.isApplication()) {
            //copy over all content of the appclient
            ClientJarMakerUtils.populateModuleJar(source, source2, target);
            return;
        }
        
        /* libraries holds URIs (relative to the application's root level) for
         * directories and JARs that need to be added to the 
         * client JAR because they are in the <library-directory> (spec requirement),
         * they are at the top-level of the EAR (legacy feature compatibility), 
         * or they appear in the manifest Class-Path entry of a JAR otherwise
         * to be included in the app client JAR
         */
        ArrayList<String> libraries = new ArrayList<String>();
        URI appURI = new File(source.getArchiveUri()).toURI();
        
        Application app = Application.class.cast(descriptor);
        for (Iterator modules = app.getModules(); modules.hasNext();) {
            ModuleDescriptor md = ModuleDescriptor.class.cast(modules.next());

            //ignore the war and rar modules, include both appclient and ejb
            if ( ! (md.getModuleType().equals(ModuleType.WAR) 
                || md.getModuleType().equals(ModuleType.RAR)) ){

                AbstractArchive subSource = source.getEmbeddedArchive(md.getArchiveUri());
                AbstractArchive subSource2 = null;
                if (source2 != null) {
                    subSource2 = source2.getEmbeddedArchive(md.getArchiveUri());
                }
                AbstractArchive subTarget = target.getEmbeddedArchive(md.getArchiveUri());
                
                /*
                 * populateModuleJar will add URIs for any JARs mentioned in
                 * the module JAR's manifest Class-Path, but to do so it needs
                 * to know the URI of the app and the URI of the parent of the module
                 * since Class-Path entries are relative to the parent of the 
                 * referring JAR.  So compute the parentURI.
                 */
                String archiveUri = md.getArchiveUri().replace('\\",'/");
                URI parentURI = null;
                try {
                    parentURI = ClientJarMakerUtils.getParent(archiveUri);
                } catch (URISyntaxException ex) {
                    IOException ioe = new IOException();
                    ioe.initCause(ex);
                    throw ioe;
                }
                
                //copy over all content of the appclient - also updates 'libraries' as needed
                ClientJarMakerUtils.populateModuleJar(subSource, subSource2, subTarget, libraries, appURI, parentURI);

                target.closeEntry(subTarget);
                source.closeEntry(subSource);
                if (source2 != null) {
                    source2.closeEntry(subSource2);
                }
            }

            //copy over the alternative deployment descriptors
            //Do this even for web or resource adapter submodules because
            //the application.xml which will be copied into the client jar
            //will still refer to those alt. DD files.  So even though the
            //web or RA submodules will not be included, include the alt. DDs
            //so the generated app client jar archive will load correctly
            //on the client.
            if (md.getAlternateDescriptor() != null) {
                String ddPath = md.getAlternateDescriptor();
                String runtimeDDPath = "sun-" + ddPath;
                if (source2 != null) {
                    ClientJarMakerUtils.copy(source2, target, ddPath);
                    ClientJarMakerUtils.copy(source2, target, runtimeDDPath);
                } else {
                    ClientJarMakerUtils.copy(source, target, ddPath);
                    ClientJarMakerUtils.copy(source, target, runtimeDDPath);
                }
            }
        }

        // The libraries list already contains URIs for JARs or directories
        // that appeared in the module's manifest Class-Path entries.  Now
        // add to that list URIs for other JARs that need to be included.
        List<String> additionalLibraries = 
            ClientJarMakerUtils.getLibraryEntries(app, source);
        libraries.addAll(additionalLibraries);
        
        // Go through the JARs to be added to the classpath.  For each one check
        // to see if it has a Manifest Class-Path entry.  If so, add each
        // part of the Class-Path entry to the list of libraries.  Note that the
        // entries can be either JARs or directories.  Either will work.
        ClientJarMakerUtils.addClassPathElementsFromManifestClassPaths(new File(appURI), libraries);
        
        // Copy all the library JARs and directories into the app client archive
        ClientJarMakerUtils.copyLibraries(source, target, libraries);

        // deployment descriptors for the application
        ClientJarMakerUtils.copyDeploymentDescriptors(
            new ApplicationArchivist(), source, source2, target);