KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > instance > ApplicationEnvironment


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.instance;
25
26 //iAS imports
27
import com.sun.enterprise.util.StringUtils;
28 import com.sun.enterprise.util.diagnostics.*;
29
30 import java.util.logging.Logger JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import com.sun.logging.LogDomains;
33 /**
34     A class that provides the environment for an Application deployed within
35     a given Server Instance. Provides convenience methods for the entire application,
36     modules within.
37     
38     @author Kedar
39     @version 1.0
40 */

41
42 public class ApplicationEnvironment {
43
44     private String JavaDoc mAppName = null;
45     private String JavaDoc mAppPath = null;
46     private String JavaDoc mAppGeneratedXMLPath = null;
47     private String JavaDoc mAppStubPath = null;
48     private String JavaDoc mAppBackupPath = null;
49     private String JavaDoc mAppJSPPath = null;
50         private String JavaDoc mJavaWebStartPath = null;
51     private InstanceEnvironment mInstance = null;
52     private static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
53         
54     
55     /**
56         Creates new ApplicationEnvironment for given InstanceEnvironment
57         and given application name.
58         @param instance InstanceEnvironment where the application is deployed.
59         @param appName String representing the name of the application.
60     */

61
62     public ApplicationEnvironment (InstanceEnvironment instance, String JavaDoc appName) {
63         if (instance == null || appName == null) {
64             throw new IllegalArgumentException JavaDoc();
65         }
66         mInstance = instance;
67         mAppName = appName;
68         createAppPath();
69         createAppStubPath();
70         createAppBackupPath();
71         createAppJSPPath();
72         createAppGeneratedXMLPath();
73                 createJavaWebStartPath();
74     }
75     
76     private void createAppPath() {
77         String JavaDoc applicationRepositoryDirPath = mInstance.getApplicationRepositoryPath();
78         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
79             applicationRepositoryDirPath,
80             mAppName
81             };
82         mAppPath = StringUtils.makeFilePath (onlyFolderNames, false);
83     }
84
85     private void createAppBackupPath() {
86         // This is used to keep a copy of directory-deployed app files
87
String JavaDoc applicationBackupRepositoryDirPath = mInstance.getApplicationBackupRepositoryPath();
88         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
89             applicationBackupRepositoryDirPath,
90             mAppName
91             };
92         mAppBackupPath = StringUtils.makeFilePath (onlyFolderNames, false);
93     }
94     
95     /**
96         Returns the absolute path for the all the elements within this application.
97         Note that it does not create/check file/directory with such a path.
98     */

99     
100     public String JavaDoc getAppPath() {
101         return mAppPath;
102     }
103     
104     /**
105         Returns the absolute path for storing all the stubs of this application.
106         Note that it does not create/check file/directory with such a path.
107     */

108     
109     public void createAppStubPath() {
110         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
111             mInstance.getApplicationStubPath(),
112             mAppName
113         };
114         
115         mAppStubPath = StringUtils.makeFilePath (onlyFolderNames, false);
116     }
117
118         /**
119                 Returns the absolute path for storing all the generated xml of this application.
120                 Note that it does not create/check file/directory with such a path.
121         */

122
123         public void createAppGeneratedXMLPath() {
124                 String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
125                         mInstance.getApplicationGeneratedXMLPath(),
126                         mAppName
127                 };
128
129                 mAppGeneratedXMLPath = StringUtils.makeFilePath (onlyFolderNames, false);
130         }
131
132     
133     /**
134         Creates the absolute path String for storing all the generated JSPs of
135         this application.
136         Note that it does not create/check file/directory with such a path.
137     */

138     
139     public void createAppJSPPath() {
140         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
141             mInstance.getApplicationCompileJspPath(),
142             mAppName
143         };
144         
145         mAppJSPPath = StringUtils.makeFilePath (onlyFolderNames, false);
146     }
147
148     /**
149         Returns the absolute path for the all the stubs within this application.
150         Note that it does not create/check file/directory with such a path.
151     */

152     
153     public String JavaDoc getAppJSPPath() {
154         assert StringUtils.ok(mAppJSPPath);
155         return mAppJSPPath;
156     }
157
158     /**
159         Returns the absolute path for the all the stubs within this application.
160         Note that it does not create/check file/directory with such a path.
161     */

162     
163     public String JavaDoc getAppStubPath() {
164         return mAppStubPath;
165     }
166
167         /**
168                 Returns the absolute path for the all the generated xml within this application.
169                 Note that it does not create/check file/directory with such a path.
170         */

171
172         public String JavaDoc getAppGeneratedXMLPath() {
173                 return mAppGeneratedXMLPath;
174         }
175         
176         /**
177                 Creates the path to this application's java-web-start directory.
178         */

179         
180         private void createJavaWebStartPath() {
181         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
182             mInstance.getJavaWebStartPath(),
183             mAppName
184         };
185         
186         mJavaWebStartPath = StringUtils.makeFilePath (onlyFolderNames, false);
187         }
188         
189         /**
190                 Returns the absolute path to the Java Web Start directory for this application.
191                 Note that it does not create/check file/directory with such a path.
192         */

193         
194         public String JavaDoc getJavaWebStartPath() {
195             return mJavaWebStartPath;
196         }
197         
198     public String JavaDoc toString()
199     {
200         return ObjectAnalyzer.toString(this);
201     }
202     
203     public static void main(String JavaDoc[] args)
204     {
205         //System.setProperty("com.sun.aas.instanceRoot", "/usr/appserv/instances");
206
InstanceEnvironment env = new InstanceEnvironment("foo");
207         ApplicationEnvironment ae = new ApplicationEnvironment(env, "myapp");
208
209         _logger.log(Level.INFO,"core.appenv_dump");
210         _logger.log(Level.INFO,ae.toString());
211     }
212 }
213
Popular Tags