// Assume this is a configuration descriptor and deploy it
if(log.isInfoEnabled()) {
log.info(sm.getString("hostConfig.deployDescriptor", file));
}
Context context = null;
try {
synchronized (digester) {
try {
context = (Context) digester.parse(contextXml);
if (context == null) {
log.error(sm.getString("hostConfig.deployDescriptor.error",
file));
return;
}
} finally {
digester.reset();
}
}
if (context instanceof Lifecycle) {
Class clazz = Class.forName(host.getConfigClass());
LifecycleListener listener =
(LifecycleListener) clazz.newInstance();
((Lifecycle) context).addLifecycleListener(listener);
}
context.setConfigFile(contextXml.getAbsolutePath());
context.setPath(contextPath);
// Add the associated docBase to the redeployed list if it's a WAR
boolean isExternalWar = false;
boolean isExternal = false;
if (context.getDocBase() != null) {
File docBase = new File(context.getDocBase());
if (!docBase.isAbsolute()) {
docBase = new File(appBase(), context.getDocBase());
}
// If external docBase, register .xml as redeploy first
if (!docBase.getCanonicalPath().startsWith(
appBase().getAbsolutePath() + File.separator)) {
isExternal = true;
deployedApp.redeployResources.put
(contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
new Long(docBase.lastModified()));
if (docBase.getAbsolutePath().toLowerCase().endsWith(".war")) {
isExternalWar = true;
}
} else {
log.warn(sm.getString("hostConfig.deployDescriptor.localDocBaseSpecified",
docBase));
// Ignore specified docBase
context.setDocBase(null);
}
}
host.addChild(context);
// Get paths for WAR and expanded WAR in appBase
String name = null;
String path = context.getPath();
if (path.equals("")) {
name = "ROOT";
} else {
if (path.startsWith("/")) {
name = path.substring(1);
} else {
name = path;
}
}
File expandedDocBase = new File(appBase(), name);
if (context.getDocBase() != null) {
// first assume docBase is absolute
expandedDocBase = new File(context.getDocBase());
if (!expandedDocBase.isAbsolute()) {
// if docBase specified and relative, it must be relative to appBase
expandedDocBase = new File(appBase(), context.getDocBase());
}
}
// Add the eventual unpacked WAR and all the resources which will be
// watched inside it
if (isExternalWar && unpackWARs) {
deployedApp.redeployResources.put(expandedDocBase.getAbsolutePath(),
new Long(expandedDocBase.lastModified()));
deployedApp.redeployResources.put
(contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
addWatchedResources(deployedApp, expandedDocBase.getAbsolutePath(), context);
} else {
// Find an existing matching war and expanded folder
if (!isExternal) {
File warDocBase = new File(expandedDocBase.getAbsolutePath() + ".war");
if (warDocBase.exists()) {
deployedApp.redeployResources.put(warDocBase.getAbsolutePath(),
new Long(warDocBase.lastModified()));
}
}
if (expandedDocBase.exists()) {
deployedApp.redeployResources.put(expandedDocBase.getAbsolutePath(),
new Long(expandedDocBase.lastModified()));
addWatchedResources(deployedApp,
expandedDocBase.getAbsolutePath(), context);
} else {
addWatchedResources(deployedApp, null, context);
}
// Add the context XML to the list of files which should trigger a redeployment
if (!isExternal) {
deployedApp.redeployResources.put
(contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
}
}
} catch (Throwable t) {
log.error(sm.getString("hostConfig.deployDescriptor.error",
file), t);
}
if (context != null && host.findChild(context.getName()) != null) {
deployed.put(contextPath, deployedApp);
}
}