KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > ddgenerator > sun > DescriptorArchivist


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.ddgenerator.sun;
25
26
27 import java.io.IOException JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.util.Iterator JavaDoc;
30
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.BundleDescriptor;
38 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
39 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile;
40 import com.sun.enterprise.deployment.util.ModuleDescriptor;
41 import com.sun.enterprise.deployment.WebBundleDescriptor;
42
43 /**
44  * This class is responsible for writing deployment descriptors
45  * after a deployment action has occured to a abstract archive instance.
46  *
47  * @author Jerome Dochez
48  */

49 public class DescriptorArchivist {
50     
51     /** Creates a new instance of DescriptorArchivist */
52     public DescriptorArchivist() {
53     }
54   
55     /**
56      * writes an application deployment descriptors
57      * @param the application object
58      * @param the abstract archive
59      */

60     public void write(Application application, AbstractArchive out)
61         throws IOException JavaDoc
62     {
63         if (application.isVirtual()) {
64             ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().next();
65             Archivist moduleArchivist = ArchivistFactory.getArchivistForType(aModule.getModuleType());
66             write(aModule.getDescriptor(), moduleArchivist, out);
67         } else {
68             // this is a real application.
69

70             // let's start by writing out all submodules deployment descriptors
71
for (Iterator JavaDoc modules = application.getModules();modules.hasNext();) {
72                 ModuleDescriptor aModule = (ModuleDescriptor) modules.next();
73                 Archivist moduleArchivist = ArchivistFactory.getArchivistForType(aModule.getModuleType());
74                 if (aModule.getAlternateDescriptor()!=null) {
75                     // the application is using alternate deployment descriptors
76
String JavaDoc runtimeDDPath = "sun-" + aModule.getAlternateDescriptor();
77                     DeploymentDescriptorFile ddFile = moduleArchivist.getConfigurationDDFile();
78                     if (ddFile!=null) {
79                         OutputStream JavaDoc os = out.putNextEntry(runtimeDDPath);
80                         ddFile.write(aModule.getDescriptor(), os);
81                         out.closeEntry();
82                     }
83                 } else {
84                     AbstractArchive moduleArchive = out.getEmbeddedArchive(aModule.getArchiveUri());
85                     write(aModule.getDescriptor(), moduleArchivist, moduleArchive);
86                 }
87             }
88             
89             // now let's write the application runtime descriptor
90
ApplicationArchivist archivist = new ApplicationArchivist();
91             archivist.setDescriptor(application);
92             archivist.writeRuntimeDeploymentDescriptors(out);
93         }
94     }
95     
96     /**
97      * writes a bundle descriptor
98      * @param the bundle descriptor
99      * @param the abstract archive
100      */

101     public void write(BundleDescriptor bundle, AbstractArchive out)
102         throws IOException JavaDoc
103     {
104         Archivist archivist = ArchivistFactory.getArchivistForArchive(out);
105         write(bundle, archivist, out);
106     }
107     
108     /**
109      * writes a bundle descriptor
110      * @param the bundle descriptor
111      * @param the archivist responsible for writing such bundle type
112      * @param the archive to write to
113      */

114     protected void write(BundleDescriptor bundle, Archivist archivist, AbstractArchive out)
115         throws IOException JavaDoc
116     {
117         
118         archivist.setDescriptor(bundle);
119         archivist.writeRuntimeDeploymentDescriptors(out);
120         
121         // now if this is a web bundle descriptor, we may need to rewrite the standard
122
// deployment descriptors if we have web services since the servlet implementation
123
// has been switched
124
if (bundle.getModuleType().equals(ModuleType.WAR)) {
125             WebBundleDescriptor webBundle = (WebBundleDescriptor) bundle;
126             if (webBundle.hasWebServices()) {
127                 archivist.writeStandardDeploymentDescriptors(out);
128             }
129         }
130     }
131 }
132
Popular Tags