try {
ContextAwareMenu menu = menuClass.newInstance();
if (menu.canHandle(context)) {
menu.addMenuListener(MenuFactory.createMenuListener(menu));
// Populate built-in menus and/or menu items
menu.initialize();
// Populate extended menus and/or menu items
MenuExtensionManager manager = MenuExtensionManager.getInstance();
for (String menubarPath : menu.getExtensionMenubarPaths()) {
List<MenuItemInfo> extendedMenus = manager.getExtendedMenus(menubarPath);
menu.addMenuItemInfos(menubarPath, extendedMenus);