-package org.wamblee.system;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-public class DefaultServiceRegistry implements ServiceRegistry {
-
- private int _count;
- private Map<String, Service> _services;
-
- public DefaultServiceRegistry() {
- _count = 0;
- _services = new HashMap<String, Service>();
- }
-
- @Override
- public synchronized Service register(ProvidedInterface aDescriptor,
- Object aService) {
- _count++;
- String id = "" + _count;
- Service svc = new DefaultService(id, aDescriptor, aService);
- _services.put(id, svc);
- return svc;
- }
-
- @Override
- public void remove(Service aService) {
- Service svc = _services.remove(aService.getId());
- if ( svc == null ) {
- throw new IllegalArgumentException("Service '" + aService.getId() + "' does not exist");
- }
- }
-
- @Override
- public synchronized Service find(String aId) {
- return _services.get(aId);
- }
-
- @Override
- public Service[] listAllServices() {
- return new ArrayList<Service>(_services.values())
- .toArray(new Service[0]);
- }
-}