Class ServiceProvider
- java.lang.Object
-
- org.silverpeas.core.util.ServiceProvider
-
public final class ServiceProvider extends Object
A provider of Silverpeas services such as repositories, controllers, transactional services, and so on.This provider is an adaptor to the underlying IoC by IOD subsystem used to manage the life-cycle and the dependencies of some objects in Silverpeas. Usually, defining injection points is enough for a bean to access the services in Silverpeas, but these injection points work only for beans managed themselves by the IoC subsystem. Hence, this provider is for unmanaged beans in order they have access all of the services available in Silverpeas. Such unmanaged beans are, for example, the entities fetched from a data source.
The provider can be either used directly by the unmanaged beans or through a more typed-specific provider. This latest solution is our preferred way.
- Author:
- mmoquillon
- See Also:
ManagedBeanProvider
- API Note:
- The
ServiceProvider
is a delegator to theManagedBeanProvider
single instance.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Set<T>
getAllServices(Class<T> type, Annotation... qualifiers)
Gets an instance of each service implementing the specified type and satisfying the given qualifiers if any.static <T> T
getService(Class<T> type, Annotation... qualifiers)
Gets an instance of the single implementation matching the specified service type and satisfying the given qualifiers if any.static <T> T
getService(String name)
Gets an object of the service qualified with the specified name.static <T> T
getService(String applicationId, String apiName)
Some APIs are defined at a high level and they can be implemented by several transverse or application services.
-
-
-
Method Detail
-
getService
public static <T> T getService(Class<T> type, Annotation... qualifiers)
Gets an instance of the single implementation matching the specified service type and satisfying the given qualifiers if any. The service is first looked for in the cache of the current thead before asking it to the IOC subsystem. If the implementation is a singleton and it's not yet cached, then the single instance is put in the cache of the current thread for further retrieval.Be attentive about that this method does not return result when trying to get the instance of an implementation of services which are dealing with typed types (see
ApplicationService<T>
for example). To deal with this kind of services, please use theInstance
annotation in a managed bean.- Type Parameters:
T
- the type of the service to return.- Parameters:
type
- the type of the service.qualifiers
- zero, one or more qualifiers annotating the service to look for.- Returns:
- the service satisfying the expected type and, if any, the expected qualifiers.
- Throws:
org.silverpeas.kernel.SilverpeasRuntimeException
- if no bean can be obtained for any reasons. The reason is given in the wrapped exception.- See Also:
ManagedBeanProvider.getManagedBean(Class, Annotation...)
-
getService
public static <T> T getService(String name)
Gets an object of the service qualified with the specified name. The service is first looked for in the cache of the current thead before asking it to the IoC subsystem. If the implementation is a singleton and it's not yet cached, then the single instance is put in the cache of the current thread for further retrieval.Be attentive about that this method does not return result when trying to get the instance of an implementation of services which are dealing with typed types (see
ApplicationService<T>
for example). To deal with this kind of services, please use theInstance
annotation in a managed bean.- Type Parameters:
T
- the type of the service to return.- Parameters:
name
- the name of the service.- Returns:
- the service matching the specified name.
- Throws:
org.silverpeas.kernel.SilverpeasRuntimeException
- if no bean can be obtained for any reasons. The reason is given in the wrapped exception.- See Also:
ManagedBeanProvider.getManagedBean(String)
-
getAllServices
public static <T> Set<T> getAllServices(Class<T> type, Annotation... qualifiers)
Gets an instance of each service implementing the specified type and satisfying the given qualifiers if any.Be attentive about that this method does not return result when trying to get the instance of an implementation of services which are dealing with typed types (see
ApplicationService<T>
for example). To deal with this kind of services, please use theInstance
annotation in a managed bean.- Type Parameters:
T
- the type of the services to return.- Parameters:
type
- the common type of the services.qualifiers
- zero, one or more qualifiers annotating the services to look for.- Returns:
- a set of services satisfying the expected type and, if any, the expected qualifiers, or an empty set otherwise.
- Throws:
org.silverpeas.kernel.SilverpeasRuntimeException
- if no bean can be obtained for any reasons. The reason is given in the wrapped exception.- See Also:
ManagedBeanProvider.getAllManagedBeans(Class, Annotation...)
-
getService
public static <T> T getService(String applicationId, String apiName)
Some APIs are defined at a high level and they can be implemented by several transverse or application services. Such APIs observes a convention naming for the services supporting them. Those APIs expects then each implementation follows this convention naming so that they can be retrieved by the engine providing the API to perform some specific tasks. The convention naming is:
[COMPONENT NAME][API NAME SUFFIX]
. For example, the Component Instance Post Construction API expects to find any implementations that have, in their name, theInstancePostConstruction
suffix. By doing so, the Component Instance Management Engine can invoke the service related to the application for which an instance has just been created.kmeliaInstancePostConstruction
is an example of such a service name for the Kmelia application.In order to be retrieved by the APIs, the implementation has to be qualified with a name following the expected naming rule by using the
Named
annotation. To be provided by this way, an implementation of an API must useNamed
annotation and fillNamed#value()
in case where the implementation class name does not correspond to[COMPONENT NAME][SERVICE NAME SUFFIX]
concatenation.Silverpeas components which supports the Workflow API are taken in charge by this method. In case of a workflow component, the implementation has to satisfies the following more specific naming convention:
processManager[WORKFLOW API NAME SUFFIX]
.- Type Parameters:
T
- the concrete type of the service to return.- Parameters:
applicationId
- a component instance identifier or a component name.apiName
- a service name suffix.- Returns:
- the service implementing the given API for the specified component (a transverse component or an application instance).
- Throws:
org.silverpeas.kernel.SilverpeasRuntimeException
- if no bean can be obtained for any reasons. The reason is given in the wrapped exception.- See Also:
ManagedBeanProvider.getManagedBean(String)
-
-