1 23 24 package com.sun.enterprise.instance; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import java.util.Set ; 29 import java.util.Properties ; 30 import java.util.Enumeration ; 31 import java.util.logging.Level ; 32 import java.io.File ; 33 import java.io.IOException ; 34 35 import javax.enterprise.deploy.shared.ModuleType ; 36 37 import com.sun.enterprise.config.ConfigBean; 38 import com.sun.enterprise.config.ConfigContext; 39 import com.sun.enterprise.config.ConfigException; 40 import com.sun.enterprise.config.serverbeans.ApplicationRef; 41 import com.sun.enterprise.config.serverbeans.Applications; 42 import com.sun.enterprise.config.serverbeans.Server; 43 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 44 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 45 import com.sun.enterprise.config.serverbeans.WebModule; 46 import com.sun.enterprise.deployment.Application; 47 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 48 import com.sun.enterprise.deployment.archivist.WebArchivist; 49 import com.sun.enterprise.deployment.archivist.WebArchivist; 50 import com.sun.enterprise.deployment.backend.DeployableObjectInfo; 51 import com.sun.enterprise.deployment.backend.DeployableObjectType; 52 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 53 import com.sun.enterprise.deployment.Descriptor; 54 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 55 import com.sun.enterprise.deployment.util.ModuleContentLinker; 56 import com.sun.enterprise.deployment.util.ModuleDescriptor; 57 import com.sun.enterprise.deployment.WebBundleDescriptor; 58 import com.sun.enterprise.util.io.FileUtils; 59 import com.sun.enterprise.util.RelativePathResolver; 60 import com.sun.enterprise.util.SystemPropertyConstants; 61 62 public class WebModulesManager extends ModulesManager { 63 public WebModulesManager(InstanceEnvironment env) throws ConfigException { 64 super(env, true); 65 } 66 67 public WebModulesManager(InstanceEnvironment env, 68 boolean useBackupServerXml) throws ConfigException { 69 super(env, useBackupServerXml); 70 WebModule[] jArray = ((Applications)configBean).getWebModule(); 72 if(jArray!=null) { 73 for(int i=0;i<jArray.length;i++) { 74 jArray[i].setConfigContext(configContext); 75 jArray[i].setXPath(ServerXPathHelper.getWebModuleIdXpathExpression(jArray[i].getName())); 76 } 77 } 78 80 } 81 82 85 public ModuleType getModuleType() { 86 return ModuleType.WAR; 87 } 88 89 private WebModule getWebModule(String modId) throws ConfigException { 90 WebModule mod = (WebModule) 91 ((Applications)this.configBean).getWebModuleByName(modId); 92 93 if(mod == null) 94 throw new ConfigException(Localizer.getValue(ExceptionType.NO_SUCH_WEB_MOD)); 95 96 return mod; 97 98 } 99 100 103 public WebModule[] listWebModules() throws ConfigException { 104 WebModule[] modules = ((Applications)this.configBean).getWebModule(); 105 106 if (modules == null) { 107 return new WebModule[0]; 108 } 109 110 ArrayList list = new ArrayList (); 111 for (int i=0; i<modules.length; i++) { 112 if ( isReferenced(modules[i].getName()) ) { 115 list.add(modules[i]); 116 } 117 } 118 WebModule[] refList = new WebModule[list.size()]; 120 return ( (WebModule[]) list.toArray(refList) ); 121 } 122 123 127 public List listIds() { 128 129 ArrayList arr = new ArrayList (); 130 WebModule[] mods = ((Applications)this.configBean).getWebModule(); 131 132 if(mods == null) return arr; 134 135 136 for (int i=0;i<mods.length;i++) { 137 String name = mods[i].getName(); 138 if ( isReferenced(name) ) { 141 arr.add(name); 142 } 143 } 144 return arr; 145 } 146 147 public void remove(String modId) throws ConfigException { 148 WebModule backEm = (WebModule) 149 ((Applications)configBean).getWebModuleByName(modId); 150 ((Applications)configBean).removeWebModule(backEm); 151 } 152 153 protected boolean isRegistered(String modId, ConfigBean bean) { 154 ConfigBean cb = null; 155 try { 156 cb = ((Applications)bean).getWebModuleByName(modId); 157 } catch(Exception cn) { 158 } 159 160 if(cb != null) return true; 161 return false; 162 } 163 164 public boolean isEnabled(String modId) throws ConfigException{ 165 return getWebModule(modId).isEnabled(); 166 } 167 168 173 public boolean isSystem(String modId) throws ConfigException{ 174 WebModule wm = getWebModule(modId); 175 String resourceType = wm.getObjectType(); 176 if(resourceType.startsWith(SYSTEM_PREFIX)) 177 return true; 178 else 179 return false; 180 } 181 182 187 public boolean isSystemAdmin(String modId) throws ConfigException{ 188 WebModule wm = getWebModule(modId); 189 String resourceType = wm.getObjectType(); 190 if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX)) 191 return true; 192 else 193 return false; 194 } 195 196 public void setEnable(String modId, boolean enable) throws ConfigException{ 197 getWebModule(modId).setEnabled(enable); 198 } 199 200 206 public void setOptionalAttributes(String modId, Properties optionalAttributes) 207 throws ConfigException { 208 if(optionalAttributes!=null) { 209 WebModule wm = getWebModule(modId); 210 Enumeration tags = optionalAttributes.keys(); 211 while(tags.hasMoreElements()) 212 { 213 String tag = (String )tags.nextElement(); 214 String value = optionalAttributes.getProperty(tag); 215 wm.setAttributeValue(tag, value); 216 } 217 } 218 } 219 220 public String getLocation(String name) throws ConfigException { 221 WebModule webModule = (WebModule) 222 ((Applications)this.configBean).getWebModuleByName(name); 223 String location = null; 224 if (webModule != null) 225 location = webModule.getLocation(); 226 return resolvePath(location); 227 } 228 229 public void setLocation(String name, String location) throws ConfigException { 230 WebModule webModule = (WebModule) 231 ((Applications)this.configBean).getWebModuleByName(name); 232 if (webModule != null) 233 webModule.setLocation(location); 234 } 235 236 public String getJSPLocation(String name){ 238 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 239 DeployableObjectType.WEB); 240 return menv.getModuleJSPPath(); 241 } 242 243 public String getGeneratedXMLLocation(String name){ 244 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 245 DeployableObjectType.WEB); 246 return menv.getModuleGeneratedXMLPath(); 247 } 248 249 public String getStubLocation(String name){ 250 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 251 DeployableObjectType.WEB); 252 return menv.getModuleStubPath(); 253 } 254 255 public String getDescription(String modId) throws ConfigException { 256 return getWebModule(modId).getDescription(); 257 } 258 259 public void setDescription(String modId, String desc) 260 throws ConfigException { 261 getWebModule(modId).setDescription(desc); 262 } 263 264 public String getVirtualServers(String modId) throws ConfigException { 265 Server server = ServerBeansFactory.getServerBean(configContext); 266 ApplicationRef ar = server.getApplicationRefByRef(modId); 267 return ar.getVirtualServers(); 268 } 269 277 278 public String getContextRoot(String modId) throws ConfigException { 279 return getWebModule(modId).getContextRoot(); 280 } 281 282 public void setContextRoot(String modId, String value) 283 throws ConfigException { 284 getWebModule(modId).setContextRoot(value); 285 } 286 287 299 public Application getDescriptor(String modId, ClassLoader cl, 300 String moduleLoc, boolean validateXML) throws ConfigException { 301 Application app = getDescriptor(modId, moduleLoc, validateXML); 302 app.setClassLoader(cl); 303 return app; 304 } 305 306 317 public Application getDescriptor(String modId, String modDir) 318 throws ConfigException { 319 320 return getDescriptor(modId, modDir, false); 321 } 322 323 335 public Application getDescriptor(String modId, String modDir, 336 boolean validateXml) throws ConfigException { 337 338 Application application = getRegisteredDescriptor(modId); 339 if (application!=null) { 340 return application; 341 } 342 try { 343 WebArchivist webArchivist = new WebArchivist(); 344 webArchivist.setXMLValidation(validateXml); 345 346 FileArchive archive = new FileArchive(); 347 if (isSystemAdmin(modId)) { 352 archive.open(modDir); 353 } else { 354 String xmlDir = getGeneratedXMLLocation(modId); 355 if (FileUtils.safeIsDirectory(xmlDir)) { 356 archive.open(xmlDir); 357 } else { 358 _logger.log(Level.WARNING, "core.no_xmldir", 360 new Object []{xmlDir, modDir}); 361 archive.open(modDir); 362 } 363 } 364 application = ApplicationArchivist.openArchive(modId, webArchivist, archive, true); 365 if(!isSystemAdmin(modId) && !isSystem(modId)) { 366 readPersistenceDeploymentDescriptors(modDir, application); 369 } 370 application.setGeneratedXMLDirectory(getGeneratedXMLLocation(modId)); 371 372 if (!application.getWebServiceDescriptors().isEmpty()) { 373 ModuleContentLinker visitor = new ModuleContentLinker(archive); 374 application.visit((com.sun.enterprise.deployment.util.ApplicationVisitor) visitor); 375 } 376 377 registerDescriptor(modId, application); 378 379 return application; 380 } catch (IOException ioe) { 381 throw new ConfigException(Localizer.getValue( 382 ExceptionType.IO_ERROR_LOADING_DD, modId), ioe); 383 } catch (Throwable t) { 384 throw new ConfigException(Localizer.getValue( 385 ExceptionType.FAIL_DD_LOAD, modId), t); 386 } 387 } 388 } 389 | Popular Tags |