1 23 24 package com.sun.enterprise.instance; 25 26 import javax.enterprise.deploy.shared.ModuleType ; 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 ; 44 import java.util.ArrayList ; 45 import java.util.Enumeration ; 46 import java.util.List ; 47 import java.util.logging.Level ; 48 import java.util.Properties ; 49 import java.util.Set ; 50 51 import com.sun.enterprise.util.RelativePathResolver; 55 import com.sun.enterprise.util.SystemPropertyConstants; 56 57 import com.sun.enterprise.util.io.FileUtils; 58 59 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 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.getAppClientModuleIdXpathExpression(jArray[i].getName())); 78 } 79 } 80 } 82 83 86 public ModuleType getModuleType() { 87 return ModuleType.CAR; 88 } 89 90 93 public AppclientModule[] getAllApps() { 94 AppclientModule[] apps = ((Applications)this.configBean).getAppclientModule(); 95 if(apps == null) return new AppclientModule[0]; 96 97 ArrayList list = new ArrayList (); 98 for (int i=0; i<apps.length; i++) { 99 if ( isReferenced(apps[i].getName()) ) { 102 list.add(apps[i]); 103 } 104 } 105 AppclientModule[] refList = new AppclientModule[list.size()]; 107 return ( (AppclientModule[]) list.toArray(refList) ); 108 } 109 110 113 public List listIds() { 114 ArrayList arr = new ArrayList (); 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 name = apps[i].getName(); 120 if ( isReferenced(name) ) { 123 arr.add(name); 124 } 125 } 126 return arr; 127 } 128 129 public String getLocation(String appId) throws ConfigException { 130 AppclientModule app = (AppclientModule) 131 ((Applications)this.configBean).getAppclientModuleByName(appId); 132 return resolvePath(app.getLocation()); 133 } 134 135 136 137 142 public boolean isEnabled(String appId) throws ConfigException { 143 return true; 144 } 145 146 151 public boolean isJavaWebStartEnabled(String appId) throws ConfigException { 152 AppclientModule app = (AppclientModule) ((Applications)this.configBean).getAppclientModuleByName(appId); 153 return app.isJavaWebStartEnabled(); 154 } 155 156 163 public boolean isSystem(String appId) throws ConfigException { 164 return false; 165 } 166 167 174 public boolean isSystemAdmin(String appId) throws ConfigException { 175 return false; 176 } 177 178 public String getStubLocation(String name) { 179 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 180 DeployableObjectType.CAR); 181 return menv.getModuleStubPath(); 182 } 183 184 public String getGeneratedXMLLocation(String name){ 185 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 186 DeployableObjectType.CAR); 187 return menv.getModuleGeneratedXMLPath(); 188 } 189 190 protected boolean isRegistered(String appId, ConfigBean bean) { 191 ConfigBean cb = null; 192 try { 193 cb = ((Applications)bean).getAppclientModuleByName(appId); 194 } catch(Exception cn) { 195 } 196 197 if(cb != null) return true; 198 return false; 199 } 200 201 206 public void remove(String appId) throws ConfigException { 207 AppclientModule backJa = (AppclientModule) 208 ((Applications)configBean).getAppclientModuleByName(appId); 209 ((Applications)configBean).removeAppclientModule(backJa); 210 } 211 212 221 public void setEnable(String appId, boolean enabled) 222 throws ConfigException { 223 } 225 226 232 public void setLocation(String appId, String location) 233 throws ConfigException { 234 getAppclientModule(appId).setLocation(location); 235 } 236 237 238 248 public void setOptionalAttributes(String appId, Properties optionalAttributes) 249 throws ConfigException { 250 } 252 253 public String getDescription(String id) throws ConfigException { 254 return getAppclientModule(id).getDescription(); 255 } 256 257 private AppclientModule getAppclientModule(String 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 id, String desc) throws ConfigException { 271 getAppclientModule(id).setDescription(desc); 272 } 273 274 287 public Application getDescriptor(String modId, ClassLoader cl, String 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 (isSystemAdmin(modId)) { 305 archive.open(modDir); 306 } else { 307 String xmlDir = getGeneratedXMLLocation(modId); 308 if (FileUtils.safeIsDirectory(xmlDir)) { 309 archive.open(xmlDir); 310 } else { 311 _logger.log(Level.WARNING, "core.no_xmldir", 313 new Object []{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 ioe) { 325 throw new ConfigException(Localizer.getValue( 326 ExceptionType.IO_ERROR_LOADING_DD, modId), ioe); 327 } catch (Throwable t) { 328 throw new ConfigException(Localizer.getValue( 329 ExceptionType.FAIL_DD_LOAD, modId), t); 330 } 331 } 332 } 333 | Popular Tags |