package net.sourceforge.javautil.web.server.deployer;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.javautil.common.io.VirtualArtifactNotFoundException;
import net.sourceforge.javautil.common.io.IVirtualDirectory;
import net.sourceforge.javautil.common.io.impl.SimplePath;
import net.sourceforge.javautil.common.reflection.cache.ClassCache;
import net.sourceforge.javautil.common.xml.XMLDocument;
import net.sourceforge.javautil.common.xml.annotation.XmlCollection;
import net.sourceforge.javautil.common.xml.annotation.XmlMap;
import net.sourceforge.javautil.common.xml.annotation.XmlTag;
import net.sourceforge.javautil.web.server.IWebServer;
import net.sourceforge.javautil.web.server.application.IWebApplication;
import net.sourceforge.javautil.web.server.application.ext.IWebApplicationExtension;
/**
* This allows for the declaration of {@link IWebServer} independent
* information.
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: WebApplicationServerDescriptor.java 2298 2010-06-16 00:20:18Z ponderator $
*/
@XmlTag(name="web-server")
public class WebApplicationServerDescriptor {
/**
* @param directory The root directory of a {@link IWebApplication}.
* @return A web app server descriptor if it exists, otherwise null
*/
public static WebApplicationServerDescriptor get (IVirtualDirectory directory) {
try {
return XMLDocument.read(directory.getFile(new SimplePath("WEB-INF/web-server.xml")), WebApplicationServerDescriptor.class);
} catch (VirtualArtifactNotFoundException e) {
return null;
}
}
/**
* The host the application should be deployed to
*/
protected String host;
/**
* The context path for the application
*/
protected String contextPath;
/**
* True if the application should be automatically restarted when class changes are detected, otherwise false
*/
protected boolean autoRestart = true;
/**
* The extensions for this application
*/
protected List<WebApplicationExtensionDescriptor> extensions = new ArrayList<WebApplicationExtensionDescriptor>();
/**
* @return The #host
*/
public String getHost() { return host; }
public void setHost(String host) { this.host = host; }
/**
* @return The {@link #contextPath}
*/
public String getContextPath() { return contextPath; }
public void setContextPath(String path) { this.contextPath = path; }
/**
* @return The {@link #autoRestart} flag
*/
public boolean isAutoRestart() { return autoRestart; }
public void setAutoRestart(boolean autoRestart) { this.autoRestart = autoRestart; }
/**
* @return The {@link #extensions}
*/
@XmlTag(name="extension",collection=@XmlCollection(WebApplicationExtensionDescriptor.class))
public List<WebApplicationExtensionDescriptor> getExtensions() { return extensions; }
public void setExtensions(List<WebApplicationExtensionDescriptor> extensions) { this.extensions = extensions; }
/**
* @param extension The extension for which to find a descriptor
* @return The descriptor, or null if none defined for the extension
*/
public WebApplicationExtensionDescriptor getDescriptorFor (IWebApplicationExtension extension) {
for (WebApplicationExtensionDescriptor descriptor : this.extensions) {
if (descriptor.getName().equals(extension.getName())) return descriptor;
}
return null;
}
/**
* A descriptor for {@link IWebApplicationExtension}'s
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: WebApplicationServerDescriptor.java 2298 2010-06-16 00:20:18Z ponderator $
*/
public static class WebApplicationExtensionDescriptor {
protected String name;
protected String className;
protected Map<String, Object> settings;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getClassName() { return className; }
public void setClassName(String className) { this.className = className; }
@XmlTag(name="setting",concreteType=LinkedHashMap.class,map=@XmlMap())
public Map<String, Object> getSettings() { return settings; }
public void setSettings(Map<String, Object> settings) { this.settings = settings; }
}
}