Class Scope


  • public final class Scope
    extends Object
    A (potentially nested) scope from which bean instances may be acquired.
    • Method Detail

      • getAllBeans

        public <T> List<T> getAllBeans​(Class<T> type)
        Get all constructable beans of the given type.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        Returns:
        the (possibly empty) list of all matching beans
      • getAllBeans

        public <T> List<T> getAllBeans​(Class<T> type,
                                       DependencyFilter filter)
        Get all constructable beans of the given type. The filter is applied to each bean to determine whether it should be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        filter - the filter to apply to determine whether a given bean should be included (must not be null)
        Returns:
        the (possibly empty) list of all matching beans
      • getAllBeans

        public <T> List<T> getAllBeans​(Class<T> type,
                                       String name)
        Get all constructable beans of the given type and name.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        Returns:
        the (possibly empty) list of all matching beans
      • getAllBeans

        public <T> List<T> getAllBeans​(Class<T> type,
                                       String name,
                                       DependencyFilter filter)
        Get all constructable beans of the given type and name. The filter is applied to each bean to determine whether it should be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        filter - the filter to apply to determine whether a given bean should be included (must not be null)
        Returns:
        the (possibly empty) list of all matching beans
      • getAllBeansWithNames

        public <T> Map<String,​T> getAllBeansWithNames​(Class<T> type,
                                                            DependencyFilter filter)
        Get all constructable beans of the given type as a map. The filter is applied to each bean to determine whether it should be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        filter - the filter to apply to determine whether a given bean should be included (must not be null)
        Returns:
        the (possibly empty) list of all matching beans
      • requireBean

        public <T> T requireBean​(Class<T> type)
        Require a single bean with the given type.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        Returns:
        the single bean (not null)
        Throws:
        NoSuchBeanException - if the bean is not present
        BeanInstantiationException - if some error occurred when instantiating the bean
      • requireBean

        public <T> T requireBean​(Class<T> type,
                                 String name)
        Require a single bean with the given type and name.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        Returns:
        the single bean (not null)
        Throws:
        NoSuchBeanException - if the bean is not present
        BeanInstantiationException - if some error occurred when instantiating the bean
      • getOptionalBean

        public <T> T getOptionalBean​(Class<T> type)
        Get a single bean with the given type, if it exists and can be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        Returns:
        the single bean, or null if it is not present
      • getOptionalBean

        public <T> T getOptionalBean​(Class<T> type,
                                     String name)
        Get a single bean with the given type and name, if it exists and can be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        Returns:
        the single bean, or null if it is not present
      • getOptionalBean

        public <T> T getOptionalBean​(Class<T> type,
                                     String name,
                                     DependencyFilter filter)
        Get a single bean with the given type and name, if it exists and can be instantiated. The filter is applied to each bean to determine whether it should be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        filter - the filter to apply to determine whether a given bean should be included (must not be null)
        Returns:
        the single bean, or null if it is not present
      • getBean

        public <T> T getBean​(Class<T> type,
                             String name,
                             boolean optional,
                             DependencyFilter filter)
        Get a single bean with the given type and name, with configurable optionality. The filter is applied to each bean to determine whether it should be instantiated.
        Type Parameters:
        T - the allowed bean type
        Parameters:
        type - the allowed bean type class (must not be null)
        name - the name of the bean which should be returned, or "" for any (must not be null)
        optional - true to return null if no bean matches, or false to throw an exception if no bean matches
        filter - the filter to apply to determine whether a given bean should be included (must not be null)
        Returns:
        the single bean, or null if it is not present
        Throws:
        NoSuchBeanException - if the bean is not present
      • getContainer

        public BeanBag getContainer()