public interface BeanProvider
Depending on the integration, beans may be resolved using reflection (expecting a no-argument constructor), or using a more advanced dependency injection context (CDI, Spring DI).
Regardless of the implementations, this interface is used to retrieve the beans, referenced either by their name, by their type, or both.
This interface may be used by any Hibernate Search module,
but should only be implemented by the Hibernate Search engine itself;
if you are looking for implementing your own bean resolver,
you should implement BeanResolver
instead.
Modifier and Type | Method and Description |
---|---|
default <T> BeanHolder<T> |
getBean(BeanReference<T> reference)
Retrieve a bean from a
BeanReference . |
<T> BeanHolder<T> |
getBean(Class<T> typeReference)
Retrieve a bean referenced by its type.
|
<T> BeanHolder<T> |
getBean(Class<T> typeReference,
String nameReference)
Retrieve a bean referenced by its type and name.
|
default <T> BeanHolder<List<T>> |
getBeans(List<? extends BeanReference<? extends T>> references)
Retrieve a list of beans from a list of
BeanReference s. |
<T> BeanHolder<T> getBean(Class<T> typeReference)
T
- The expected return type.typeReference
- The type used as a reference to the bean to retrieve. 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> getBean(Class<T> typeReference, String nameReference)
T
- The expected return type.typeReference
- The type used as a reference to the bean to retrieve. Must be non-null.nameReference
- The name used as a reference to the bean to retrieve. Must be non-null and non-empty.BeanHolder
containing the resolved bean.SearchException
- if the reference is invalid (null or empty) or the bean cannot be resolved.default <T> BeanHolder<T> getBean(BeanReference<T> reference)
BeanReference
.
This method is just syntactic sugar to allow to write bridgeProvider::getBean
and get 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 retrieve. 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>> getBeans(List<? extends BeanReference<? extends T>> references)
BeanReference
s.
The main advantage of calling this method over looping and calling getBean(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 to write bridgeProvider::getBeans
and get a Function<BeanReference<T>, T>
that can be used in Optional.map(Function)
for instance.
T
- The expected return 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.Copyright © 2006-2019 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.