report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Application application = applications.getApplication(applicationName);
if (application.isLifecycleModule()) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
ApplicationInfo appInfo = appRegistry.get(applicationName);
if (appInfo == null) {
report.setMessage(localStrings.getLocalString("application.not.enabled","Application {0} is not in an enabled state", applicationName));
return;
}
com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
if (app == null) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
Map<String, String> subComponents ;
Map<String, String> subComponentsMap = new HashMap<String, String>();
if (appname == null) {
subComponents = getAppLevelComponents(app, type, subComponentsMap);
} else {
BundleDescriptor bundleDesc = app.getModuleByUri(modulename);
if (bundleDesc == null) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidmodulename", "Invalid module name", appname, modulename));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
subComponents = getModuleLevelComponents(
bundleDesc, type, subComponentsMap);
}
// the type param can only have values "ejbs" and "servlets"
if (type != null) {
if (!type.equals("servlets") && !type.equals("ejbs")) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidtype", "The type option has invalid value {0}. It should have a value of servlets or ejbs.", type));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
List<String> subModuleInfos = new ArrayList<String>();
if (!app.isVirtual()) {
subModuleInfos = getSubModulesForEar(app, type);
}
int[] longestValue = new int[2];
for (Map.Entry<String, String> entry : subComponents.entrySet()) {
String key = entry.getKey();
if (key.length() > longestValue[0]) {
longestValue[0] = key.length();
}
String value = entry.getValue();
if (value.length() > longestValue[1]) {
longestValue[1] = value.length();
}
}
StringBuilder formattedLineBuf = new StringBuilder();
for (int j = 0; j < 2; j++) {
longestValue[j] += 2;
formattedLineBuf.append("%-")
.append(longestValue[j])
.append("s");
}
String formattedLine = formattedLineBuf.toString();
if (!terse && subComponents.isEmpty()) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
int i=0;
for (String key : subComponents.keySet()) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(
String.format(formattedLine,
new Object[]{key, subComponents.get(key)} ));
if (appname == null && !app.isVirtual()) {
// we use the property mechanism to provide
// support for JSR88 client
if (subModuleInfos.get(i) != null) {
childPart.addProperty("moduleInfo",
subModuleInfos.get(i));
}
}
if (resources) {
Module module = application.getModule(key);
if (module != null) {
ActionReport subReport = report.addSubActionsReport();
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
final ParameterMap parameters = new ParameterMap();
parameters.add("appname", application.getName());
parameters.add("modulename", module.getName());
inv.parameters(parameters).execute();
ActionReport.MessagePart subPart = subReport.getTopMessagePart();
for (ActionReport.MessagePart cp : subPart.getChildren()) {