Class AbstractScopeResolver<S>

  • Type Parameters:
    S - the type of the scope discriminator object
    All Implemented Interfaces:
    ScopeResolver

    public abstract class AbstractScopeResolver<S>
    extends java.lang.Object
    implements ScopeResolver
    Abstract base implementation of a ScopeResolver which manages a map of instances per scope.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void destroyScope​(S scope)
      Destroys the given scope.
      <T> T get​(java.lang.Object key, CreationalContext<T> creationalContext)
      Returns an existing instance associated with the given key, or uses the given context to create one.
      protected abstract S getCurrentScope()
      Returns the current scope, or null if there is no current scope.
      boolean isActive()
      Returns true when this scope is currently active, otherwise false.
      void remove​(java.lang.Object key)
      Removes the given key from this scope resolver.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractScopeResolver

        public AbstractScopeResolver()
    • Method Detail

      • isActive

        public final boolean isActive()
        Description copied from interface: ScopeResolver
        Returns true when this scope is currently active, otherwise false.
        Specified by:
        isActive in interface ScopeResolver
        Returns:
        true when this scope is currently active, otherwise false
      • get

        public final <T> T get​(java.lang.Object key,
                               CreationalContext<T> creationalContext)
                        throws java.lang.Exception
        Description copied from interface: ScopeResolver
        Returns an existing instance associated with the given key, or uses the given context to create one.
        Specified by:
        get in interface ScopeResolver
        Type Parameters:
        T - the type of the instances provided by the CreationalContext
        Parameters:
        key - an object suitable as a key for use in a map, cannot be null
        creationalContext - an CreationalContext, cannot be null
        Returns:
        an instance of the given type, never null
        Throws:
        ScopeNotActiveException - when there is no scope active
        java.lang.Exception - when the object factory throws an exception
      • remove

        public final void remove​(java.lang.Object key)
        Description copied from interface: ScopeResolver
        Removes the given key from this scope resolver.
        Specified by:
        remove in interface ScopeResolver
        Parameters:
        key - an object suitable as a key for use in a map, cannot be null
      • getCurrentScope

        protected abstract S getCurrentScope()
        Returns the current scope, or null if there is no current scope.
        Returns:
        the current scope, or null if there is no current scope
      • destroyScope

        protected final void destroyScope​(S scope)
        Destroys the given scope. Removes all references to instance from the given scope and releases their associated CreationalContexts. Does nothing if the scope does not exist.
        Parameters:
        scope - a scope, cannot be null