public interface BeanResolver
Depending on the integration, beans may be instantiated using reflection (expecting a no-argument constructor), or provided by a more advanced dependency injection context (CDI, Spring DI).
Regardless of the underlying implementation, this interface is used to resolve beans,
referenced either
by their type,
or by their type and name,
or by their role.
This interface is API,
but should only be implemented by Hibernate Search itself;
if you are looking to provide beans from a different source,
you should implement BeanProvider instead.
| Modifier and Type | Method and Description |
|---|---|
default <T> BeanHolder<T> |
resolve(BeanReference<T> reference)
Resolve a
BeanReference. |
<T> BeanHolder<T> |
resolve(Class<T> typeReference)
Resolve a bean by its type.
|
<T> BeanHolder<T> |
resolve(Class<T> typeReference,
String nameReference)
Resolve a bean by its name.
|
default <T> BeanHolder<List<T>> |
resolve(List<? extends BeanReference<? extends T>> references)
Resolve a list of
BeanReferences. |
<T> BeanHolder<List<T>> |
resolveRole(Class<T> role)
Resolve the given role into a list of beans.
|
<T> BeanHolder<T> resolve(Class<T> typeReference)
T - The expected return type.typeReference - The type used as a reference to the bean to resolve. Must be non-null.BeanHolder containing the resolved bean.SearchException - if the reference is invalid (null) or the bean cannot be resolved.<T> BeanHolder<T> resolve(Class<T> typeReference, String nameReference)
T - The expected return type.typeReference - The type used as a reference to the bean to resolve. Must be non-null.nameReference - The name used as a reference to the bean to resolve. Must be non-null and non-empty.BeanHolder containing the resolved bean.SearchException - if a reference is invalid (null or empty) or the bean cannot be resolved.default <T> BeanHolder<T> resolve(BeanReference<T> reference)
BeanReference.
This method is just syntactic sugar to allow writing bridgeProvider::resolve
and getting a Function<BeanReference<T>, T> that can be used in Optional.map(Function)
for instance.
T - The expected return type.reference - The reference to the bean to resolve. Must be non-null.BeanHolder containing the resolved bean.SearchException - if the reference is invalid (null or empty) or the bean cannot be resolved.default <T> BeanHolder<List<T>> resolve(List<? extends BeanReference<? extends T>> references)
BeanReferences.
The main advantage of calling this method over looping and calling resolve(BeanReference) repeatedly
is that errors are handled correctly: if a bean was already instantiated, and getting the next one fails,
then the first bean will be properly closed before the exception is propagated.
Also, this method returns a BeanHolder<List<T>> instead of a List<BeanHolder<T>>,
so its result is easier to use in a try-with-resources.
This method is also syntactic sugar to allow writing bridgeProvider::resolve
and getting a Function<BeanReference<T>, T> that can be used in Optional.map(Function)
for instance.
T - The expected bean type.references - The references to the beans to retrieve. Must be non-null.BeanHolder containing a List containing the resolved beans,
in the same order as the references.SearchException - if one reference is invalid (null or empty) or the corresponding bean cannot be resolved.<T> BeanHolder<List<T>> resolveRole(Class<T> role)
WARNING: this does not just return all the beans that implement role.
Beans are assigned a role explicitly during
bean configuration
by calling
BeanConfigurationContext.assignRole(Class, BeanReference).
T - The expected bean type.role - The role that must have been assigned to the retrieved beans. Must be non-null and non-empty.BeanHolder containing a List containing the resolved beans.SearchException - if one of the references assigned to the role cannot be resolved.Copyright © 2006-2020 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.