org.robokind.api.common.services
Class ServiceContext<ServiceClass,ServiceConfig,Param>

java.lang.Object
  extended by org.robokind.api.common.services.ServiceContext<ServiceClass,ServiceConfig,Param>
Type Parameters:
ServiceClass - Class of Service created in this ServiceContext
ServiceConfig - Class of ServiceConfig used in this ServiceContext
Param - Class of the parameter used by this ServiceContext

public class ServiceContext<ServiceClass,ServiceConfig,Param>
extends Object

An ServiceContext keeps track of an attempt to create a new Service. It contains a complementary pair of ConfigurationLoader and ServiceFactory where: the loader takes the given Param type the loader and factory share the same ServiceConfig class the factory returns the given Service class

Author:
Matthew Stevenson

Constructor Summary
ServiceContext()
          Creates an empty ServiceContext
ServiceContext(ConfigurationLoader<ServiceConfig,Param> loader, ServiceFactory<ServiceClass,ServiceConfig> factory)
          Creates a new ServiceContext from the given ConfigurationLoader and ServiceFactory.
 
Method Summary
 boolean buildService()
          Builds a Service using the ServiceFactory and ServiceConfig.
 VersionProperty getConfigFormat()
           
 Class<ServiceConfig> getConfigurationClass()
           
 Param getLoadParameter()
          Returns the load parameter.
 ServiceClass getService()
          Returns the Service from this context.
 Class<ServiceClass> getServiceClass()
           
 ServiceConfig getServiceConfiguration()
          Returns the ServiceConfig loaded from the LoadParameter.
 ConfigurationLoader<ServiceConfig,Param> getServiceConfigurationLoader()
          Returns the ConfigurationLoader for this ServiceContext.
 ServiceFactory<ServiceClass,ServiceConfig> getServiceFactory()
          Return the ServiceFactory used by this ServiceContext.
 VersionProperty getServiceVersion()
           
 boolean loadConfiguration()
          Loads the ServiceConfig using the ConfigurationLoader and LoadParameter.
 void setLoadParameter(Param param)
          Sets the load parameter.
 void setServiceConfiguration(ServiceConfig config)
          Sets the ServiceConfig to use instead of loading a config.
 void setServiceConfigurationLoader(ConfigurationLoader<ServiceConfig,Param> loader)
          Sets the ConfigurationLoader for this ServiceContext.
 void setServiceFactory(ServiceFactory<ServiceClass,ServiceConfig> factory)
          Sets the ServiceFactory to be used by this ServiceContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceContext

public ServiceContext()
Creates an empty ServiceContext


ServiceContext

public ServiceContext(ConfigurationLoader<ServiceConfig,Param> loader,
                      ServiceFactory<ServiceClass,ServiceConfig> factory)
Creates a new ServiceContext from the given ConfigurationLoader and ServiceFactory.

Parameters:
loader - ConfigurationLoader of the correct type
factory - ServiceFactory of the correct type
Method Detail

getServiceConfigurationLoader

public ConfigurationLoader<ServiceConfig,Param> getServiceConfigurationLoader()
Returns the ConfigurationLoader for this ServiceContext.

Returns:
ConfigurationLoader for this ServiceContext

setServiceConfigurationLoader

public void setServiceConfigurationLoader(ConfigurationLoader<ServiceConfig,Param> loader)
Sets the ConfigurationLoader for this ServiceContext.

Parameters:
loader - ConfigurationLoader to use

getServiceFactory

public ServiceFactory<ServiceClass,ServiceConfig> getServiceFactory()
Return the ServiceFactory used by this ServiceContext.

Returns:
ServiceFactory used by this ServiceContext

setServiceFactory

public void setServiceFactory(ServiceFactory<ServiceClass,ServiceConfig> factory)
Sets the ServiceFactory to be used by this ServiceContext.

Parameters:
factory - ServiceFactory to be used by this ServiceContext

getLoadParameter

public Param getLoadParameter()
Returns the load parameter.

Returns:
load parameter

setLoadParameter

public void setLoadParameter(Param param)
Sets the load parameter. This is passed to the ConfigurationLoader to load the ServiceConfig.

Parameters:
param - parameter passed to the ConfigurationLoader to load the ServiceConfig

loadConfiguration

public boolean loadConfiguration()
Loads the ServiceConfig using the ConfigurationLoader and LoadParameter.

Returns:
true if the config is not null (regardless of when and where it was set)

getServiceConfiguration

public ServiceConfig getServiceConfiguration()
Returns the ServiceConfig loaded from the LoadParameter. loadConfiguration must be called for the configuration to be available.

Returns:
ServiceConfig loaded from the LoadParameter

setServiceConfiguration

public void setServiceConfiguration(ServiceConfig config)
Sets the ServiceConfig to use instead of loading a config. If this is set to null, this will attempt to load a config when building the service.

Parameters:
config - ServiceConfig to set

buildService

public boolean buildService()
Builds a Service using the ServiceFactory and ServiceConfig. Attempts to load the ServiceConfig if it has not been loaded.


getService

public ServiceClass getService()
Returns the Service from this context. buildService() must be called fore the service to be available.

Returns:
Service from this context

getServiceVersion

public VersionProperty getServiceVersion()

getServiceClass

public Class<ServiceClass> getServiceClass()

getConfigFormat

public VersionProperty getConfigFormat()

getConfigurationClass

public Class<ServiceConfig> getConfigurationClass()


Copyright © 2011-2013. All Rights Reserved.