toolbox.services
Class ServiceRegistryImpl

Package class diagram package ServiceRegistryImpl
java.lang.Object
  extended by toolbox.services.ServiceRegistryImpl
All Implemented Interfaces:
ServiceRegistry

public class ServiceRegistryImpl
extends java.lang.Object
implements ServiceRegistry

The default ServiceRegistry implementation.

All service and environment dependencies are defined in an XML configuration document.


Constructor Summary
ServiceRegistryImpl()
          Default constructor
 
Method Summary
 void destroy()
          Destroy this registry, by destroy all the singleton services and all service environments.
 java.lang.String getProperty(java.lang.String name)
          Return the value of the named registry configuration property.
 java.lang.Object getService(java.lang.String name, java.lang.Class clazz)
          Create and return an instance of the named service.
 void init(java.lang.String name, java.lang.String config)
          Initialise this registry by reading the registry configuration.
 void loadEnvironment(java.lang.String name)
          Force the registry to load the named environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceRegistryImpl

public ServiceRegistryImpl()
Default constructor

Method Detail

init

public void init(java.lang.String name,
                 java.lang.String config)
          throws ServiceException
Initialise this registry by reading the registry configuration.

Specified by:
init in interface ServiceRegistry
Parameters:
name - Registry name.
config - Location of the registry configuration.
Throws:
ServiceException - if the registry configuration cannot be created.

getService

public java.lang.Object getService(java.lang.String name,
                                   java.lang.Class clazz)
                            throws ServiceException
Create and return an instance of the named service.

Specified by:
getService in interface ServiceRegistry
Parameters:
name - String containing the name or identifier for the service.
clazz - The class that represents the service type or implementation.
Returns:
Object containing an instance of service.
Throws:
ServiceException - if the service cannot be created and returned.

loadEnvironment

public void loadEnvironment(java.lang.String name)
                     throws ServiceException
Force the registry to load the named environment. This can be useful when the environment utilises a callback mechanism when communicating with service related classes.

Specified by:
loadEnvironment in interface ServiceRegistry
Parameters:
name - String containing the name of the environment to load.
Throws:
ServiceException - if the environment cannot be loaded.

getProperty

public java.lang.String getProperty(java.lang.String name)
Return the value of the named registry configuration property.

Specified by:
getProperty in interface ServiceRegistry
Parameters:
name - String containing property name.
Returns:
String containing the value of the property.

destroy

public void destroy()
             throws ServiceException
Destroy this registry, by destroy all the singleton services and all service environments.

Specified by:
destroy in interface ServiceRegistry
Throws:
ServiceException - if the registry cannot be destroy.