Class ContainerExtractorBinder

java.lang.Object
org.hibernate.search.mapper.pojo.extractor.impl.ContainerExtractorBinder

public class ContainerExtractorBinder extends Object
Binds ContainerExtractorPaths to a given input type, and allows to create extractors for a given BoundContainerExtractorPath.

The ContainerExtractorPath is 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: CollectionElementExtractor won't work on a Map.
  • Second to determine the resulting value type: [MapValueExtractor.class, CollectionElementExtractor.class] applied to a Map<String, Collection<Integer>> will result in Integer values.
  • 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 to CollectionElementExtractor. For a Map<String, Collection<Integer>> the default path will be resolved to [MapValueExtractor.class, CollectionElementExtractor.class].
This "binding" results in a BoundContainerExtractorPath, which carries both a ContainerExtractorPath (which is an explicit list of classes, and never ContainerExtractorPath.defaultExtractors(), since the default path was resolved) and the resulting value type.

From this "bound path", the ContainerExtractorBinder is able to later create a ContainerExtractor, which can be used at runtime to extract values from a container.

  • Constructor Details

  • Method Details

    • 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 <C> boolean isDefaultExtractorPath(PojoTypeModel<C> sourceType, ContainerExtractorPath extractorPath)