portal.services
Class ServiceLocator

java.lang.Object
  extended byportal.services.ServiceLocator
Direct Known Subclasses:
ServiceManager

public abstract class ServiceLocator
extends java.lang.Object

This class allows you to locate a service based on the interface it needs to implement.

Example:

Registry registry = (Registry) ServiceLocator.getServiceLocator().locateService(portal.registry.Registry.class);

Author:
Bavo De Ridder < bavo AT coderspotting DOT org >

Constructor Summary
ServiceLocator()
           
 
Method Summary
static ServiceLocator getServiceLocator()
          Returns an instance of the ServiceLocator that has been initialized by the framework.
abstract  IService locateService(java.lang.Class interfaceRequired)
          This method will search for a registered service that implements a certain interface.
protected static void setServiceLocator(ServiceLocator serviceLocator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceLocator

public ServiceLocator()
Method Detail

setServiceLocator

protected static void setServiceLocator(ServiceLocator serviceLocator)
                                 throws ServiceException
Throws:
ServiceException

getServiceLocator

public static final ServiceLocator getServiceLocator()
Returns an instance of the ServiceLocator that has been initialized by the framework.

Returns:
the singleton instance of the ServiceLocator

locateService

public abstract IService locateService(java.lang.Class interfaceRequired)
                                throws ServiceException
This method will search for a registered service that implements a certain interface. When no service is found, null is returned. When multiple services implement the requested interface, only one will be returned. Which one depends on the internal workings of the engine and might change.

Parameters:
interfaceRequired - The Class instance of the interface the service should implement
Returns:
an instance of the service implementing the requested interface or null when none found
Throws:
ServiceException - thrown when the framework was unable to search for a service