Class ContainerExtractorBinder
- java.lang.Object
-
- org.hibernate.search.mapper.pojo.extractor.impl.ContainerExtractorBinder
-
public class ContainerExtractorBinder extends Object
BindsContainerExtractorPaths to a given input type, and allows to create extractors for a givenBoundContainerExtractorPath.The
ContainerExtractorPathis independent from the input type. This means in particular that the path needs to "bound" to an input type before it can be useful:- First to check that the path applies correctly:
CollectionElementExtractorwon't work on aMap. - Second to determine the resulting value type:
[MapValueExtractor.class, CollectionElementExtractor.class]applied to aMap<String, Collection<Integer>>will result inIntegervalues. - Third, in the case of the default path, to determine the exact list of extractor classes.
For instance, for a
Collection<String>the default path will be resolved toCollectionElementExtractor. For aMap<String, Collection<Integer>>the default path will be resolved to[MapValueExtractor.class, CollectionElementExtractor.class].
BoundContainerExtractorPath, which carries both aContainerExtractorPath(which is an explicit list of classes, and neverContainerExtractorPath.defaultExtractors(), since the default path was resolved) and the resulting value type.From this "bound path", the
ContainerExtractorBinderis able to later create aContainerExtractor, which can be used at runtime to extract values from a container. - First to check that the path applies correctly:
-
-
Constructor Summary
Constructors Constructor Description ContainerExtractorBinder(BeanResolver beanResolver, ContainerExtractorRegistry containerExtractorRegistry, TypePatternMatcherFactory typePatternMatcherFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> BoundContainerExtractorPath<C,?>bindPath(PojoTypeModel<C> sourceType, ContainerExtractorPath extractorPath)Bind a container extractor path to a given source type, i.e.<C,V>
ContainerExtractorHolder<C,V>create(BoundContainerExtractorPath<C,V> boundPath)Create a container value extractor from a bound path, or fail.booleanisDefaultExtractorPath(PojoTypeModel<?> sourceType, ContainerExtractorPath extractorPath)<C> Optional<BoundContainerExtractorPath<C,?>>tryBindPath(PojoTypeModel<C> sourceType, ContainerExtractorPath extractorPath)Try to bind a container extractor path to a given source type, i.e.
-
-
-
Constructor Detail
-
ContainerExtractorBinder
public ContainerExtractorBinder(BeanResolver beanResolver, ContainerExtractorRegistry containerExtractorRegistry, TypePatternMatcherFactory typePatternMatcherFactory)
-
-
Method Detail
-
tryBindPath
public <C> Optional<BoundContainerExtractorPath<C,?>> tryBindPath(PojoTypeModel<C> sourceType, ContainerExtractorPath extractorPath)
Try to bind a container extractor path to a given source type, i.e. to resolve the possibly implicit extractor path (ContainerExtractorPath.defaultExtractors()) and to validate that all extractors in the path can be applied.- Type Parameters:
C- The source type.- Parameters:
sourceType- A model of the source type to apply extractors to.extractorPath- The list of extractors to apply.- Returns:
- The resolved extractor path, or an empty optional if one of the extractors in the path cannot be applied.
-
bindPath
public <C> BoundContainerExtractorPath<C,?> bindPath(PojoTypeModel<C> sourceType, ContainerExtractorPath extractorPath)
Bind a container extractor path to a given source type, i.e. resolve the possibly implicit extractor path (ContainerExtractorPath.defaultExtractors()) and validate that all extractors in the path can be applied, or fail.- Type Parameters:
C- The source type.- Parameters:
sourceType- A model of the source type to apply extractors to.extractorPath- The list of extractors to apply.- Returns:
- The bound extractor path.
- Throws:
SearchException- if one of the extractors in the path cannot be applied.
-
create
public <C,V> ContainerExtractorHolder<C,V> create(BoundContainerExtractorPath<C,V> boundPath)
Create a container value extractor from a bound path, or fail.- Type Parameters:
C- The source type.V- The extracted value type.- Parameters:
boundPath- The bound path to create the extractor from.- Returns:
- The extractor.
- Throws:
AssertionFailure- if the bound path was empty
-
isDefaultExtractorPath
public boolean isDefaultExtractorPath(PojoTypeModel<?> sourceType, ContainerExtractorPath extractorPath)
-
-