package org.jboss.services.deployment;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.jboss.system.ListenerServiceMBeanSupport;
public class DeploymentService
extends ListenerServiceMBeanSupport
implements DeploymentServiceMBean
{
public static final String DEFAULT_TEMPLATE_DIR = "conf/templates";
public static final String DEFAULT_UNDEPLOY_DIR = "undeploy";
public static final String DEFAULT_DEPLOY_DIR = "deploy";
private DeploymentManager manager;
private String templateDir;
private String undeployDir;
private String deployDir;
public DeploymentService()
{
templateDir = DEFAULT_TEMPLATE_DIR;
undeployDir = DEFAULT_UNDEPLOY_DIR;
deployDir = DEFAULT_DEPLOY_DIR;
}
public void setTemplateDir(String templateDir)
{
this.templateDir = templateDir;
}
public String getTemplateDir()
{
return templateDir;
}
public String getUndeployDir()
{
return undeployDir;
}
public void setUndeployDir(String undeployDir)
{
this.undeployDir = undeployDir;
}
public String getDeployDir()
{
return deployDir;
}
public void setDeployDir(String deployDir)
{
this.deployDir = deployDir;
}
public Set listModuleTemplates()
{
return manager.listModuleTemplates();
}
public List getTemplatePropertyInfo(String template)
throws Exception
{
return manager.getTemplatePropertyInfo(template);
}
public String createModule(String module, String template, HashMap properties)
throws Exception
{
return manager.createModule(module, template, properties);
}
public String createModule(String module, String template, String[] properties)
throws Exception
{
HashMap map = new HashMap();
for (int i = 0; i < properties.length; i++)
{
StringTokenizer st = new StringTokenizer(properties[i], "=");
String key = st.nextToken();
String value = st.nextToken();
if (value.indexOf('|') >= 0)
{
StringTokenizer st2 = new StringTokenizer(value, "|");
int tokens = st2.countTokens();
String[] array = new String[tokens];
for (int j = 0; j < tokens; j++)
array[j] = st2.nextToken();
map.put(key, array);
}
else
{
map.put(key, value);
}
}
return manager.createModule(module, template, map);
}
public boolean removeModule(String module)
{
return manager.removeModule(module);
}
public void deployModuleAsynch(String module)
throws Exception
{
manager.moveToDeployDir(module);
}
public URL getDeployedURL(String module)
throws Exception
{
return manager.getDeployedURL(module);
}
public void undeployModuleAsynch(String module)
throws Exception
{
manager.moveToModuleDir(module);
}
public URL getUndeployedURL(String module)
throws Exception
{
return manager.getUndeployedURL(module);
}
public boolean uploadLibrary(URL src, String filename)
{
return LibraryManager.getInstance().uploadLibrary(src, filename);
}
public void startService()
throws Exception
{
manager = new DeploymentManager(templateDir, undeployDir, deployDir, log);
}
public void stopService()
{
manager = null;
}
}