Qwylt

java.lang.module
Class ServiceSpace

java.lang.Object
  extended by java.lang.module.ServiceSpace

public class ServiceSpace
extends java.lang.Object

A Module wrapper that creates and manages service instances.

Since:
Jan 24, 2010
Author:
Bryan Atsatt.

Nested Class Summary
static class ServiceSpace.Locator
          A locator for service instances.
 
Constructor Summary
ServiceSpace(Module module, ServiceSpace.Locator... locators)
          Constructor.
 
Method Summary
<T> boolean
addService(ServiceType<T> type, T service)
          Adds the specified service.
 Module getModule()
          Returns the module from which this instance loads service classes.
<T> T
getService(java.lang.Class<T> type)
          Returns or creates the first service instance of the specified type.
<T> T
getService(ServiceType<T> type)
          Returns or creates the first service instance of the specified type.
<T> java.util.List<T>
getServices(java.lang.Class<T> type)
          Returns or creates all service instances of the specified type.
<T> java.util.List<T>
getServices(ServiceType<T> type)
          Returns or creates all service instances of the specified type.
<T> boolean
removeService(ServiceType<T> type, T service)
          Removes the specified service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceSpace

public ServiceSpace(Module module,
                    ServiceSpace.Locator... locators)
Constructor.

Parameters:
module - The module from which this instance will load service classes.
locators - The locators to use to find service instances.
Method Detail

getModule

public Module getModule()
Returns the module from which this instance loads service classes.

Returns:
The class space.

getService

public <T> T getService(java.lang.Class<T> type)
Returns or creates the first service instance of the specified type.

Parameters:
type - The service type.
Returns:
The service, null if none.
Throws:
java.lang.IllegalArgumentException - if type is an array.

getService

public <T> T getService(ServiceType<T> type)
Returns or creates the first service instance of the specified type.

Parameters:
type - The service type.
Returns:
The service, null if none.

getServices

public <T> java.util.List<T> getServices(java.lang.Class<T> type)
Returns or creates all service instances of the specified type.

Parameters:
type - The service type.
Returns:
The services, empty if none.
Throws:
java.lang.IllegalArgumentException - if type is an array.

getServices

public <T> java.util.List<T> getServices(ServiceType<T> type)
Returns or creates all service instances of the specified type.

Parameters:
type - The service type.
Returns:
The services, empty if none.

addService

public <T> boolean addService(ServiceType<T> type,
                              T service)
Adds the specified service.

Parameters:
type - The service type.
service - The service.
Returns:
true if the service was not already present.

removeService

public <T> boolean removeService(ServiceType<T> type,
                                 T service)
Removes the specified service.

Parameters:
type - The service type.
service - The service.
Returns:
true if the service was found and removed.

Qwylt

Send comments or questions to Bryan Atsatt