KickJava   Java API By Example, From Geeks To Geeks.

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


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.deploy.shared.AbstractArchive;
36 import com.sun.enterprise.deployment.interfaces.ClientJarMaker;
37 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
38 import com.sun.enterprise.deployment.util.ModuleDescriptor;
39 import com.sun.enterprise.util.zip.ZipItem;
40
41 /**
42  * This class is responsible for creating an appclient jar file that
43  * will be used by the appclient container to run the appclients for
44  * the deployed application.
45  *
46  * @author deployment dev team
47  */

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

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

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

87     public void create(RootDeploymentDescriptor descriptor, AbstractArchive source,
88         AbstractArchive source2, AbstractArchive target,ZipItem[] stubs,
89         Properties JavaDoc props) throws IOException JavaDoc {
90         
91         // in all cases we copy the stubs file in the target archive
92
ClientJarMakerUtils.populateStubs(target, stubs);
93
94         AbstractArchive appclientSource = null;
95         AbstractArchive appclientSource2 = null;
96
97         // abstract out the one and only appclient content from ear file
98
if (descriptor.isApplication()) {
99
100             // copy and expand library files here
101
// @@@ need to clean up to handle manifest override problem
102
// @@@ for multiple library jar files
103
List JavaDoc<String JavaDoc> libraries = ClientJarMakerUtils.getLibraryEntries(
104                     Application.class.cast(descriptor), source);
105
106             for (String JavaDoc entryName : libraries) {
107                 AbstractArchive subSource = null;
108                 try {
109                     subSource = source.getEmbeddedArchive(entryName);
110                     for (Enumeration JavaDoc subEntries = subSource.entries();
111                                 subEntries.hasMoreElements();) {
112                         String JavaDoc subEntryName =
113                                 String JavaDoc.class.cast(subEntries.nextElement());
114                         ClientJarMakerUtils.copy(
115                                 subSource, target, subEntryName);
116                     }
117                 } finally {
118                     if (subSource != null) {
119                         source.closeEntry(subSource);
120                     }
121                 }
122             }
123
124             //there should only be one appclient in this ear file
125
for (Iterator JavaDoc modules = Application.class.cast(descriptor).getModules();
126                     modules.hasNext();) {
127                 ModuleDescriptor md = ModuleDescriptor.class.cast(modules.next());
128                 if (md.getModuleType().equals(ModuleType.CAR)) {
129                     appclientSource = source.getEmbeddedArchive(md.getArchiveUri());
130                     if (source2 != null) {
131                         appclientSource2 =
132                             source2.getEmbeddedArchive(md.getArchiveUri());
133                     }
134                     break;
135                 }
136             }
137         } else {
138             appclientSource = source;
139             appclientSource2 = source2;
140         }
141
142         //copy over all content of the appclient
143
if (appclientSource != null) {
144             ClientJarMakerUtils.populateModuleJar(
145                 appclientSource, appclientSource2, target);
146         } else {
147             //this is a workaround because otherwise the appclient jar could
148
//be empty which causes problems when closing the archive (there is
149
//a requirement on having at least one entry in the archive before
150
//closing)
151
ClientJarMakerUtils.copyDeploymentDescriptors(
152                 new ApplicationArchivist(), source, source2, target);
153         }
154
155         // for backward compatibility, we need to include the content
156
// of the ejb module as well, since many clients currently are
157
// packaged without their ejb dependencies. We will copy the
158
// .class entries only. We copy them here _after_ the appclient
159
// classes have been copied so that if any duplicates exist,
160
// the class in the original appclient jar prevails.
161
if (descriptor.isApplication()) {
162             for (Iterator JavaDoc modules = Application.class.cast(descriptor).getModules();
163                     modules.hasNext();) {
164                 ModuleDescriptor md = ModuleDescriptor.class.cast(modules.next());
165                 if (md.getModuleType().equals(ModuleType.EJB)) {
166                     AbstractArchive subSource =
167                         source.getEmbeddedArchive(md.getArchiveUri());
168                     for (Enumeration JavaDoc e = subSource.entries();e.hasMoreElements();) {
169                         String JavaDoc entryName = String JavaDoc.class.cast(e.nextElement());
170                         if (!entryName.endsWith(".class")) {
171                             continue;
172                         }
173                         try {
174                             ClientJarMakerUtils.copy(subSource, target, entryName);
175                         } catch(IOException JavaDoc ioe) {
176                             // duplicate, we ignore
177
} finally {
178                             if (subSource != null) {
179                                 source.closeEntry(subSource);
180                             }
181                         }
182                     }
183                 }
184             }
185         }
186     }
187 }
188
Popular Tags