// Assume this is a configuration descriptor and deploy it
if(log.isDebugEnabled()) {
log.debug(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 isWar = 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())) {
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")) {
isWar = 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(name);
File warDocBase = new File(name + ".war");
if (!expandedDocBase.isAbsolute()) {
expandedDocBase = new File(appBase(), name);
warDocBase = new File(appBase(), name + ".war");
}
// Add the eventual unpacked WAR and all the resources which will be
// watched inside it
if (isWar && 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 (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);
}
}