ServiceReference[] references = new ServiceReference[0];
try {
references = bundleContext.getServiceReferences(EventHandler.class.getName(), EventHandler.MANAGED_FILTER);
if (references != null && references.length > 0) {
for (ServiceReference ref : references) {
EventHandler handler = (EventHandler) bundleContext.getService(ref);
if (command.getHandlerName() == null) {
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name());
} else {
if (command.getHandlerName().equals(handler.getClass().getName())) {
if (command.getStatus() != null) {
if (command.getStatus()) {
// persist the handler switch status to configuration admin
persist(handler.getClass().getName(), SwitchStatus.ON);
handler.getSwitch().turnOn();
} else {
// persist the handler switch status to configuration admin
persist(handler.getClass().getName(), SwitchStatus.OFF);
handler.getSwitch().turnOff();
}
}
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name());
break;
}
}
}
}