Package com.hpe.caf.util
Class ModuleLoader
- java.lang.Object
-
- com.hpe.caf.util.ModuleLoader
-
public final class ModuleLoader extends Object
Utility class that provides methods for finding and returning components at runtime using the Java ServiceLoader.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TgetService(Class<T> intf)Determine the first advertised service implementation for the specified interface.static <T> TgetService(Class<T> intf, Class<? extends T> defaultImpl)Determine the first advertised service implementation for the specified interface.static <T> TgetServiceOrElse(Class<T> intf, T defaultObj)Determine the first advertised service implementation for the specified interface.static <T> List<T>getServices(Class<T> intf)Get all advertised service implementations of the specified interface.
-
-
-
Method Detail
-
getService
public static <T> T getService(Class<T> intf) throws ModuleLoaderException
Determine the first advertised service implementation for the specified interface. The implementations are advertised via the Java "ServiceLoader" mechanism.- Type Parameters:
T- the interface- Parameters:
intf- the interface to find an advertised service implementation for- Returns:
- an advertised implementation of intf of type T
- Throws:
ModuleLoaderException- if there is no advertised implementation available
-
getService
public static <T> T getService(Class<T> intf, Class<? extends T> defaultImpl) throws ModuleLoaderException
Determine the first advertised service implementation for the specified interface. The implementations are advertised via the Java "ServiceLoader" mechanism.- Type Parameters:
T- the interface- Parameters:
intf- the interface to find an advertised service implementation fordefaultImpl- the default implementation class if an advertised one is not found, may be null- Returns:
- an advertised implementation of intf of type T
- Throws:
ModuleLoaderException- if the implementation is missing and no defaultImpl is specified
-
getServiceOrElse
public static <T> T getServiceOrElse(Class<T> intf, T defaultObj)
Determine the first advertised service implementation for the specified interface. The implementations are advertised via the Java "ServiceLoader" mechanism.- Type Parameters:
T- the interface- Parameters:
intf- the interface to find an advertised service implementation fordefaultObj- the default object to return if an advertised one is not found, may be null- Returns:
- an advertised implementation of intf of type T, or the default object if one is not found
-
getServices
public static <T> List<T> getServices(Class<T> intf)
Get all advertised service implementations of the specified interface.- Type Parameters:
T- the interface- Parameters:
intf- the interface to find advertised service implementations of- Returns:
- a collection of implementations of the specified interface
-
-