List<MainMenuOption> options = new ArrayList<MainMenuOption>();
for (int index = 0; index < menuOptions.getLength(); index++) {
Node menuNode = menuOptions.item(index);
Element menuElement = (Element) menuNode;
String name = menuElement.getAttribute("name");
MainMenuOption option = new MainMenuOption();
option.setHtml(name);
if (menuElement.hasAttribute("commandClass")) {
String className = menuElement.getAttribute("commandClass");
try {
Object obj = ReflectionHelper.newInstance(className);
if (obj instanceof BaseCommand) {
option.setCommand((BaseCommand) obj);
} else {
option.setHtml(option.getHtml()+ "(" + i18n.NotOfType(className, "BaseCommand") + ")");
option.setEnabled(false);
}
} catch (Exception e) {
option.setHtml(option.getHtml() + i18n.Error(e.getLocalizedMessage()));
option.setEnabled(false);
}
} else {
option.setSubMenu(readMenuOptions(menuElement.getChildNodes()));
}
options.add(option);
}
return options;
}