jklustor-all-api-0.0.7-20140619012755 (ChemAxon)


com.chemaxon.apidiscovery.util
Class ServiceUtil

Object
  extended by com.chemaxon.apidiscovery.util.ServiceUtil

@Beta
public final class ServiceUtil
extends Object

Utility class to ease service location.

Please note that in the future different DI solutions might be used instead of ServiceLoader.

Please note that this class is annotated with the Beta annotation, so

Author:
Gabor Imre

Method Summary
static
<S> boolean
isServiceAvailable(Class<S> service)
          Check if a specific service is defined and implementation can be loaded.
static
<S> S
loadService(Class<S> service, boolean ensureSingle)
          Load and instantiate an implementation for a given service interface.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadService

public static <S> S loadService(Class<S> service,
                                boolean ensureSingle)
                     throws ServiceConfigurationError
Load and instantiate an implementation for a given service interface.

Type Parameters:
S - Interface type to instantiate
Parameters:
service - Service interface class
ensureSingle - Ensure that only one implementation exists. If set and multiple implementations found then a ServiceConfigurationError is thrown.
Returns:
One instantiated implementation for the given interface
Throws:
ServiceConfigurationError - When something goes wrong (in the underlying ServiceLoader, incase no implementation found, or ensureSingle is true and multiple implementations found

isServiceAvailable

public static <S> boolean isServiceAvailable(Class<S> service)
                                  throws ServiceConfigurationError
Check if a specific service is defined and implementation can be loaded.

Note that there is no guarantee regarding the successfull instantiation of the service.

Type Parameters:
S - Interface type
Parameters:
service - Service interface class
Returns:
true when at least one implementation of the given service is available
Throws:
ServiceConfigurationError - can be thrown by the underlying ServiceLoader.

jklustor-all-api-0.0.7-20140619012755 (ChemAxon)