KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > archivist > EjbArchivist


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.archivist;
25
26 import java.io.File JavaDoc;
27 import java.io.FileNotFoundException JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.logging.Level JavaDoc;
31 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
32 import org.xml.sax.SAXParseException JavaDoc;
33
34 import com.sun.enterprise.deployment.Application;
35 import com.sun.enterprise.deployment.Descriptor;
36 import com.sun.enterprise.deployment.EjbBundleDescriptor;
37 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
38 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
39 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile;
40 import com.sun.enterprise.deployment.io.DescriptorConstants;
41 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile;
42 import com.sun.enterprise.deployment.io.runtime.EjbRuntimeDDFile;
43 import com.sun.enterprise.deployment.util.DOLUtils;
44 import com.sun.enterprise.deployment.util.EjbBundleValidator;
45 import com.sun.enterprise.deployment.util.EjbBundleVisitor;
46 import com.sun.enterprise.deployment.util.EjbComponentAnnotationDetector;
47 import com.sun.enterprise.deployment.util.ModuleContentValidator;
48 import com.sun.enterprise.util.FileUtil;
49 import com.sun.enterprise.util.LocalStringManagerImpl;
50
51 /**
52  * This class is responsible for handling J2EE EJB Bundlearchive files.
53  *
54  * @author Jerome Dochez
55  * @version
56  */

57 public class EjbArchivist extends Archivist {
58
59     EjbBundleDescriptor descriptor = null;
60     
61     /**
62      * The DeploymentDescriptorFile handlers we are delegating for XML i/o
63      */

64     DeploymentDescriptorFile standardDD = new EjbDeploymentDescriptorFile();
65     
66     // resources...
67
private static LocalStringManagerImpl localStrings =
68         new LocalStringManagerImpl(EjbArchivist.class);
69     
70     /** Creates new EjbBundleArchvisit */
71     public EjbArchivist() {
72     }
73     
74     /**
75      * @return the module type handled by this archivist
76      * as defined in the application DTD
77      *
78      */

79     public ModuleType JavaDoc getModuleType() {
80         return ModuleType.EJB;
81     }
82     
83     /**
84      * Set the DOL descriptor for this Archivist, used by super classes
85      */

86     public void setDescriptor(Descriptor descriptor) {
87         if (descriptor instanceof EjbBundleDescriptor) {
88             this.descriptor = (EjbBundleDescriptor) descriptor;
89         } else {
90             if (descriptor instanceof Application) {
91                 // this is acceptable if the application actually represents
92
// a standalone module
93
Set JavaDoc ejbBundles = ((Application) descriptor).getEjbBundleDescriptors();
94                 if (ejbBundles.size()>0) {
95                     this.descriptor = (EjbBundleDescriptor) ejbBundles.iterator().next();
96                     if (this.descriptor.getModuleDescriptor().isStandalone())
97                         return;
98                     else
99                         this.descriptor=null;
100                 }
101             }
102             DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.descriptorFailure", new Object JavaDoc[] {this});
103             throw new RuntimeException JavaDoc("Error setting descriptor " + descriptor + " in " + this);
104         }
105     }
106
107     /**
108      * @return the DeploymentDescriptorFile responsible for handling
109      * standard deployment descriptor
110      */

111     public DeploymentDescriptorFile getStandardDDFile() {
112         return standardDD;
113     }
114     
115     /**
116      * @return if exists the DeploymentDescriptorFile responsible for
117      * handling the configuration deployment descriptors
118      */

119     public DeploymentDescriptorFile getConfigurationDDFile() {
120         return new EjbRuntimeDDFile();
121     }
122     
123     /**
124      * @return the location of the web services related deployment
125      * descriptor file inside this archive or null if this archive
126      * does not support webservices implementation.
127      */

128     public String JavaDoc getWebServicesDeploymentDescriptorPath() {
129         return DescriptorConstants.EJB_WEBSERVICES_JAR_ENTRY;
130     }
131     
132     /**
133      * @return the Descriptor for this archvist
134      */

135     public Descriptor getDescriptor() {
136         return descriptor;
137     }
138
139     /**
140      * @return a default BundleDescriptor for this archivist
141      */

142     public Descriptor getDefaultBundleDescriptor() {
143         EjbBundleDescriptor ejbBundleDesc =
144             new EjbBundleDescriptor();
145         return ejbBundleDesc;
146     }
147
148     /**
149      * perform any post deployment descriptor reading action
150      *
151      * @param descriptor deployment descriptor for the module
152      * @param archive the module archive
153      */

154     protected void postOpen(RootDeploymentDescriptor descriptor, AbstractArchive archive)
155         throws IOException JavaDoc
156     {
157         super.postOpen(descriptor, archive);
158         EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) descriptor;
159         ModuleContentValidator mdv = new ModuleContentValidator(archive);
160         ejbBundle.visit((EjbBundleVisitor)mdv);
161     }
162     
163     /**
164      * validates the DOL Objects associated with this archivist, usually
165      * it requires that a class loader being set on this archivist or passed
166      * as a parameter
167      */

168     public void validate(ClassLoader JavaDoc aClassLoader) {
169         ClassLoader JavaDoc cl = aClassLoader;
170         if (cl==null) {
171             cl = classLoader;
172         }
173         if (cl==null) {
174             return;
175         }
176         descriptor.setClassLoader(cl);
177         descriptor.visit((EjbBundleVisitor) new EjbBundleValidator());
178     }
179
180     /**
181      * prepare an archivist for inclusion in a application archive.
182      *
183      * @param out file where this archivist will be saved
184      */

185     protected void prepareForInclusion(AbstractArchive out) throws IOException JavaDoc {
186         
187     // store the ejbJar by its hort filename
188
String JavaDoc ejbClientJarUri = descriptor.getEjbClientJarUri();
189
190         // If this ejb-jar has an ejb client jar, the ejb client jar URI
191
// is relative to the directory in which the ejb-jar lives.
192
if( !ejbClientJarUri.equals("") ) {
193             String JavaDoc ejbClientJarPath =
194                 ejbClientJarUri.replace(FileUtil.JAR_SEPARATOR_CHAR, File.separatorChar);
195                 
196             File JavaDoc ejbJarFile = new File JavaDoc(path);
197             File JavaDoc ejbClientJar = new File JavaDoc(ejbJarFile.getParentFile(), ejbClientJarPath);
198             if( ejbClientJar.exists() ) {
199                 // Pull the ejb-client-jar into the .ear and set the
200
// ejb-jar manifest classpath to point to it(relative
201
// to the base of the .ear)
202
addFileToArchive(out, ejbClientJar.getAbsolutePath(), ejbClientJarUri);
203                 String JavaDoc classPath = getClassPath();
204                 if (classPath==null) {
205                     classPath=ejbClientJarUri;
206                 } else {
207                     classPath+=" " + ejbClientJarUri;
208                 }
209                 setClassPath(classPath);
210             } else {
211                throw new FileNotFoundException JavaDoc(localStrings.getLocalString("enterprise.deployment.noclientjarentry", "Warning: {0} not found as a client jar entry.", new Object JavaDoc[] {ejbClientJar.toString()}));
212             }
213         }
214     }
215
216     protected String JavaDoc getArchiveExtension() {
217         return EJB_EXTENSION;
218     }
219
220     protected boolean postHandles(AbstractArchive abstractArchive)
221             throws IOException JavaDoc {
222         EjbComponentAnnotationDetector detector =
223                     new EjbComponentAnnotationDetector();
224         return detector.hasAnnotationInArchive(abstractArchive);
225     }
226
227     @Override JavaDoc public void readPersistenceDeploymentDescriptors(
228             AbstractArchive archive, Descriptor descriptor)
229             throws IOException JavaDoc, SAXParseException JavaDoc {
230         if(logger.isLoggable(Level.FINE)) {
231             logger.logp(Level.FINE, "EjbArchivist",
232                     "readPersistenceDeploymentDescriptors", "archive = {0}",
233                     archive.getURI());
234         }
235         // note we pass "" as the PURootPath because META-INF/persistence.xml
236
// can only be present on the top level in an ejb-jar, so the root of
237
// persistence unit is always same as the root of an ejb-jar file.
238
// hence relative distance between them is empty.
239
readPersistenceDeploymentDescriptor(archive, "", descriptor);
240     }
241 }
242
Popular Tags