package net.sourceforge.javautil.web.server.deployer;
import net.sourceforge.javautil.common.ArchiveUtil;
import net.sourceforge.javautil.common.io.IVirtualArtifact;
import net.sourceforge.javautil.common.io.IVirtualDirectory;
import net.sourceforge.javautil.common.io.IVirtualFile;
import net.sourceforge.javautil.common.io.impl.Directory;
import net.sourceforge.javautil.common.io.impl.DirectoryRoot;
import net.sourceforge.javautil.common.io.impl.SystemFile;
import net.sourceforge.javautil.common.io.impl.ZippedDirectory;
import net.sourceforge.javautil.deployer.artifact.IVirtualArtifactDeployer;
import net.sourceforge.javautil.deployer.artifact.VirtualArtifactDeployerException;
import net.sourceforge.javautil.deployer.artifact.IVirtualArtifactDeployment;
import net.sourceforge.javautil.deployer.artifact.IVirtualArtifactDeploymentPattern;
import net.sourceforge.javautil.deployer.artifact.impl.VirtualArtifactDeploymentBase;
import net.sourceforge.javautil.web.server.application.IWebApplication;
import net.sourceforge.javautil.web.server.application.impl.WebApplicationStandard;
import net.sourceforge.javautil.web.server.application.impl.VirtualDirectoryResolver;
/**
* This will recognize a compressed or expanded Web Application aRchive (WAR).
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: WebApplicationDeploymentPatternWAR.java 2316 2010-06-21 04:44:57Z ponderator $
*/
public class WebApplicationDeploymentPatternWAR implements IVirtualArtifactDeploymentPattern<IVirtualDirectory,WebApplicationDeployment<IVirtualDirectory>,WebApplicationDeployer> {
public WebApplicationDeployment<IVirtualDirectory> createDeployment(WebApplicationDeployer deployer, IVirtualArtifact artifact) {
IVirtualDirectory war = null;
if (artifact instanceof SystemFile && "war".equals( ((IVirtualFile)artifact).getExtension() )) {
war = new ZippedDirectory( (SystemFile) artifact );
} else if (artifact instanceof IVirtualDirectory && artifact.getName().endsWith(".war")) {
war = (IVirtualDirectory) artifact;
} else {
throw new VirtualArtifactDeployerException(deployer, artifact, "Cannot deploy the artifact as a web application: " + artifact);
}
Directory vwar = new DirectoryRoot();
vwar.link(war);
return new WebApplicationDeployment(vwar, deployer, war);
}
public boolean matches(IVirtualArtifact artifact) {
if (artifact instanceof SystemFile && "war".equals( ((IVirtualFile)artifact).getExtension() )) {
return true;
} else if (artifact instanceof IVirtualDirectory && artifact.getName().endsWith(".war")) {
return true;
}
return false;
}
}