Class AbstractBeanResolutionContext

java.lang.Object
io.micronaut.context.AbstractBeanResolutionContext
All Implemented Interfaces:
BeanLocator, BeanResolutionContext, ConversionServiceProvider, ValueResolver<CharSequence>, AutoCloseable
Direct Known Subclasses:
DefaultBeanResolutionContext

@Internal public abstract class AbstractBeanResolutionContext extends Object implements BeanResolutionContext
Default implementation of the BeanResolutionContext interface.
Since:
1.2.3
Author:
Graeme Rocher
  • Field Details

  • Constructor Details

    • AbstractBeanResolutionContext

      @Internal protected AbstractBeanResolutionContext(DefaultBeanContext context, @Nullable BeanDefinition<?> rootDefinition)
      Parameters:
      context - The bean context
      rootDefinition - The bean root definition
  • Method Details

    • getConversionService

      public ConversionService getConversionService()
      Description copied from interface: ConversionServiceProvider
      Provides the conversion service.
      Specified by:
      getConversionService in interface ConversionServiceProvider
      Returns:
      the conversion service
    • getPropertyResolver

      public @Nullable PropertyResolver getPropertyResolver()
      Specified by:
      getPropertyResolver in interface BeanResolutionContext
      Returns:
      The property resolver
    • getConfigurationPath

      public ConfigurationPath getConfigurationPath()
      Specified by:
      getConfigurationPath in interface BeanResolutionContext
      Returns:
      The configuration path.
    • setConfigurationPath

      public @Nullable ConfigurationPath setConfigurationPath(@Nullable ConfigurationPath configurationPath)
      Description copied from interface: BeanResolutionContext
      Sets the configuration path.
      Specified by:
      setConfigurationPath in interface BeanResolutionContext
      Parameters:
      configurationPath - The configuration path.
      Returns:
      The previous path
    • valueResolved

      public void valueResolved(Argument<?> argument, @Nullable Qualifier<?> qualifier, String property, @Nullable Object value)
      Description copied from interface: BeanResolutionContext
      Callback when a value is resolved in some other context.
      Specified by:
      valueResolved in interface BeanResolutionContext
      Parameters:
      argument - The argument
      qualifier - The qualifier
      property - The property
      value - The value
    • resolvePropertyValue

      public @Nullable Object resolvePropertyValue(Argument<?> argument, String stringValue, @Nullable String cliProperty, boolean isPlaceholder)
      Description copied from interface: BeanResolutionContext
      Resolve a property value.
      Specified by:
      resolvePropertyValue in interface BeanResolutionContext
      Parameters:
      argument - The argument
      stringValue - The string value
      cliProperty - The CLI property
      isPlaceholder - Whether it is a place holder
      Returns:
      The resolved value
    • getBean

      public <T> T getBean(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> T getBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> T getBean(BeanDefinition<T> definition)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given bean definition.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      definition - The bean type
      Returns:
      An instanceof said bean
      See Also:
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • streamOfType

      public <T> Stream<T> streamOfType(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • streamOfType

      public <T> Stream<T> streamOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • mapOfType

      public <V> Map<String,V> mapOfType(Argument<V> beanType, @Nullable Qualifier<V> qualifier)
      Description copied from interface: BeanLocator
      Obtain a map of beans of the given type where the key is the qualifier.
      Specified by:
      mapOfType in interface BeanLocator
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      See Also:
    • findBean

      public <T> Optional<T> findBean(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      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
      See Also:
    • findBean

      public <T> Optional<T> findBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      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
      See Also:
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Argument<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      Returns:
      The found beans
    • getProxyTargetBean

      public <T> T getProxyTargetBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanLocator
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getBeanRegistrations(Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanResolutionContext
      Obtains the bean registrations for the given type and qualifier.
      Specified by:
      getBeanRegistrations in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A collection of BeanRegistration
    • copyStateFrom

      public void copyStateFrom(AbstractBeanResolutionContext context)
      Copy the state from a previous resolution context.
      Parameters:
      context - The previous context
    • copyForLazyProxyTarget

      public BeanResolutionContext copyForLazyProxyTarget(BeanDefinition<?> proxyBeanDefinition)
      Description copied from interface: BeanResolutionContext
      Copy current context to be used later when resolving a lazy proxy target.
      Specified by:
      copyForLazyProxyTarget in interface BeanResolutionContext
      Parameters:
      proxyBeanDefinition - The proxy bean definition
      Returns:
      The bean resolution context
    • copyForRuntimeProxyTarget

      @Internal public final BeanResolutionContext copyForRuntimeProxyTarget(BeanDefinition<?> targetDefinition)
      Copies this context for a runtime proxy, whose definition resolves a target through it for as long as the proxy lives. A proxy can do so from any thread, and on every call, so that only a copy that is never written to can be shared: each creation of a target happens in its own copy, and a call neither meets another call nor what a failed one left behind.

      A call of a proxy comes when the resolution that created the proxy is over, so the copy starts from an empty path, whatever the path is now. The proxy creator can also resolve the one target it keeps while it creates the proxy: that one remains a part of the creation, see runtimeProxyTargetContext().

      A target that calls its own proxy while it is created is not reported as a circular dependency: the call resolves a further target, and without an end to it the thread runs out of stack.

      Parameters:
      targetDefinition - The definition of the target of the proxy
      Returns:
      The context for the proxy to retain
      Since:
      5.2.23
    • runtimeProxyTargetContext

      @Internal public final BeanResolutionContext runtimeProxyTargetContext()
      Returns:
      The context to resolve the target of a runtime proxy through at this moment: the one creating the proxy, on the thread creating it and for as long as it does, so that the target and what it receives are owned by the proxy; this context otherwise
      Since:
      5.2.23
    • addDependentBean

      public <T> void addDependentBean(BeanRegistration<T> beanRegistration)
      Description copied from interface: BeanResolutionContext
      Adds a dependent bean to the resolution context.
      Specified by:
      addDependentBean in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      beanRegistration - The bean registration
    • destroyInjectScopedBeans

      public void destroyInjectScopedBeans()
      Description copied from interface: BeanResolutionContext
      Call back to destroy any InjectScope beans.
      Specified by:
      destroyInjectScopedBeans in interface BeanResolutionContext
      See Also:
    • getAndResetDependentBeans

      public List<BeanRegistration<?>> getAndResetDependentBeans()
      Specified by:
      getAndResetDependentBeans in interface BeanResolutionContext
      Returns:
      The dependent beans that must be destroyed by an upstream bean
    • getDependentBeans

      public List<BeanRegistration<?>> getDependentBeans()
      Specified by:
      getDependentBeans in interface BeanResolutionContext
      Returns:
      The current dependent beans that must be destroyed by an upstream bean.
    • markDependentAsFactory

      public void markDependentAsFactory()
      Description copied from interface: BeanResolutionContext
      Marks first dependent as factory. Dependent can be missing which means it's a singleton or scoped bean.
      Specified by:
      markDependentAsFactory in interface BeanResolutionContext
    • getAndResetDependentFactoryBean

      public @Nullable BeanRegistration<?> getAndResetDependentFactoryBean()
      Specified by:
      getAndResetDependentFactoryBean in interface BeanResolutionContext
      Returns:
      The dependent factory beans that was used to create the bean in context
    • popDependentBeans

      public @Nullable List<BeanRegistration<?>> popDependentBeans()
      Specified by:
      popDependentBeans in interface BeanResolutionContext
      Returns:
      The current dependent beans that must be destroyed by an upstream bean
    • pushDependentBeans

      public void pushDependentBeans(@Nullable List<BeanRegistration<?>> dependentBeans)
      Description copied from interface: BeanResolutionContext
      The push the current dependent beans that must be destroyed by an upstream bean.
      Specified by:
      pushDependentBeans in interface BeanResolutionContext
      Parameters:
      dependentBeans - Dependent beans collection that can be used to add more dependents
    • getContext

      public final BeanContext getContext()
      Specified by:
      getContext in interface BeanResolutionContext
      Returns:
      The context
    • getRootDefinition

      public final @Nullable BeanDefinition getRootDefinition()
      Specified by:
      getRootDefinition in interface BeanResolutionContext
      Returns:
      The class requested at the root of this resolution context
    • getPath

      public final BeanResolutionContext.Path getPath()
      Specified by:
      getPath in interface BeanResolutionContext
      Returns:
      The path that this resolution has taken so far
    • setAttribute

      public final Object setAttribute(CharSequence key, @Nullable Object value)
      Description copied from interface: BeanResolutionContext
      Store a value within the context.
      Specified by:
      setAttribute in interface BeanResolutionContext
      Parameters:
      key - The key
      value - The value
      Returns:
      The previous value or null
    • getAttribute

      public final @Nullable Object getAttribute(CharSequence key)
      Specified by:
      getAttribute in interface BeanResolutionContext
      Parameters:
      key - The key
      Returns:
      The attribute value
    • removeAttribute

      public final @Nullable Object removeAttribute(CharSequence key)
      Description copied from interface: BeanResolutionContext
      Remove the attribute for the given key.
      Specified by:
      removeAttribute in interface BeanResolutionContext
      Parameters:
      key - the key
      Returns:
      The previous value
    • getAttributes

      public @Nullable Map<CharSequence, Object> getAttributes()
      Description copied from interface: BeanResolutionContext
      Get the map representing current attributes.
      Specified by:
      getAttributes in interface BeanResolutionContext
      Returns:
      All attributes
    • setAttributes

      public void setAttributes(@Nullable Map<CharSequence, Object> attributes)
      Description copied from interface: BeanResolutionContext
      Set new attributes map (The map is supposed to be mutable).
      Specified by:
      setAttributes in interface BeanResolutionContext
      Parameters:
      attributes - The attributes
    • getCurrentQualifier

      public @Nullable Qualifier<?> getCurrentQualifier()
      Specified by:
      getCurrentQualifier in interface BeanResolutionContext
      Returns:
      The current bean identifier
    • setCurrentQualifier

      public void setCurrentQualifier(@Nullable Qualifier<?> qualifier)
      Description copied from interface: BeanResolutionContext
      Sets the current qualifier.
      Specified by:
      setCurrentQualifier in interface BeanResolutionContext
      Parameters:
      qualifier - The qualifier
    • get

      public <T> Optional<T> get(CharSequence name, ArgumentConversionContext<T> conversionContext)
      Description copied from interface: ValueResolver
      Resolve the given property for the given name.
      Specified by:
      get in interface ValueResolver<CharSequence>
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      conversionContext - The conversion context
      Returns:
      An optional containing the property value if it exists and is able to be converted
    • get

      public <T> Optional<T> get(CharSequence name, Class<T> requiredType)
      Description copied from interface: ValueResolver
      Resolve the given property for the given name.
      Specified by:
      get in interface ValueResolver<CharSequence>
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      requiredType - The required type
      Returns:
      An optional containing the property value if it exists and is able to be converted
    • findBeanDefinitions

      public final <T> Collection<BeanDefinition<T>> findBeanDefinitions(Argument<T> argument, @Nullable BeanDefinition<?> bd)
    • getBeanRegistration

      public final <T> BeanRegistration<T> getBeanRegistration(Argument<T> argument, @Nullable Qualifier<T> qualifier)
    • getProxyTargetBean

      public <T> T getProxyTargetBean(BeanDefinition<T> definition, Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanResolutionContext
      Resolves the proxy target for a given proxy bean definition. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      definition - The proxy bean definition
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance