org.specrunner
Class SRServices

java.lang.Object
  extended by org.specrunner.SRServices

public final class SRServices
extends Object

Centralizes the services provided by the SpecRunner framework. To get full list of available services list use method getServices(). For specific services, i.e. if you need an instance of IStringAlignerFactory, use SRServices.get(IStringAlignerFactory.class).

This is thread-safe!

Author:
Thiago Santos

Nested Class Summary
static class SRServices.ShutDown
          Shutdown hook thread.
 
Method Summary
protected static void addHook(SRServices service)
          Add shutdown hook to the environment.
<T> void
bind(Class<T> clazz, T instance)
          Bind a service to the SpecRunner.
static SRServices get()
          Gets the instance of SRServices.
static
<T> T
get(Class<T> clazz)
          Shortcut static method to recover a service (thread-safe).
static IComparatorManager getComparatorManager()
          Shortcut method to comparator manager.
static IConverterManager getConverterManager()
          Shortcut method to converter manager.
static IExpressionFactory getExpressionFactory()
          Shortcut method to expression factory.
static IFeatureManager getFeatureManager()
          Shortcut method to feature manager.
 Map<Class<?>,Object> getServices()
          The map of all available services.
static ISpecRunner getSpecRunner()
          Shortcut method to the topmost interface.
static ISpecRunnerPlugin getSpecRunnerPlugin()
          Shortcut method to the topmost interface for programmatic plugins.
 String getThreadName()
          Get the thread associated to this service..
<T> T
lookup(Class<T> clazz)
          Lookup for a service by its type.
static void release()
          Release all reusable resources pending.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bind

public <T> void bind(Class<T> clazz,
                     T instance)
Bind a service to the SpecRunner. Be sure you create an instance of a given service to each thread. This is quite simple, for example, in JUnit testing set features/services using @Before annotation instead of @BeforeClass. Features, however, can be set on @BeforeClass without side-effects.

Type Parameters:
T - The type to be bound.
Parameters:
clazz - The service type.
instance - The service instance.

lookup

public <T> T lookup(Class<T> clazz)
Lookup for a service by its type.

Type Parameters:
T - The service type.
Parameters:
clazz - The service type.
Returns:
The instance of the given service, or throws IllegalArgumentException if the service was not previously bound.

getServices

public Map<Class<?>,Object> getServices()
The map of all available services. This is the mapping itself, not a copy, is up to you change as you want (take your chances).

Returns:
The services mapping.

getThreadName

public String getThreadName()
Get the thread associated to this service..

Returns:
A thread name.

get

public static <T> T get(Class<T> clazz)
Shortcut static method to recover a service (thread-safe).

Type Parameters:
T - A class type.
Parameters:
clazz - see lookup.
Returns:
see lookup.

get

public static SRServices get()
Gets the instance of SRServices.

Returns:
The services instance.

addHook

protected static void addHook(SRServices service)
Add shutdown hook to the environment.

Parameters:
service - A service to be shut down.

getFeatureManager

public static IFeatureManager getFeatureManager()
Shortcut method to feature manager.

Returns:
The feature manager.

getConverterManager

public static IConverterManager getConverterManager()
Shortcut method to converter manager.

Returns:
The converter manager.

getComparatorManager

public static IComparatorManager getComparatorManager()
Shortcut method to comparator manager.

Returns:
The feature comparator.

getExpressionFactory

public static IExpressionFactory getExpressionFactory()
Shortcut method to expression factory.

Returns:
The expression factory.

getSpecRunner

public static ISpecRunner getSpecRunner()
                                 throws SpecRunnerException
Shortcut method to the topmost interface.

Returns:
A specification runner.
Throws:
SpecRunnerException - On recovering errors.

getSpecRunnerPlugin

public static ISpecRunnerPlugin getSpecRunnerPlugin()
                                             throws SpecRunnerException
Shortcut method to the topmost interface for programmatic plugins.

Returns:
A specification runner.
Throws:
SpecRunnerException - On recovering errors.

release

public static void release()
Release all reusable resources pending.



Copyright © 2014. All rights reserved.