KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @(#) EjbcContextImpl.java
26  *
27  */

28
29 package com.sun.enterprise.deployment.backend;
30
31 import java.io.File JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Properties JavaDoc;
34 import com.sun.ejb.codegen.EjbcContext;
35 import com.sun.ejb.codegen.IASEJBCTimes;
36 import com.sun.enterprise.loader.EJBClassLoader;
37 import com.sun.enterprise.util.io.FileUtils;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40 import com.sun.enterprise.deployment.Application;
41
42
43 /**
44  * Ejbc runtime environment created by deployment backend. This class
45  * contains all the information needed by ejbc for a particular deployment.
46  *
47  * @author Nazrul Islam
48  * @since JDK 1.4
49  */

50 public class EjbcContextImpl implements EjbcContext {
51
52     /**
53      * Do-nothing constructor.
54      */

55     EjbcContextImpl()
56     {
57     }
58
59     /**
60      * @author bnevins
61      * I added this constructor to get rid of the long, error-prone sequence of setter commands
62      * sprinkled in the code to create instances for CMP usage. They all use the
63      * same sequences, so it may as well be a constructor that has some smarts...
64      */

65     
66     EjbcContextImpl(File JavaDoc srcDir, File JavaDoc stubsDir, Application dd, DeploymentRequest request)
67     {
68         setSrcDir(srcDir);
69         setStubsDir(stubsDir);
70         setDeploymentRequest(request);
71         setOptionalArguments(request.getOptionalArguments());
72         setDescriptor(dd);
73     }
74     
75     
76     /**
77      * Returns the current directory where the archive has been exploded.
78      *
79      * @return the directory where the archive has been exploded
80      */

81     public File JavaDoc getSrcDir() {
82         return this._srcDir;
83     }
84
85     /**
86      * Sets the directory where the archive has been exploded.
87      *
88      * @param srcDir current directory where the archive has been exploded
89      */

90     void setSrcDir(File JavaDoc srcDir) {
91         this._srcDir = srcDir;
92     }
93
94     /**
95      * Returns the old directory where the ear file was exploded (in case
96      * of redeployment) or null.
97      *
98      * @return old directory where the ear file was exploded or null
99      */

100     public File JavaDoc getOldSrcDir() {
101         return this._oldSrcDir;
102     }
103
104     /**
105      * Sets the old src directory for redeployment optimization.
106      *
107      * @param oldSrcDir old directory where the ear file was exploded
108      */

109     void setOldSrcDir(File JavaDoc oldSrcDir) {
110         this._oldSrcDir = oldSrcDir;
111     }
112
113     /**
114      * Returns the (current stubs) directory where all the code is
115      * generated and being compiled for this archive.
116      *
117      * @return the current stubs directory for this archive
118      */

119     public File JavaDoc getStubsDir() {
120         return this._stubsDir;
121     }
122
123     /**
124      * Sets the current stubs directory.
125      *
126      * @param stubsDir current stubs directory
127      */

128     void setStubsDir(File JavaDoc stubsDir) {
129         this._stubsDir = stubsDir;
130     }
131
132     /**
133      * Returns the (old stubs) directory where generated code from
134      * previous deployment can be found in case of redeployment.
135      *
136      * @return in case of redeployment, the old stubs directory or null
137      */

138     public File JavaDoc getOldStubsDir() {
139         return this._oldStubsDir;
140     }
141
142     /**
143      * Sets the old stubs directory.
144      *
145      * @param oldStubsDir in case of redeployment, the old stubs dir
146      */

147     void setOldStubsDir(File JavaDoc oldStubsDir) {
148         this._oldStubsDir = oldStubsDir;
149     }
150
151     /**
152      * Returns the object representation of the deployment descriptor
153      * for the current archive.
154      *
155      * @return the deployment descriptor for the current archive
156      */

157     public Application getDescriptor() {
158         return this._application;
159     }
160
161     /**
162      * Sets the deployment descriptor object.
163      *
164      * @param application deployment descriptor object for the
165      * current archive
166      */

167     void setDescriptor(Application application) {
168         this._application = application;
169     }
170
171     /**
172      * Returns true when the archive is being redeployed.
173      *
174      * @return true when the archive is being redeployed
175      */

176     public boolean isRedeploy() {
177
178         boolean tf = false;
179
180         if ( FileUtils.safeIsDirectory(this._oldSrcDir)
181                 && FileUtils.safeIsDirectory(this._oldStubsDir) ) {
182
183             tf = true;
184
185         }
186
187         return tf;
188     }
189
190     public ClassLoader JavaDoc getOldClassLoader() {
191         return this._oldClassLoader;
192     }
193
194     void setOldClassLoader(ClassLoader JavaDoc oldClassLoader) {
195         this._oldClassLoader = oldClassLoader;
196     }
197
198     /**
199      * Returns the class paths need by this archive to compile the
200      * generated src. This includes class-path prefix, class-path
201      * of the target instance, common class loader paths, shared
202      * class loader paths and the ejb class loader paths.
203      *
204      * @return the ejb class paths for this archive
205      */

206     public String JavaDoc[] getClasspathUrls() {
207         return this._classpathUrls;
208     }
209
210     /**
211      * Sets the ejb class paths.
212      *
213      * @param classpathUrls the ejb class paths for this archive
214      */

215     void setClasspathUrls(String JavaDoc[] classpathUrls) {
216         this._classpathUrls = classpathUrls;
217     }
218
219     /**
220      * Returns the RMIC options as defined in the instance's server
221      * configuration.
222      *
223      * The default is:
224      * "-iiop -poa -alwaysgenerate -keepgenerated -g"
225      *
226      * @return the RMIC options
227      */

228     public List JavaDoc getRmicOptions() {
229         return this._rmicOptions;
230     }
231
232     /**
233      * Sets the RMIC options.
234      *
235      * @param rmicOptions RMIC options
236      */

237     void setRmicOptions(List JavaDoc rmicOptions) {
238         this._rmicOptions = rmicOptions;
239     }
240
241     /**
242      * Returns the JAVAC options as defined in the instance's server
243      * configuration.
244      *
245      * The default is: "-g"
246      *
247      * @return the JAVAC options
248      */

249     public List JavaDoc getJavacOptions() {
250         return this._javacOptions;
251     }
252
253     /**
254      * Sets the JAVAC options.
255      *
256      * @param javacOptions JAVAC options
257      */

258     void setJavacOptions(List JavaDoc javacOptions) {
259         this._javacOptions = javacOptions;
260     }
261
262     /**
263      * Returns the timing information for the sub-tasks of ejbc.
264      *
265      * @return timing information for the sub-tasks of ejbc
266      */

267     public IASEJBCTimes getTiming() {
268         return this._timing;
269     }
270
271     /**
272      * Sets the timing for ejbc.
273      *
274      * @param timing object encapsulating the timing information
275      * for the sub-tasks of ejbc
276      */

277     void setTiming(IASEJBCTimes timing) {
278         this._timing = timing;
279     }
280
281     /**
282      * Returns the ejb class paths of this archive.
283      *
284      * @return the ejb class paths for this archive
285      */

286     public String JavaDoc[] getEjbClasspathUrls() {
287         return this._ejbClasspathUrls;
288     }
289
290     /**
291      * Sets the ejb class path for this deployment.
292      * This is the ejb part of the archive and
293      * does not have any other class paths.
294      *
295      * This method is used during re-deployment optimization in ejbc.
296      */

297     void setEjbClasspathUrls(String JavaDoc[] paths) {
298         this._ejbClasspathUrls = paths;
299     }
300
301     /**
302      * Returns the deployment mode, i.e., archive layout.
303      * Default is EXPLODED mode.
304      *
305      * @return deployment mode
306      */

307     public DeploymentMode getDeploymentMode() {
308         return this._deploymentMode;
309     }
310
311     /**
312      * Sets the deployment mode.
313      *
314      * @param mode deployment mode to be used for this deployment
315      */

316     void setDeploymentMode(DeploymentMode mode) throws IASDeploymentException {
317         if (mode == null) {
318             String JavaDoc msg = localStrings.getString(
319                         "enterprise.deployment.backend.invalid_deployment_mode",
320                         "null" );
321             throw new IASDeploymentException(msg);
322         }
323         this._deploymentMode = mode;
324     }
325
326     /**
327      * Returns the optional arguments - which currently consists of
328      * CMP-specific deployment arguments
329      *
330      * @return optional attributes
331      */

332     public Properties JavaDoc getOptionalArguments()
333     {
334         return _optionalArguments;
335     }
336     
337     /**
338      * Sets the optional attributes
339      * @see setOptionalAttributes
340      * @param optionalAttributes the optional attributes as name-value pairs
341      */

342     void setOptionalArguments(Properties JavaDoc p)
343     {
344         _optionalArguments = p;
345     }
346
347     /**
348      * Returns the original DeploymentRequest object for the current deployment
349      * @return Deployment Request object
350      */

351     public DeploymentRequest getDeploymentRequest()
352     {
353         return _request;
354     }
355
356     /**
357      * Sets the original DeploymentRequest object for the current deployment
358      * @param request Deployment Request object
359      */

360     void setDeploymentRequest(DeploymentRequest request)
361     {
362         _request = request;
363     }
364
365     public void cleanup() {
366
367         if( _oldClassLoader != null ) {
368             if( _oldClassLoader instanceof EJBClassLoader ) {
369                 ( (EJBClassLoader) _oldClassLoader ).done();
370                 _oldClassLoader = null;
371             }
372         }
373
374     }
375     
376     // ---- INSTANCE VARIABLE(S) - PRIVATE ----------------------------------
377

378     /** current directory where the ear file has been exploded */
379     private File JavaDoc _srcDir = null;
380
381     /** old directory where the ear file was exploded (redeployment only) */
382     private File JavaDoc _oldSrcDir = null;
383
384     /** current stubs directory for the archive */
385     private File JavaDoc _stubsDir = null;
386
387     /** old stubs directory for the archive (redeployment only) */
388     private File JavaDoc _oldStubsDir = null;
389
390     /** obj representation of deployment descriptor */
391     private Application _application = null;
392
393     /** obj representation of the old deployment descriptor */
394     private Object JavaDoc _oldDescriptor = null;
395
396     private ClassLoader JavaDoc _oldClassLoader = null;
397
398     /** class paths for this archive */
399     private String JavaDoc[] _classpathUrls = null;
400
401     /** ejb class paths for this archive */
402     private String JavaDoc[] _ejbClasspathUrls = null;
403
404     /** RMIC options */
405     private List JavaDoc _rmicOptions = null;
406
407     /** JAVAC options */
408     private List JavaDoc _javacOptions = null;
409
410     /** timing information for the sub-tasks of ejbc */
411     private IASEJBCTimes _timing = null;
412
413     /** deployment mode */
414     private DeploymentMode _deploymentMode = DeploymentMode.EXPLODED;
415
416     /** optional attributes */
417     private Properties JavaDoc _optionalArguments = null;
418
419     /** Deployment Request object */
420     private DeploymentRequest _request = null;
421
422     /** i18n string manager */
423     private static StringManager localStrings =
424             StringManager.getManager( EjbcContextImpl.class );
425 }
426
Popular Tags