public void addService(Service service)
{
if (service == null)
{
// Cannot add null ''{0}'' to the ''{1}''
ConfigurationException ex = new ConfigurationException();
ex.setMessage(ConfigurationConstants.NULL_COMPONENT, new Object[]{"Service", "MessageBroker"});
throw ex;
}
String id = service.getId();
if (id == null)
{
// Cannot add ''{0}'' with null id to the ''{1}''
ConfigurationException ex = new ConfigurationException();
ex.setMessage(ConfigurationConstants.NULL_COMPONENT_ID, new Object[]{"Service", "MessageBroker"});
throw ex;
}
// No need to add if service is already added
if (getService(id) == service)
{
return;
}
// Do not allow multiple services with the same id
if (getService(id) != null)
{
// Cannot add a ''{0}'' with the id ''{1}'' that is already registered with the ''{2}''
ConfigurationException ex = new ConfigurationException();
ex.setMessage(ConfigurationConstants.DUPLICATE_COMPONENT_ID, new Object[]{"Service", id, "MessageBroker"});
throw ex;
}
// Do not allow multiple services of the same type
String type = service.getClass().getName();
if (getServiceByType(type) != null)
{
ConfigurationException ce = new ConfigurationException();
ce.setMessage(SERVICE_TYPE_EXISTS, new Object[] {type});
throw ce;
}
services.put(id, service);