Class AbstractContext

java.lang.Object
com.vaadin.cdi.util.AbstractContext
All Implemented Interfaces:
jakarta.enterprise.context.spi.Context
Direct Known Subclasses:
RouteScopedContext, UIScopedContext, VaadinServiceScopedContext, VaadinSessionScopedContext

public abstract class AbstractContext extends Object implements jakarta.enterprise.context.spi.Context
A skeleton containing the most important parts of a custom CDI Context. An implementing Context needs to implement the missing methods from the Context interface and getContextualStorage(Contextual, boolean).
Since:
15.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractContext(jakarta.enterprise.inject.spi.BeanManager beanManager)
    Creates a new context and determines whether its scope is passivating.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Make sure that the Context is really active.
    boolean
    destroy(jakarta.enterprise.context.spi.Contextual bean)
    Destroy the Contextual Instance of the given Bean.
    void
    destroys all the Contextual Instances in the Storage returned by getContextualStorage(Contextual, boolean).
    Destroys all the Contextual Instances in the specified ContextualStorage.
    static void
    destroyBean(jakarta.enterprise.context.spi.Contextual bean, ContextualInstanceInfo<?> contextualInstanceInfo)
    Destroys the given contextual instance using the given bean.
    <T> T
    get(jakarta.enterprise.context.spi.Contextual<T> bean)
     
    <T> T
    get(jakarta.enterprise.context.spi.Contextual<T> bean, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext)
     
    Returns the contextual storages that are currently active for this context.
    protected abstract ContextualStorage
    getContextualStorage(jakarta.enterprise.context.spi.Contextual<?> contextual, boolean createIfNotExist)
    An implementation has to return the underlying storage which contains the items held in the Context.
    boolean
    Checks whether the scope served by this context is a passivating scope.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface jakarta.enterprise.context.spi.Context

    getScope, isActive
  • Constructor Details

    • AbstractContext

      protected AbstractContext(jakarta.enterprise.inject.spi.BeanManager beanManager)
      Creates a new context and determines whether its scope is passivating.
      Parameters:
      beanManager - the bean manager used to check whether the scope of this context is a passivating scope
  • Method Details

    • getContextualStorage

      protected abstract ContextualStorage getContextualStorage(jakarta.enterprise.context.spi.Contextual<?> contextual, boolean createIfNotExist)
      An implementation has to return the underlying storage which contains the items held in the Context.
      Parameters:
      contextual - the contextual for which the storage is requested, may be null
      createIfNotExist - whether a ContextualStorage shall get created if it doesn't yet exist.
      Returns:
      the underlying storage
    • getActiveContextualStorages

      protected List<ContextualStorage> getActiveContextualStorages()
      Returns the contextual storages that are currently active for this context.

      The default implementation returns a list containing the storage returned by getContextualStorage(Contextual, boolean) without creating it, so the only entry is null if no storage exists yet.

      Returns:
      a list of the active contextual storages, entries may be null
    • isPassivatingScope

      public boolean isPassivatingScope()
      Checks whether the scope served by this context is a passivating scope.
      Returns:
      whether the served scope is a passivating scope
    • get

      public <T> T get(jakarta.enterprise.context.spi.Contextual<T> bean)
      Specified by:
      get in interface jakarta.enterprise.context.spi.Context
    • get

      public <T> T get(jakarta.enterprise.context.spi.Contextual<T> bean, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext)
      Specified by:
      get in interface jakarta.enterprise.context.spi.Context
    • destroy

      public boolean destroy(jakarta.enterprise.context.spi.Contextual bean)
      Destroy the Contextual Instance of the given Bean.
      Parameters:
      bean - dictates which bean shall get cleaned up
      Returns:
      true if the bean was destroyed, false if there was no such bean.
    • destroyAllActive

      public void destroyAllActive()
      destroys all the Contextual Instances in the Storage returned by getContextualStorage(Contextual, boolean).
    • destroyAllActive

      public static Map<Object,ContextualInstanceInfo<?>> destroyAllActive(ContextualStorage storage)
      Destroys all the Contextual Instances in the specified ContextualStorage. This is a static method to allow various holder objects to cleanup properly in @PreDestroy.
      Parameters:
      storage - the storage whose contextual instances should be destroyed
      Returns:
      a map of the destroyed entries that were held in the storage
    • destroyBean

      public static void destroyBean(jakarta.enterprise.context.spi.Contextual bean, ContextualInstanceInfo<?> contextualInstanceInfo)
      Destroys the given contextual instance using the given bean.
      Parameters:
      bean - the bean to use for destroying the instance
      contextualInstanceInfo - the contextual instance and its creational context
    • checkActive

      protected void checkActive()
      Make sure that the Context is really active.
      Throws:
      jakarta.enterprise.context.ContextNotActiveException - if there is no active Context for the current Thread.