Component component = ComponentBuilder.build(bundle, bundleContext);
if (component == null) {
return;
} else {
ServiceReference reference = bundleContext.getServiceReference(CarbonUIDefinitions.class.getName());
CarbonUIDefinitions carbonUIDefinitions = null;
if (reference != null) {
carbonUIDefinitions = (CarbonUIDefinitions) bundleContext.getService(reference);
}
if (carbonUIDefinitions != null) {
if (log.isDebugEnabled()) {
log.debug("Found carbonUIDefinitions in OSGi context");
}
if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) {
if (log.isDebugEnabled()) {
log.debug("Adding UI component using existing Carbon Definition");
}
ArrayList<Menu> menusToAdd = new ArrayList<Menu>();
for (Menu menu : component.getMenus()) {
// Prevent adding the menu if it is defined to be hidden.
if (!(hideMenuIds.contains(menu.getId()))) {
menusToAdd.add(menu);
}
}
if(menusToAdd.size() > 0) {
Menu[] menus = new Menu[menusToAdd.size()];
menus = menusToAdd.toArray(menus);
carbonUIDefinitions.addMenuItems(menus);
}
carbonUIDefinitions.addServletItems(component.getServlets());
carbonUIDefinitions.addUnauthenticatedUrls(component.getUnauthenticatedUrlList());
carbonUIDefinitions.addSkipTilesUrls(component.getSkipTilesUrlList());
carbonUIDefinitions.addHttpUrls(component.getSkipHttpsUrlList());
carbonUIDefinitions.addContexts(component.getContextsList());
} else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)) {
if (log.isDebugEnabled()) {
log.debug("Removing UI component using existing carbon definition");
}
carbonUIDefinitions.removeMenuItems(component.getMenus());
carbonUIDefinitions.removeServletItems(component.getServlets());
carbonUIDefinitions.removeUnauthenticatedUrls(component.getUnauthenticatedUrlList());
carbonUIDefinitions.removeSkipTilesUrls(component.getSkipTilesUrlList());
carbonUIDefinitions.removeHttpUrls(component.getSkipHttpsUrlList());
carbonUIDefinitions.removeContexts(component.getContextsList());
}
} else {
if (log.isDebugEnabled()) {
log.debug("CarbonUIDefinitions is NULL. Registering new...");
}
carbonUIDefinitions = new CarbonUIDefinitions();
carbonUIDefinitions.addMenuItems(component.getMenus());
carbonUIDefinitions.addServletItems(component.getServlets());
carbonUIDefinitions.addUnauthenticatedUrls(component.getUnauthenticatedUrlList());
carbonUIDefinitions.addSkipTilesUrls(component.getSkipTilesUrlList());
carbonUIDefinitions.addHttpUrls(component.getSkipHttpsUrlList());
carbonUIDefinitions.addContexts(component.getContextsList());
bundleContext.registerService(CarbonUIDefinitions.class.getName(), carbonUIDefinitions, null);
}
}
//processing servlet definitions
processServletDefinitions(component,action);