KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25 * EjbModuleDeployer.java
26 *
27 * Created on January 3, 2002, 3:33 PM
28 */

29
30 package com.sun.enterprise.deployment.backend;
31
32 import java.io.*;
33 import java.util.List JavaDoc;
34 import java.util.logging.*;
35
36 import com.sun.ejb.codegen.IASEJBCTimes;
37 import com.sun.enterprise.util.io.FileUtils;
38 import com.sun.enterprise.util.zip.ZipFileException;
39 import com.sun.enterprise.util.zip.ZipItem;
40 import com.sun.enterprise.config.ConfigException;
41 import com.sun.enterprise.instance.BaseManager;
42 import com.sun.enterprise.instance.EjbModulesManager;
43 import com.sun.enterprise.instance.InstanceEnvironment;
44 import com.sun.enterprise.instance.ModuleEnvironment;
45 import com.sun.enterprise.util.diagnostics.Profiler;
46 import com.sun.enterprise.util.i18n.StringManager;
47 import com.sun.enterprise.security.SecurityUtil;
48 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper;
49 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory;
50 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr;
51 import com.sun.enterprise.deployment.Application;
52 import com.sun.enterprise.deployment.EjbBundleDescriptor;
53 import com.sun.enterprise.deployment.EjbDescriptor;
54 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils;
55 import com.sun.enterprise.security.util.IASSecurityException;
56 import com.sun.enterprise.security.application.EJBSecurityManager;
57 import com.sun.enterprise.security.factory.EJBSecurityManagerFactory;
58 import com.sun.enterprise.loader.EJBClassPathUtils;
59
60 // imports for dd generator
61
import com.sun.enterprise.deployment.archivist.Archivist;
62 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
63 import com.sun.enterprise.deployment.interfaces.*;
64
65
66 /**
67 * EjbModuleDeployer is a class for deploying EJB Modules
68 * Much of the code is in the super-class.
69 *
70 * @author bnevins
71 * @version
72 */

73 public class EjbModuleDeployer extends ModuleDeployer
74 {
75     EjbModuleDeployer(DeploymentRequest r) throws IASDeploymentException
76     {
77         super(r);
78     }
79     
80     ///////////////////////////////////////////////////////////////////////////
81

82     protected boolean needsStubs()
83     {
84         return true;
85     }
86     
87     ///////////////////////////////////////////////////////////////////////////
88

89     protected BaseManager createConfigManager(InstanceEnvironment ienv, ModuleEnvironment menv) throws IASDeploymentException, ConfigException
90     {
91         manager = new EjbModulesManager(ienv);
92         return manager;
93     }
94     
95     ///////////////////////////////////////////////////////////////////////////
96

97     protected void preDeploy() throws IASDeploymentException
98     {
99         assert stubsDir != null;
100         assert moduleDir != null;
101         assert moduleName != null;
102
103         try
104         {
105             if(isRegistered()) {
106             String JavaDoc msg = localStrings.getString(
107             "enterprise.deployment.backend.deploy_error_module_exists");
108             throw new IASDeploymentException( msg );
109             }
110
111             // if the directories already exist on disk -- wipe them out
112
// We do this because otherwise they'd never get this Module deployed
113
// without wiping the dirs manually
114
liquidateModuleDirAndStubsDirIfTheyHappenToExist();
115
116             if(request.isArchive()) {
117                             // check if this is a .jar file or a single .class file
118
if (request.getFileSource().getFile().getName().endsWith(".class")) {
119                                 copyAutodeployedClassFile(request.getFileSource().getFile(), moduleDir);
120                             } else {
121                     J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir);
122                             }
123                         }
124
125                         xmlDir.mkdirs();
126                         stubsDir.mkdirs();
127         }
128         catch(Exception JavaDoc e)
129         {
130             throw new IASDeploymentException(e.toString(), e);
131         }
132     }
133     
134     ///////////////////////////////////////////////////////////////////////////
135

136     protected void deploy() throws IASDeploymentException, ConfigException
137     {
138         loadDescriptors();
139         runVerifier();
140                 // Set the generated XML directory in application desc
141
request.getDescriptor().setGeneratedXMLDirectory(xmlDir.getAbsolutePath());
142         ZipItem[] clientStubs = runEJBC();
143         createClientJar(clientStubs);
144     }
145     
146     ///////////////////////////////////////////////////////////////////////////
147

148     protected void preRedeploy() throws IASDeploymentException, ConfigException
149     {
150         assert stubsDir != null;
151         assert moduleDir != null;
152         assert moduleName != null;
153         
154         setOldDirs();
155         
156
157         try {
158             if(request.isArchive()) {
159                 // check if this is a .jar file or a single .class file
160
if (request.getFileSource().getFile().getName().endsWith(".class")) {
161                     copyAutodeployedClassFile(request.getFileSource().getFile(), moduleDir);
162                 } else {
163                     J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir);
164                 }
165             }
166         } catch(IOException e) {
167             throw new IASDeploymentException(e.toString(), e);
168         }
169         xmlDir.mkdirs();
170         stubsDir.mkdirs();
171     }
172     
173     ///////////////////////////////////////////////////////////////////////////
174

175     protected void register() throws IASDeploymentException, ConfigException
176     {
177         super.register();
178         setShared(request.isSharedModule());
179     }
180     
181     ///////////////////////////////////////////////////////////////////////////
182
protected void generatePolicy() throws IASDeploymentException
183     {
184         // if this is a part of application then generatePolicy in AppDeployerBa
185
// se will be called, so this should be a no-op
186
try
187         {
188             if(request.isApplication())
189             {
190                 return;
191             }
192             else
193             {
194                 Application app = request.getDescriptor();
195                 EjbBundleDescriptor ejbBundleDesc =
196                     (EjbBundleDescriptor)
197                     app.getStandaloneBundleDescriptor();
198                 //For standalone ejbs, the RoleMapper should be constructed by now
199
String JavaDoc name = EJBSecurityManager.getContextID(ejbBundleDesc);
200                 SecurityUtil.generatePolicyFile(name);
201                                 EJBSecurityManagerFactory ejbsmf =
202                                     (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance();
203                                 ejbsmf.createSecurityManager(
204                                     (EjbDescriptor)ejbBundleDesc.getEjbs().iterator().next());
205             }
206         }
207         catch (IASSecurityException se)
208         {
209             String JavaDoc msg =
210             localStrings.getString("enterprise.deployment.backend.generate_policy_error" );
211
212             logger.log(Level.WARNING, msg, se);
213             throw new IASDeploymentException(msg, se);
214         }
215     }
216     
217     // Instantiate class
218
DDGenerator ddGenerator = null;
219
220     ///////////////////////////////////////////////////////////////////////////
221

222     public void removePolicy() throws IASDeploymentException
223     {
224         if (request.isApplication())
225         {
226             return;
227         }
228
229         String JavaDoc requestName = request.getName();
230                 EJBSecurityManagerFactory ejbsmf =
231                    (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance();
232                 String JavaDoc[] names =
233                     ejbsmf.getAndRemoveContextIdForEjbAppName(requestName);
234                 String JavaDoc name = null;
235         try
236         {
237                         if (names != null && names.length > 0 &&
238                                 names[0] != null) {
239                             name = names[0];
240                             SecurityUtil.removePolicy(name);
241                         }
242         }
243         catch(IASSecurityException ex)
244         {
245             String JavaDoc msg = localStrings.getString(
246                 "enterprise.deployment.backend.remove_policy_error",name);
247             logger.log(Level.WARNING, msg, ex);
248             throw new IASDeploymentException(msg, ex);
249         }
250     }
251
252     ///////////////////////////////////////////////////////////////////////////
253

254     private EjbModulesManager manager = null;
255     private static StringManager localStrings = StringManager.getManager( EjbModuleDeployer.class );
256 }
257
258
Popular Tags