Qwylt

java.lang.module.spi
Class ServiceLocator

java.lang.Object
  extended by java.lang.module.ServiceSpace.Locator
      extended by java.lang.module.spi.ServiceLocator

public class ServiceLocator
extends ServiceSpace.Locator

A ServiceSpace.Locator that uses ClassSpace.getServiceProviders(String) to find service implementations. Requires a default constructor on all service implementation classes and will cache service instances that are singletons, specified by:

Since:
Feb 4, 2010
Author:
Bryan Atsatt. Copyright (c) 2010 Oracle.

Nested Class Summary
static interface ServiceLocator.Factory
          A factory for new service instances.
 
Field Summary
static ServiceLocator.Factory DEFAULT_FACTORY
          A factory that requires a default constructor.
 
Constructor Summary
ServiceLocator()
          Constructor.
ServiceLocator(ServiceLocator.Factory factory)
          Constructor.
 
Method Summary
<T> T
getService(ServiceType<T> type, ServiceSpace space)
          Returns or creates a service instance of the specified type.
<T> boolean
getServices(ServiceType<T> type, ServiceSpace space, java.util.List<T> result)
          Returns or creates all service instances of the specified type.
static ServiceSpace newServiceSpace(Module module)
          Returns a new ServiceSpace for the specified Module.
 
Methods inherited from class java.lang.module.ServiceSpace.Locator
getCachedServices
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FACTORY

public static ServiceLocator.Factory DEFAULT_FACTORY
A factory that requires a default constructor.

Constructor Detail

ServiceLocator

public ServiceLocator()
Constructor. Uses the default factory.


ServiceLocator

public ServiceLocator(ServiceLocator.Factory factory)
Constructor.

Parameters:
factory - The factory to use.
Method Detail

newServiceSpace

public static ServiceSpace newServiceSpace(Module module)
Returns a new ServiceSpace for the specified Module.

Parameters:
module - The module.
Returns:
The new ServiceSpace.

getService

public <T> T getService(ServiceType<T> type,
                        ServiceSpace space)
Description copied from class: ServiceSpace.Locator
Returns or creates a service instance of the specified type.

Specified by:
getService in class ServiceSpace.Locator
Parameters:
type - The service type.
space - The service space that is requesting the instance.
Returns:
The service or null if not found or could not be created.

getServices

public <T> boolean getServices(ServiceType<T> type,
                               ServiceSpace space,
                               java.util.List<T> result)
Description copied from class: ServiceSpace.Locator
Returns or creates all service instances of the specified type.

Specified by:
getServices in class ServiceSpace.Locator
Parameters:
type - The service type.
Returns:
The services, empty if none.

Qwylt

Send comments or questions to Bryan Atsatt