Interface BeanLocator

All Known Subinterfaces:
ApplicationContext, BeanContext, ConditionContext<T>, ConfigurableApplicationContext, ConfigurableBeanContext, InitializableBeanContext
All Known Implementing Classes:
DefaultApplicationContext, DefaultBeanContext

public interface BeanLocator

Core interface for locating and discovering Bean instances.

Since:
1.0
Author:
Graeme Rocher
  • Method Details

    • getBean

      @NonNull <T> T getBean(@NonNull @NonNull BeanDefinition<T> definition)
      Obtains a Bean for the given bean definition.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      definition - The bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBean

      @NonNull <T> T getBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBean

      @NonNull default <T> T getBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • getBean

      @NonNull default <T> T getBean(@NonNull @NonNull Argument<T> beanType)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • getProvider

      @NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      @NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Class<T> beanType)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      @NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      @NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Argument<T> beanType)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A provider for the given type
      Since:
      4.5.0
      See Also:
    • findBean

      @NonNull <T> @NonNull Optional<T> findBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • findBean

      @NonNull default <T> @NonNull Optional<T> findBean(@NonNull @NonNull Argument<T> beanType)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • findBean

      @NonNull <T> @NonNull Optional<T> findBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBeansOfType

      @NonNull <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Class<T> beanType)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      @NonNull <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getBeansOfType

      @NonNull default <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Argument<T> beanType)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      Returns:
      The found beans
      Since:
      3.0.0
    • getBeansOfType

      @NonNull default <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      qualifier - The qualifier
      Returns:
      The found beans
      Since:
      3.0.0
    • streamOfType

      @NonNull <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • streamOfType

      @NonNull default <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      Since:
      3.0.0
      See Also:
    • streamOfType

      @NonNull default <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Argument<T> beanType)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A stream of instances
      Since:
      3.0.0
      See Also:
    • mapOfType

      @NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Argument<V> beanType, @Nullable @Nullable Qualifier<V> qualifier)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      @NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Class<V> beanType, @Nullable @Nullable Qualifier<V> qualifier)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      @NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Class<V> beanType)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      @NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Argument<V> beanType)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • getProxyTargetBean

      @NonNull <T> T getProxyTargetBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getProxyTargetBean

      @NonNull default <T> T getProxyTargetBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier)
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
      Since:
      3.0.0
    • streamOfType

      @NonNull default <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Class<T> beanType)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      Returns:
      A stream
    • getBean

      @NonNull default <T> T getBean(@NonNull @NonNull Class<T> beanType)
      Obtains a Bean for the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      NoSuchBeanException - If the bean doesn't exist
    • findBean

      @NonNull default <T> @NonNull Optional<T> findBean(@NonNull @NonNull Class<T> beanType)
      Finds a Bean for the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
    • findOrInstantiateBean

      @NonNull default <T> @NonNull Optional<T> findOrInstantiateBean(@NonNull @NonNull Class<T> beanType)
      Finds a Bean for the given type or attempts to instantiate the given instance.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean if it could not be found or instantiated
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type