Package io.wcm.sling.commons.caservice
Interface ContextAwareServiceResolver
-
@ProviderType public interface ContextAwareServiceResolver
Resolves the best-matching context-aware service implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ContextAwareServiceResolver.ResolveAllResult<S extends ContextAwareService>
Result of theresolveAll(Class, Adaptable)
method.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <S extends ContextAwareService>
@NotNull ContextAwareServiceCollectionResolver<S,java.lang.Void>getCollectionResolver(@NotNull java.util.Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection)
Gets aContextAwareServiceCollectionResolver
which operates on a given collection of service references of the required service.<S extends ContextAwareService,D>
@NotNull ContextAwareServiceCollectionResolver<S,D>getCollectionResolver(@NotNull java.util.Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection, @NotNull java.util.function.BiFunction<@NotNull org.osgi.framework.ServiceReference<S>,@Nullable S,@Nullable D> decorator)
Gets aContextAwareServiceCollectionResolver
which operates on a given collection of service references of the required service.<S extends ContextAwareService>
Sresolve(@NotNull java.lang.Class<S> serviceClass, @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves the best-matching service implementation for the given resource context.<S extends ContextAwareService>
@NotNull ContextAwareServiceResolver.ResolveAllResult<S>resolveAll(@NotNull java.lang.Class<S> serviceClass, @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves all matching service implementations for the given resource context.
-
-
-
Method Detail
-
resolve
@Nullable <S extends ContextAwareService> S resolve(@NotNull @NotNull java.lang.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 inContextAwareService
) 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 classadaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. 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 java.lang.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 inContextAwareService
) 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 classadaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. 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,java.lang.Void> getCollectionResolver(@NotNull @NotNull java.util.Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection)
Gets aContextAwareServiceCollectionResolver
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 java.util.Collection<org.osgi.framework.ServiceReference<S>> serviceReferenceCollection, @NotNull @NotNull java.util.function.BiFunction<@NotNull org.osgi.framework.ServiceReference<S>,@Nullable S,@Nullable D> decorator)
Gets aContextAwareServiceCollectionResolver
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 classD
- Decorator class that is calculated once for each item of the service objects collection.- Parameters:
serviceReferenceCollection
- Collection of service referencedecorator
- Creates decoration for each collection item once.- Returns:
- Collection resolver
-
-