Class BeanStorage

  • All Implemented Interfaces:
    Serializable

    public class BeanStorage
    extends Object
    implements Serializable
    CDI bean storage. This class is theoretically reusable for multiple CDI scopes. It's currently however only used by the OmniFaces CDI view scope.
    Since:
    1.6
    Author:
    Radu Creanga <rdcrng@gmail.com>, Bauke Scholtz
    See Also:
    Serialized Form
    • Constructor Detail

      • BeanStorage

        public BeanStorage​(int initialCapacity)
        Construct a new CDI bean storage with the given initial capacity of the map holding all beans.
        Parameters:
        initialCapacity - The initial capacity of the map holding all beans.
    • Method Detail

      • createBean

        @Deprecated(since="4.5",
                    forRemoval=true)
        public <T> T createBean​(Contextual<T> type,
                                CreationalContext<T> context)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Replaced by getBean(Contextual, CreationalContext) which won't discard any existing bean.
        Create and return the bean associated with given context and creational context.
        Type Parameters:
        T - The generic bean type.
        Parameters:
        type - The contextual type of the CDI managed bean.
        context - The context to create the bean in.
        Returns:
        The bean associated with given context and creational context.
        Throws:
        ClassCastException - When the bean doesn't implement serializable.
      • getBean

        public <T> T getBean​(Contextual<T> type,
                             CreationalContext<T> context)
        Returns the bean associated with the given context, or if there is none, then create one with the given creational context.
        Type Parameters:
        T - The generic bean type.
        Parameters:
        type - The contextual type of the CDI managed bean.
        Returns:
        The bean associated with given context and creational context.
        Since:
        4.5
      • getBean

        public <T> T getBean​(Contextual<T> type)
        Returns the bean associated with the given context, or null if there is none.
        Type Parameters:
        T - The generic bean type.
        Parameters:
        type - The contextual type of the CDI managed bean.
        Returns:
        The bean associated with the given context, or null if there is none.
      • destroyBeans

        public void destroyBeans()
        Destroy all beans managed so far.