Interface BeanResolutionContext

All Superinterfaces:
AutoCloseable, BeanLocator, ConversionServiceProvider, ValueResolver<CharSequence>
All Known Implementing Classes:
AbstractBeanResolutionContext, DefaultBeanResolutionContext

@Internal public interface BeanResolutionContext extends ValueResolver<CharSequence>, AutoCloseable, BeanLocator, ConversionServiceProvider
Represents the resolution context for a current resolve of a given bean.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • EXISTING_DEPENDENT_BEANS

      static final String EXISTING_DEPENDENT_BEANS
      Attribute that exposes the dependent bean registrations already created for the bean this context is operating on.

      During bean creation those registrations are available from getDependentBeans(), but a bean is destroyed with a fresh resolution context that has no dependents of its own. This attribute is retained for compatibility with generated factory definitions that still use that fallback.

      Since:
      5.2.0
      See Also:
    • INTERCEPTOR_REGISTRATIONS

      static final String INTERCEPTOR_REGISTRATIONS
      Attribute used while a bean is being created to transfer the interceptor registrations selected for that bean to its BeanRegistration.

      The value is an identity map keyed by BeanDefinition. It is consumed by the bean context after creation and must be treated as an implementation detail.

      Since:
      5.2.0
      See Also:
    • SHARED_INTERCEPTOR_REGISTRATIONS

      static final String SHARED_INTERCEPTOR_REGISTRATIONS
      Attribute used while a bean with constructor advice is being constructed to share the interceptor registrations selected for it with its post-construct interception.

      The value is a mutable stack that belongs to the creation in progress and must be treated as an implementation detail.

      Since:
      5.2.1
      See Also:
    • EXISTING_INTERCEPTOR_REGISTRATIONS

      static final String EXISTING_INTERCEPTOR_REGISTRATIONS
      Attribute that exposes the interceptor registrations selected while creating the bean being disposed.

      The value is a read-only List<BeanRegistration<?>>. It is set only while a bean is being disposed and is intended for lifecycle interception.

      Since:
      5.2.0
      See Also:
  • Method Details

    • close

      default void close()
      Specified by:
      close in interface AutoCloseable
    • getPropertyResolver

      @Nullable PropertyResolver getPropertyResolver()
      Returns:
      The property resolver
    • getBeanRegistrations

      <T> Collection<BeanRegistration<T>> getBeanRegistrations(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains the bean registrations for the given type and qualifier.
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A collection of BeanRegistration
      Since:
      3.5.0
    • destroyInjectScopedBeans

      void destroyInjectScopedBeans()
      Call back to destroy any InjectScope beans.
      Since:
      3.1.0
      See Also:
    • copy

      Copy current context to be used later.
      Returns:
      The bean resolution context
      Since:
      3.1.0
    • copyForLazyProxyTarget

      default BeanResolutionContext copyForLazyProxyTarget(BeanDefinition<?> proxyBeanDefinition)
      Copy current context to be used later when resolving a lazy proxy target.
      Parameters:
      proxyBeanDefinition - The proxy bean definition
      Returns:
      The bean resolution context
      Since:
      5.1.0
    • shouldInitializeBean

      default boolean shouldInitializeBean(BeanDefinition<?> beanDefinition, Object bean)
      Returns whether a newly constructed bean instance should receive field/method injection and initialization callbacks.
      Parameters:
      beanDefinition - The bean definition
      bean - The newly constructed bean instance
      Returns:
      True if the bean instance should be injected and initialized
      Since:
      5.1.0
    • getContext

      BeanContext getContext()
      Returns:
      The context
    • getRootDefinition

      @Nullable BeanDefinition getRootDefinition()
      Returns:
      The class requested at the root of this resolution context
    • getPath

      Returns:
      The path that this resolution has taken so far
    • getConfigurationPath

      ConfigurationPath getConfigurationPath()
      Returns:
      The configuration path.
      Since:
      4.0.0
    • setAttribute

      @Nullable Object setAttribute(CharSequence key, @Nullable Object value)
      Store a value within the context.
      Parameters:
      key - The key
      value - The value
      Returns:
      The previous value or null
    • getAttribute

      @Nullable Object getAttribute(CharSequence key)
      Parameters:
      key - The key
      Returns:
      The attribute value
    • removeAttribute

      @Nullable Object removeAttribute(CharSequence key)
      Remove the attribute for the given key.
      Parameters:
      key - the key
      Returns:
      The previous value
    • getAttributes

      @Nullable Map<CharSequence, Object> getAttributes()
      Get the map representing current attributes.
      Returns:
      All attributes
      Since:
      4.0.0
    • setAttributes

      void setAttributes(@Nullable Map<CharSequence, Object> attributes)
      Set new attributes map (The map is supposed to be mutable).
      Parameters:
      attributes - The attributes
      Since:
      4.0.0
    • addInFlightBean

      <T> void addInFlightBean(BeanIdentifier beanIdentifier, BeanRegistration<T> beanRegistration)
      Adds a bean that is created as part of the resolution. This is used to store references to instances passed to BeanContext.inject(Object).
      Type Parameters:
      T - The instance type
      Parameters:
      beanIdentifier - The bean identifier
      beanRegistration - The bean registration
    • removeInFlightBean

      void removeInFlightBean(BeanIdentifier beanIdentifier)
      Removes a bean that is in the process of being created. This is used to store references to instances passed to BeanContext.inject(Object).
      Parameters:
      beanIdentifier - The bean identifier
    • getInFlightBean

      <T> @Nullable BeanRegistration<T> getInFlightBean(BeanIdentifier beanIdentifier)
      Obtains an inflight bean for the given identifier. An "In Flight" bean is one that is currently being created but has not finished construction and been registered as a singleton just yet. For example in the case whereby a bean as a PostConstruct method that also triggers bean resolution of the same bean.
      Type Parameters:
      T - The bean type
      Parameters:
      beanIdentifier - The bean identifier
      Returns:
      The bean
    • getCurrentQualifier

      @Nullable Qualifier<?> getCurrentQualifier()
      Returns:
      The current bean identifier
    • setCurrentQualifier

      void setCurrentQualifier(@Nullable Qualifier<?> qualifier)
      Sets the current qualifier.
      Parameters:
      qualifier - The qualifier
    • addDependentBean

      <T> void addDependentBean(BeanRegistration<T> beanRegistration)
      Adds a dependent bean to the resolution context.
      Type Parameters:
      T - The generic type
      Parameters:
      beanRegistration - The bean registration
    • getAndResetDependentBeans

      default List<BeanRegistration<?>> getAndResetDependentBeans()
      Returns:
      The dependent beans that must be destroyed by an upstream bean
    • popDependentBeans

      default @Nullable List<BeanRegistration<?>> popDependentBeans()
      Returns:
      The current dependent beans that must be destroyed by an upstream bean
      Since:
      3.5.0
    • getDependentBeans

      default List<BeanRegistration<?>> getDependentBeans()
      Returns:
      The current dependent beans that must be destroyed by an upstream bean.
      Since:
      5.1.0
    • pushDependentBeans

      default void pushDependentBeans(@Nullable List<BeanRegistration<?>> dependentBeans)
      The push the current dependent beans that must be destroyed by an upstream bean.
      Parameters:
      dependentBeans - Dependent beans collection that can be used to add more dependents
      Since:
      3.5.0
    • markDependentAsFactory

      default void markDependentAsFactory()
      Marks first dependent as factory. Dependent can be missing which means it's a singleton or scoped bean.
      Since:
      3.5.0
    • getAndResetDependentFactoryBean

      default @Nullable BeanRegistration<?> getAndResetDependentFactoryBean()
      Returns:
      The dependent factory beans that was used to create the bean in context
      Since:
      3.5.0
    • setConfigurationPath

      @Nullable ConfigurationPath setConfigurationPath(@Nullable ConfigurationPath configurationPath)
      Sets the configuration path.
      Parameters:
      configurationPath - The configuration path.
      Returns:
      The previous path
    • resolvePropertyValue

      @Nullable Object resolvePropertyValue(Argument<?> argument, String stringValue, @Nullable String cliProperty, boolean isPlaceholder)
      Resolve a property value.
      Parameters:
      argument - The argument
      stringValue - The string value
      cliProperty - The CLI property
      isPlaceholder - Whether it is a place holder
      Returns:
      The resolved value
    • valueResolved

      void valueResolved(Argument<?> argument, @Nullable Qualifier<?> qualifier, String property, @Nullable Object value)
      Callback when a value is resolved in some other context.
      Parameters:
      argument - The argument
      qualifier - The qualifier
      property - The property
      value - The value
    • getProxyTargetBean

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