package net.sf.invicta.handler;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
import net.sf.invicta.InvictaException;
import net.sf.invicta.api.Product;
/**
* Returns instructions for creating an application.xml file.
*/
public class DependAppModulesHandler extends InvictaBasicHandler {
private final static String MODULE_TYPE_EJB = "ejb";
private final static String MODULE_TYPE_JAVA = "java";
private final static String MODULE_TYPE_WEB = "web";
private final static String PRODUCT_TYPE_EJB = "ejb";
private final static String PRODUCT_TYPE_JAVA = "jar";
private final static String PRODUCT_TYPE_WEB = "war";
/**
*
*/
public String getName() {
return "dependAppModules";
}
/**
*
*/
public String handle(Map paramsMap) throws InvictaException {
return getDependModules();
}
/**
*
*/
public String handle(List params) throws InvictaException {
return getDependModules();
}
/**
*
*/
protected String getDependModules() {
String modulesStr = "";
// Add all products
for (Iterator productIter =
getComponent().getRecursiveProducts().iterator();
productIter.hasNext();) {
Product product = (Product)productIter.next();
if (product.getFile() != null) {
File file = new File(product.getFile());
if (product.getType().equals(PRODUCT_TYPE_EJB)) {
modulesStr += getEJBModule(file.getName());
} else if (product.getType().equals(PRODUCT_TYPE_JAVA)) {
modulesStr += getJavaModule(file.getName());
} else if (product.getType().equals(PRODUCT_TYPE_WEB)) {
modulesStr += getWebModule(
product.getAppName(), file.getName());
}
}
}
return modulesStr;
}
/**
*
*/
private String getWebModule(String name, String file) {
return "<module type=\"" + MODULE_TYPE_WEB + "\" file=\"" + file +
"\" name=\"" + name + "\"/>\n";
}
/**
*
*/
private String getJavaModule(String file) {
return "<module type=\"" + MODULE_TYPE_JAVA + "\" file=\"" + file +
"\"/>\n";
}
/**
*
*/
private String getEJBModule(String file) {
return "<module type=\"" + MODULE_TYPE_EJB + "\" file=\"" + file +
"\"/>\n";
}
}
|