Class ScopeManager


  • @ThreadSafe
    public final class ScopeManager
    extends Object
    This is the manager class for non-web scope handling. The following scopes are supported:
    • global
    • application
    • request
    • session
    • session application
    Author:
    Philip Helger
    • Field Detail

      • SCOPE_ATTRIBUTE_PREFIX_INTERNAL

        public static final String SCOPE_ATTRIBUTE_PREFIX_INTERNAL
        The prefix to be used for attribute names in any scope to indicate system internal attributes
        See Also:
        Constant Field Values
    • Method Detail

      • setGlobalScope

        public static void setGlobalScope​(@Nonnull
                                          IGlobalScope aGlobalScope)
        This method is only to be called by this class and the web scope manager!
        Parameters:
        aGlobalScope - The scope to be set. May not be null.
      • onGlobalBegin

        @Nonnull
        public static IGlobalScope onGlobalBegin​(@Nonnull @Nonempty
                                                 String sScopeID)
        This method is used to set the initial global scope.
        Parameters:
        sScopeID - The scope ID to use
        Returns:
        The created global scope object. Never null.
      • isGlobalScopePresent

        public static boolean isGlobalScopePresent()
      • onGlobalEnd

        public static void onGlobalEnd()
        To be called when the singleton global context is to be destroyed.
      • getSessionScope

        @Nonnull
        public static ISessionScope getSessionScope()
        Get the current session scope, based on the current request scope.
        Returns:
        Never null.
        Throws:
        IllegalStateException - If no request scope is present or if the underlying request scope does not have a session ID.
      • getSessionScope

        @Nullable
        public static ISessionScope getSessionScope​(boolean bCreateIfNotExisting)
        Get the current session scope, based on the current request scope.
        Parameters:
        bCreateIfNotExisting - true to create a new scope, if none is present yet, false to return null if either no request scope or no session scope is present.
        Returns:
        null if bCreateIfNotExisting is false and either no request scope or no session scope is present, the ISessionScope otherwise.
        Throws:
        IllegalStateException - if bCreateIfNotExisting is true but no request scope is present. This exception is also thrown if the underlying request scope does not have a session ID.
      • destroySessionScope

        public static void destroySessionScope​(@Nonnull
                                               ISessionScope aSessionScope)
        Manually destroy the passed session scope.
        Parameters:
        aSessionScope - The session scope to be destroyed. May not be null.
      • internalSetAndInitRequestScope

        public static void internalSetAndInitRequestScope​(@Nonnull
                                                          IRequestScope aRequestScope)
        This method is only to be called by this class and the web scope manager!
        Parameters:
        aRequestScope - The request scope to use. May not be null.
      • getRequestScopeOrNull

        @Nullable
        public static IRequestScope getRequestScopeOrNull()
        Returns:
        The current request scope or null if no request scope is present.
      • isRequestScopePresent

        public static boolean isRequestScopePresent()
        Returns:
        true if a request scope is present, false otherwise
      • internalClearRequestScope

        public static void internalClearRequestScope()
        Internal method to clear request scope thread local.
        Since:
        9.0.0
      • onRequestEnd

        public static void onRequestEnd()
        To be called after a request finished.
      • isInternalAttribute

        public static boolean isInternalAttribute​(@Nullable
                                                  String sAttributeName)
        Check if the passed attribute name is an internal attribute.
        Parameters:
        sAttributeName - The name of the attribute to check. May be null.
        Returns:
        true if the passed attribute name is not null and starts with the SCOPE_ATTRIBUTE_PREFIX_INTERNAL prefix.