throw new Exception("not a filesystem friendly module name: " + module);
log.info("createModule(module=" + module +
", template=" + template + ", properties=" + properties + ")");
ConfigInfo ci = (ConfigInfo)configMap.get(template);
if (ci == null)
throw new Exception("template does not exist: " + template);
// get optional package extension (e.g. .sar)
// and enforce it on the output package (file or directory)
File outputModule;
String extension = ci.getExtension();
if (extension == null || module.endsWith(extension))
outputModule = new File(this.undeployDir, module);
else
outputModule = new File(this.undeployDir, module + extension);
// check if module already exists in output dir
if (outputModule.exists())
throw new Exception("module already exist: " + outputModule);
String vmTemplate = ci.getTemplate();
// make sure we clean-up in case something goes wrong
try
{
// simple case - single descriptor package (e.g. xxx-service.xml)
if (vmTemplate != null )
{
VelocityContext ctx = createTemplateContext(ci, properties);
BufferedWriter out = new BufferedWriter(new FileWriter(outputModule));
try {
boolean success = ve.mergeTemplate(template + '/' + vmTemplate, ctx, out);
if (success == true)
{
String errorMsg = (String)ctx.get(TEMPLATE_ERROR_PARAM);
if (errorMsg.length() > 0)
throw new Exception("Template error: " + errorMsg);
else
log.debug("created module '" + outputModule.getName() + "' based on template '" + template + "'");
}
else
throw new Exception("Failed to create module '" + outputModule.getName());
}
finally
{
out.close();
}
}
else
{
// complex case - many descriptors and possibly files to copy
// now output will be a directory instead of a plain descriptor (e.g. xxx.sar)
VelocityContext ctx = createTemplateContext(ci, properties);
// deep copy files if copydir specified
String copydir = ci.getCopydir();
File sourceDir = new File(this.templateDir, template + '/' + copydir);
deepCopy(sourceDir, outputModule);
// go through all declared templates
List templateList = ci.getTemplateInfoList();
for (Iterator i = templateList.iterator(); i.hasNext(); )
{
TemplateInfo ti = (TemplateInfo)i.next();