KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > backend > ApplicationClientJarMaker


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.backend;
25
26 import java.io.IOException JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Properties JavaDoc;
31 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
32
33 import com.sun.enterprise.deployment.Application;
34 import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
35 import com.sun.enterprise.deployment.archivist.Archivist;
36 import com.sun.enterprise.deployment.archivist.ArchivistFactory;
37 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
38 import com.sun.enterprise.deployment.interfaces.ClientJarMaker;
39 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
40 import com.sun.enterprise.deployment.util.ModuleDescriptor;
41 import com.sun.enterprise.util.zip.ZipItem;
42
43 /**
44  * This class is responsible for creating an appclient jar file that
45  * will be used by the appclient container to run the appclients for
46  * the deployed application.
47  *
48  * @author Jerome Dochez
49  */

50 class ApplicationClientJarMaker implements ClientJarMaker {
51
52     protected Properties JavaDoc props;
53
54     /**
55      * Default constructor for this stateless object
56      * @param props are the implementation properties (if any)
57      */

58     public ApplicationClientJarMaker(Properties JavaDoc props) {
59         this.props = props;
60     }
61     
62     /**
63      * creates the appclient container jar file
64      * @param descriptor is the loaded module's deployment descriptor
65      * @param source is the abstract archive for the source module deployed
66      * @param target is the abstract archive for the desired appclient container jar file
67      * @param stubs are the stubs generated by the deployment codegen
68      * @param props is a properties collection to pass implementation parameters
69      *
70      * @throws IOException when the jar file creation fail
71      */

72     public void create(RootDeploymentDescriptor descriptor, AbstractArchive source,
73         AbstractArchive target,ZipItem[] stubs, Properties JavaDoc props)
74         throws IOException JavaDoc {
75         create(descriptor, source, null, target, stubs, props);
76     }
77
78     /**
79      * creates the appclient container jar file
80      * @param descriptor is the loaded module's deployment descriptor
81      * @param source is the abstract archive for the source module deployed
82      * @param source is the abstract archive for the generated xml directory
83      * @param target is the abstract archive for the desired appclient container jar file
84      * @param stubs are the stubs generated by the deployment codegen
85      * @param props is a properties collection to pass implementation parameters
86      *
87      * @throws IOException when the jar file creation fail
88      */

89     public void create(RootDeploymentDescriptor descriptor, AbstractArchive source,
90         AbstractArchive source2, AbstractArchive target,ZipItem[] stubs,
91         Properties JavaDoc props) throws IOException JavaDoc {
92
93         // in all cases we copy the stubs file in the target archive
94
ClientJarMakerUtils.populateStubs(target, stubs);
95
96         //@@@ this block will not be called if we use ModuleClientMaker
97
if (!descriptor.isApplication()) {
98             //copy over all content of the appclient
99
ClientJarMakerUtils.populateModuleJar(source, source2, target);
100             return;
101         }
102         
103         Application app = Application.class.cast(descriptor);
104         for (Iterator JavaDoc modules = app.getModules(); modules.hasNext();) {
105             ModuleDescriptor md = ModuleDescriptor.class.cast(modules.next());
106
107             //ignore the war and rar modules, include both appclient and ejb
108
if (md.getModuleType().equals(ModuleType.WAR)
109                 || md.getModuleType().equals(ModuleType.RAR)) {
110                 continue;
111             }
112
113             AbstractArchive subSource = source.getEmbeddedArchive(md.getArchiveUri());
114             AbstractArchive subSource2 = null;
115             if (source2 != null) {
116                 subSource2 = source2.getEmbeddedArchive(md.getArchiveUri());
117             }
118             AbstractArchive subTarget = target.getEmbeddedArchive(md.getArchiveUri());
119
120             //copy over all content of the appclient
121
ClientJarMakerUtils.populateModuleJar(subSource, subSource2, subTarget);
122                 
123             target.closeEntry(subTarget);
124             source.closeEntry(subSource);
125             if (source2 != null) {
126                 source2.closeEntry(subSource2);
127             }
128
129             //copy over the alternative deployment descriptors
130
if (md.getAlternateDescriptor() != null) {
131                 String JavaDoc ddPath = md.getAlternateDescriptor();
132                 String JavaDoc runtimeDDPath = "sun-" + ddPath;
133                 if (source2 != null) {
134                     ClientJarMakerUtils.copy(source2, target, ddPath);
135                     ClientJarMakerUtils.copy(source2, target, runtimeDDPath);
136                 } else {
137                     ClientJarMakerUtils.copy(source, target, ddPath);
138                     ClientJarMakerUtils.copy(source, target, runtimeDDPath);
139                 }
140             }
141         }
142
143         // populate the library jars
144
List JavaDoc<String JavaDoc> libraries =
145             ClientJarMakerUtils.getLibraryEntries(app, source);
146         for (String JavaDoc library : libraries) {
147             ClientJarMakerUtils.copy(source, target, library);
148         }
149
150         // deployment descriptors for the application
151
ClientJarMakerUtils.copyDeploymentDescriptors(
152             new ApplicationArchivist(), source, source2, target);
153     }
154 }
155
Popular Tags