blob: 6d80c872a5450df230afd19451be753457d49da7 [file] [log] [blame]
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.enterprise.web;
import com.sun.enterprise.config.serverbeans.Application;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.util.io.FileUtils;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl;
import java.io.File;
/**
* Represents the configuration parameters required in order to create
* and install a web module (web application) into the server runtime.
*/
public class WebModuleConfig {
// ----------------------------------------------------- Instance Variables
/**
* The config bean containing the properties specified in the web-module
* element in server.xml.
*/
private Application _wmBean = null;
/**
* The parent directory under which the work directory for files generated
* by the web application (i.e compiled JSP class files etc) resides.
*/
private String _baseDir = null;
/**
* The work directory
*/
private String workDir = null;
/**
* The directory under which the work directory for files generated
* by the web application (i.e compiled JSP class files etc) resides.
*/
private String _workDir = null;
/**
* The source directory for the web application
*/
private File _dir = null;
/**
* The objectType property
*/
private String _objectType = null;
/**
* The parent classloader for the web application.
*/
private ClassLoader _parentLoader = null;
/**
* Deployment descriptor information about the web application.
*/
private WebBundleDescriptorImpl _wbd = null;
/**
* keep a list of virtual servers that this webmodule is associated with
*/
private String _vsIDs;
// START S1AS 6178005
private String stubBaseDir;
// END S1AS 6178005
private ClassLoader _appClassLoader = null;
private DeploymentContext deploymentContext;
// ------------------------------------------------------------- Properties
public ClassLoader getAppClassLoader() {
return _appClassLoader;
}
public void setAppClassLoader(ClassLoader _appClassLoader) {
this._appClassLoader = _appClassLoader;
}
/**
* Set the elements of information specified in the web-module element
* in server.xml.
*/
public void setBean(Application wmBean) {
_wmBean = wmBean;
}
/**
* Return the configuration information specified in server.xml.
*/
public Application getBean() {
return _wmBean;
}
/**
* Return the name of the web application (as specified in server.xml)
*
* @return [$appID:]$moduleID
*/
public String getName() {
String name = null;
if (_wbd != null) {
name = _wbd.getModuleID();
}
return name;
}
/**
* Return the context path at which the web application is deployed.
*/
public String getContextPath() {
String ctxPath = null;
if (_wbd != null) {
ctxPath = _wbd.getContextRoot().trim();
// Don't prefix a / if this web module is the default one
// i.e. has an empty context-root
if ((ctxPath.length() > 0) && !ctxPath.startsWith("/")) {
ctxPath = "/" + ctxPath;
} else if (ctxPath.equals("/")) {
ctxPath = "";
}
}
return ctxPath;
}
/**
* Set the directory in which the web application is deployed.
*/
public void setLocation(File sourceDir) {
_dir = sourceDir;
}
/**
* Return the directory in which the web application is deployed.
*/
public File getLocation() {
return _dir;
}
/**
* Return the list of virtual servers to which the web application is
* deployed.
*/
public String getVirtualServers() {
return _vsIDs;
}
/**
* Return the list of virtual servers to which the web application is
* deployed.
*/
public void setVirtualServers(String virtualServers) {
_vsIDs = virtualServers;
}
/**
* Set the parent classloader for the web application.
*/
public void setParentLoader(ClassLoader parentLoader) {
_parentLoader = parentLoader;
}
/**
* Return the parent classloader for the web application.
*/
public ClassLoader getParentLoader() {
return _parentLoader;
}
/**
* Sets the deployment context for this web application.
*/
public void setDeploymentContext(DeploymentContext deploymentContext) {
synchronized (this) {
this.deploymentContext = deploymentContext;
}
}
/**
* Gets the deployment context of this web application.
*/
public DeploymentContext getDeploymentContext() {
synchronized (this) {
return deploymentContext;
}
}
/**
* Sets the work directory for this web application.
*/
public synchronized void setWorkDir(String workDir) {
this.workDir = workDir;
}
/**
* Gets the work directory for this web application.
*
* The work directory is either
* generated/jsp/$appID/$moduleID
* or
* generated/jsp/$moduleID
*/
public synchronized String getWorkDir() {
if (workDir == null) {
if (deploymentContext != null &&
deploymentContext.getScratchDir(
"jsp") != null) {
workDir = deploymentContext.getScratchDir("jsp").getPath();
} else {
workDir = getWebDir(_baseDir);
}
}
return workDir;
}
// START S1AS 6178005
/**
* Gets the stub path of this web application.
*
* @return Stub path of this web application
*/
public String getStubPath() {
return getWebDir(stubBaseDir);
}
// END S1AS 6178005
/**
* Sets the parent of the work directory for this web application.
*
* The actual work directory is a subdirectory named after
* the web application.
*
* @param baseDir The new base directory under which the actual work
* directory will be created
*/
public void setWorkDirBase(String baseDir) {
synchronized (this) {
_baseDir = baseDir;
}
}
// START S1AS 6178005
/**
* Sets the base directory of this web application's stub path.
*
* @param stubBaseDir Stub path
*/
public void setStubBaseDir(String stubBaseDir) {
this.stubBaseDir = stubBaseDir;
}
// END S1AS 6178005
/**
* Return the object representation of the deployment descriptor specified
* for the web application.
*/
public WebBundleDescriptorImpl getDescriptor() {
return _wbd;
}
/**
* Set the deployment descriptor object describing the contents of the
* web application.
*
* @param wbd The deployment descriptor object
*/
public void setDescriptor(WebBundleDescriptorImpl wbd) {
_wbd = wbd;
}
/**
* Return the objectType property
*/
public String getObjectType() {
return _objectType;
}
/**
* Set the objectType property.
*
* @param objectType objectType property
*/
public void setObjectType(String objectType) {
_objectType = objectType;
}
/*
* Appends this web module's id to the given base directory path, and
* returns it.
*
* @param baseDir Base directory path
*/
private String getWebDir(String baseDir) {
if (baseDir == null) {
return null;
}
StringBuilder dir = new StringBuilder(baseDir);
dir.append(File.separator);
com.sun.enterprise.deployment.Application app = _wbd.getApplication();
if (app != null && !app.isVirtual()) {
dir.append(FileUtils.makeFriendlyFilename(
app.getRegistrationName()));
dir.append(File.separator);
dir.append(FileUtils.makeFriendlyFilename(
_wbd.getModuleDescriptor().getArchiveUri()));
} else {
dir.append(FileUtils.makeLegalNoBlankFileName(
_wbd.getModuleID()));
}
return dir.toString();
}
}