public class DefaultServiceRegistry extends Object implements ServiceRegistry
ServiceRegistry implementation.
Subclasses can register services by:
add(Class, Object) to register a service instance.add(ServiceRegistry) to register a set of services.protected SomeService
createSomeService() { .... }.Service instances are created on demand. getFactory(Class) looks for a service instance which implements Factory<T> where T is the expected type.
Service registries are arranged in a hierarchy. If a service of a given type cannot be located, the registry uses its parent registry, if any, to locate the service.
| Constructor and Description |
|---|
DefaultServiceRegistry() |
DefaultServiceRegistry(ServiceRegistry parent) |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
add(Class<T> serviceType,
T serviceInstance)
Adds a service to this registry.
|
void |
add(ServiceRegistry nested)
Adds a set of services to this registry.
|
void |
close()
Closes all services for this registry.
|
<T> T |
get(Class<T> serviceType)
Locates the service of the given type.
|
<T> Factory<T> |
getFactory(Class<T> type)
Locates a factory which can create services of the given type.
|
<T> T |
newInstance(Class<T> type)
Creates a new service instance of the given type.
|
String |
toString() |
public DefaultServiceRegistry()
public DefaultServiceRegistry(ServiceRegistry parent)
public void add(ServiceRegistry nested)
public <T> void add(Class<T> serviceType, T serviceInstance)
public void close()
public <T> T get(Class<T> serviceType) throws IllegalArgumentException
ServiceRegistryget in interface ServiceRegistryT - The service type.serviceType - The service type.UnknownServiceException - When there is no service of the given type available.IllegalArgumentExceptionpublic <T> Factory<T> getFactory(Class<T> type)
ServiceRegistrygetFactory in interface ServiceRegistryT - The service type that the factory should create.type - The service type that the factory should create.public <T> T newInstance(Class<T> type)
ServiceRegistrynewInstance in interface ServiceRegistryT - The service type.type - The service typeCopyright © 2013. All rights reserved