Interface ContextAwareServiceResolver


@ProviderType public interface ContextAwareServiceResolver
Resolves the best-matching context-aware service implementation.
  • Method Details

    • resolve

      @Nullable <S extends ContextAwareService> S resolve(@NotNull @NotNull Class<S> serviceClass, @Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
      Resolves the best-matching service implementation for the given resource context. Only implementations which accept the given context resource path (via the service properties defined in ContextAwareService) are considered as candidates. If multiple candidates exist the implementation with the highest service ranking is returned.
      Type Parameters:
      S - Service interface or class
      Parameters:
      serviceClass - Service interface or class
      adaptable - Adaptable which is either a Resource or SlingHttpServletRequest. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.
      Returns:
      Service implementation or null if no match found.
    • resolveAll

      @NotNull <S extends ContextAwareService> @NotNull ContextAwareServiceResolver.ResolveAllResult<S> resolveAll(@NotNull @NotNull Class<S> serviceClass, @Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
      Resolves all matching service implementations for the given resource context. Only implementations which accept the given context resource path (via the service properties defined in ContextAwareService) are considered as candidates. The candidates are returned ordered descending by their service ranking.
      Type Parameters:
      S - Service interface or class
      Parameters:
      serviceClass - Service interface or class
      adaptable - Adaptable which is either a Resource or SlingHttpServletRequest. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.
      Returns:
      Collection of all matching services
    • getCollectionResolver

      @NotNull <S extends ContextAwareService> @NotNull ContextAwareServiceCollectionResolver<S,Void> getCollectionResolver(@NotNull @NotNull Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection)
      Gets a ContextAwareServiceCollectionResolver which operates on a given collection of service references of the required service. This collection is usually managed by OSGi Declarative Services and expected to contain all services with the service interface ordered by service ranking (high to low). The collection resolver helps to get service(s) matching the resource context out of this list.
      Type Parameters:
      S - Service interface or class
      Parameters:
      serviceReferenceCollection - Collection of service references
      Returns:
      Collection resolver
    • getCollectionResolver

      @NotNull <S extends ContextAwareService, D> @NotNull ContextAwareServiceCollectionResolver<S,D> getCollectionResolver(@NotNull @NotNull Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection, @NotNull @NotNull BiFunction<@NotNull org.osgi.framework.ServiceReference<S>,@Nullable S,@Nullable D> decorator)
      Gets a ContextAwareServiceCollectionResolver which operates on a given collection of service references of the required service. This collection is usually managed by OSGi Declarative Services and expected to contain all services with the service interface ordered by service ranking (high to low). The collection resolver helps to get service(s) matching the resource context out of this list.
      Type Parameters:
      S - Service interface or class
      D - Decorator class that is calculated once for each item of the service objects collection.
      Parameters:
      serviceReferenceCollection - Collection of service reference
      decorator - Creates decoration for each collection item once.
      Returns:
      Collection resolver