KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
27
28 import com.sun.enterprise.config.ConfigBean;
29 import com.sun.enterprise.config.ConfigContext;
30 import com.sun.enterprise.config.ConfigException;
31 import com.sun.enterprise.config.serverbeans.AppclientModule;
32 import com.sun.enterprise.config.serverbeans.Applications;
33 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
34 import com.sun.enterprise.deployment.Application;
35 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
36 import com.sun.enterprise.deployment.archivist.AppClientArchivist;
37 import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
38 import com.sun.enterprise.deployment.backend.DeployableObjectInfo;
39 import com.sun.enterprise.deployment.backend.DeployableObjectType;
40 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
41 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
42
43 import java.io.IOException JavaDoc;
44 import java.util.ArrayList JavaDoc;
45 import java.util.Enumeration JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.logging.Level JavaDoc;
48 import java.util.Properties JavaDoc;
49 import java.util.Set JavaDoc;
50
51 //The RelativePathResolver is used to translate relative paths containing
52
//embedded system properties (e.g. ${com.sun.aas.instanceRoot}/applications)
53
//into absolute paths
54
import com.sun.enterprise.util.RelativePathResolver;
55 import com.sun.enterprise.util.SystemPropertyConstants;
56
57 import com.sun.enterprise.util.io.FileUtils;
58
59 /**
60  * Provides access to app client information per server instance.
61  */

62 public class AppclientModulesManager extends ModulesManager {
63     
64     public AppclientModulesManager(InstanceEnvironment env) throws ConfigException {
65         super(env, true);
66     }
67     
68     public AppclientModulesManager(InstanceEnvironment env, boolean useBackupServerXml) throws ConfigException {
69         super(env, useBackupServerXml);
70         
71         //FIXME: HACK START
72
AppclientModule[] jArray = ((Applications)configBean).getAppclientModule();
73     if(jArray!=null) {
74             for(int i=0;i<jArray.length;i++) {
75                 jArray[i].setConfigContext(configContext);
76         //jArray[i].setXPath(ServerXPathHelper.getAppIdXpathExpression(jArray[i].getName()));
77
jArray[i].setXPath(ServerXPathHelper.getAppClientModuleIdXpathExpression(jArray[i].getName()));
78             }
79     }
80     //FIXME: HACK END
81
}
82         
83     /**
84      * @return the module type this class is managing
85      */

86     public ModuleType JavaDoc getModuleType() {
87         return ModuleType.CAR;
88     }
89         
90     /**
91      * Returns an array of all applications deployed with the server.
92      */

93     public AppclientModule[] getAllApps() {
94         AppclientModule[] apps = ((Applications)this.configBean).getAppclientModule();
95         if(apps == null) return new AppclientModule[0];
96         
97         ArrayList JavaDoc list = new ArrayList JavaDoc();
98         for (int i=0; i<apps.length; i++) {
99             // add the modules to the list if it is referenced
100
// by this server
101
if ( isReferenced(apps[i].getName()) ) {
102                 list.add(apps[i]);
103             }
104         }
105         // returns an array of modules referenced by this server
106
AppclientModule[] refList = new AppclientModule[list.size()];
107         return ( (AppclientModule[]) list.toArray(refList) );
108     }
109     
110     /**
111      * Returns a list of all applications deployed with the server.
112      */

113     public List JavaDoc listIds() {
114         ArrayList JavaDoc arr = new ArrayList JavaDoc();
115         AppclientModule[] apps = ((Applications)this.configBean).getAppclientModule();
116         if(apps == null) return arr;
117             
118         for (int i=0;i<apps.length;i++) {
119             String JavaDoc name = apps[i].getName();
120             // adds the web module to the list if
121
// it is referenced by this server
122
if ( isReferenced(name) ) {
123                 arr.add(name);
124             }
125         }
126         return arr;
127     }
128     
129     public String JavaDoc getLocation(String JavaDoc appId) throws ConfigException {
130         AppclientModule app = (AppclientModule)
131         ((Applications)this.configBean).getAppclientModuleByName(appId);
132         return resolvePath(app.getLocation());
133     }
134     
135     
136     
137     /**
138      * There is no persistent state store in domain.xml
139      * Hence, return true always.
140      *
141      */

142     public boolean isEnabled(String JavaDoc appId) throws ConfigException {
143         return true;
144     }
145
146     /**
147      *Reports whether Java Web Start access is enabled for the specified app client.
148      *@param appId the module ID of the app client to check
149      *@return boolean indicating whether access is permitted
150      */

151     public boolean isJavaWebStartEnabled(String JavaDoc appId) throws ConfigException {
152         AppclientModule app = (AppclientModule) ((Applications)this.configBean).getAppclientModuleByName(appId);
153         return app.isJavaWebStartEnabled();
154     }
155     
156     /**
157      * Checks whether this application is a system app
158      *
159      * appclients are always non-system apps
160      *
161      * @return false
162      */

163     public boolean isSystem(String JavaDoc appId) throws ConfigException {
164         return false;
165     }
166
167     /**
168      * Checks whether this application is a system admin app
169      *
170      * appclients are always non-system apps
171      *
172      * @return false
173      */

174     public boolean isSystemAdmin(String JavaDoc appId) throws ConfigException {
175         return false;
176     }
177
178     public String JavaDoc getStubLocation(String JavaDoc name) {
179         ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name,
180                                                      DeployableObjectType.CAR);
181         return menv.getModuleStubPath();
182     }
183     
184     public String JavaDoc getGeneratedXMLLocation(String JavaDoc name){
185         ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name,
186                                                      DeployableObjectType.CAR);
187         return menv.getModuleGeneratedXMLPath();
188     }
189
190     protected boolean isRegistered(String JavaDoc appId, ConfigBean bean) {
191         ConfigBean cb = null;
192         try {
193             cb = ((Applications)bean).getAppclientModuleByName(appId);
194         } catch(Exception JavaDoc cn) {
195         }
196         
197         if(cb != null) return true;
198         return false;
199     }
200     
201     /**
202      * Removes the application information from the configuration file.
203      *
204      * @param appId a unique identifier for the application
205      */

206     public void remove(String JavaDoc appId) throws ConfigException {
207         AppclientModule backJa = (AppclientModule)
208             ((Applications)configBean).getAppclientModuleByName(appId);
209         ((Applications)configBean).removeAppclientModule(backJa);
210     }
211     
212     /**
213      * Identifies whether an application is enabled or disabled.
214      *
215      * Appclients do not need to have a persistent enable state
216      * Hence, this method does nothing for now.
217      *
218      * @param appId unique idenitifier for the application
219      * @param isEnabled flag for enabling or disabling the application
220      */

221     public void setEnable(String JavaDoc appId, boolean enabled)
222             throws ConfigException {
223         //Enabled is not persisted for appclients.
224
}
225
226     /**
227      * Set the location for an App
228      *
229      * @param appId unique idenitifier for the application
230      * @param location
231      */

232     public void setLocation(String JavaDoc appId, String JavaDoc location)
233             throws ConfigException {
234         getAppclientModule(appId).setLocation(location);
235     }
236     
237     
238     /**
239      * Set the optional attributes for an App
240      *
241      * This method is required by the base class.
242      * Since there are no optional attributes for appclient
243      * don't do anything in this method
244      *
245      * @param appId unique idenitifier for the application
246      * @param optionalAttributes - pairs tag/value to set
247      */

248     public void setOptionalAttributes(String JavaDoc appId, Properties JavaDoc optionalAttributes)
249             throws ConfigException {
250                 //Not required for appclient.
251
}
252         
253     public String JavaDoc getDescription(String JavaDoc id) throws ConfigException {
254         return getAppclientModule(id).getDescription();
255     }
256     
257     private AppclientModule getAppclientModule(String JavaDoc appId)
258             throws ConfigException {
259
260         AppclientModule app = (AppclientModule)
261             ((Applications)this.configBean).getAppclientModuleByName(appId);
262
263         if(app == null)
264             throw new ConfigException(
265                 Localizer.getValue(ExceptionType.APP_NOT_EXIST));
266         return app;
267         
268     }
269     
270     public void setDescription(String JavaDoc id, String JavaDoc desc) throws ConfigException {
271         getAppclientModule(id).setDescription(desc);
272     }
273     
274     /**
275      * Returns the deployment descriptor object for the connector module
276      * in the specified directory.
277      *
278      * @param modId web module id
279      * @param modDir The directory containing the web module
280      * @param validateXml use validating parser when true
281      * @param verify true indicates that verifier option is ON
282      *
283      * @return the deployment descriptor object for this web module
284      *
285      * @throws ConfigException if unable to load the deployment descriptor
286      */

287      public Application getDescriptor(String JavaDoc modId, ClassLoader JavaDoc cl, String JavaDoc modDir,
288          boolean validateXml) throws ConfigException {
289      
290         Application application = getRegisteredDescriptor(modId);
291         if (application!=null) {
292             application.setClassLoader(cl);
293             return application;
294         }
295      try {
296          AppClientArchivist appClientArchivist = new AppClientArchivist();
297          appClientArchivist.setXMLValidation(validateXml);
298              appClientArchivist.setClassLoader(cl);
299          
300          FileArchive archive = new FileArchive();
301              // if is system predeployed app, load from original mod dir
302
// else load from generated/xml dir
303
// print a warning if generated/xml dir is not there
304
if (isSystemAdmin(modId)) {
305                 archive.open(modDir);
306              } else {
307                  String JavaDoc xmlDir = getGeneratedXMLLocation(modId);
308                  if (FileUtils.safeIsDirectory(xmlDir)) {
309                      archive.open(xmlDir);
310                  } else {
311                      // log a warning message in the server log
312
_logger.log(Level.WARNING, "core.no_xmldir",
313                          new Object JavaDoc[]{xmlDir, modDir});
314
315                      archive.open(modDir);
316                  }
317              }
318          application = ApplicationArchivist.openArchive(modId, appClientArchivist, archive, true);
319          application.setClassLoader(cl);
320              application.setGeneratedXMLDirectory(getGeneratedXMLLocation(modId));
321              registerDescriptor(modId, application);
322          return application;
323          
324      } catch (IOException JavaDoc ioe) {
325          throw new ConfigException(Localizer.getValue(
326          ExceptionType.IO_ERROR_LOADING_DD, modId), ioe);
327      } catch (Throwable JavaDoc t) {
328          throw new ConfigException(Localizer.getValue(
329          ExceptionType.FAIL_DD_LOAD, modId), t);
330      }
331      }
332 }
333
Popular Tags