Class ContextManager

All Implemented Interfaces:
IContextListener

public final class ContextManager extends HandleObjectManager<Context> implements IContextListener

A context manager tracks the sets of defined and enabled contexts within the application. The manager sends notification events to listeners when these sets change. It is also possible to retrieve any given context with its identifier.

This class is not intended to be extended by clients.

Since:
3.1
  • Field Details

    • DEBUG

      public static boolean DEBUG
      This flag can be set to true if the context manager should print information to System.out when certain boundary conditions occur.
  • Constructor Details

    • ContextManager

      public ContextManager()
  • Method Details

    • deferUpdates

      public void deferUpdates(boolean defer)
      Informs the manager that a batch operation has started.

      Note: You must insure that if you call deferUpdates(true) that nothing in your batched operation will prevent the matching call to deferUpdates(false).

      Parameters:
      defer - true when starting a batch operation false when ending the operation
      Since:
      3.5
    • addActiveContext

      public final void addActiveContext(String contextId)
      Activates a context in this context manager.
      Parameters:
      contextId - The identifier of the context to activate; must not be null.
    • addContextManagerListener

      public final void addContextManagerListener(IContextManagerListener listener)
      Adds a listener to this context manager. The listener will be notified when the set of defined contexts changes. This can be used to track the global appearance and disappearance of contexts.
      Parameters:
      listener - The listener to attach; must not be null.
    • contextChanged

      public final void contextChanged(ContextEvent contextEvent)
      Description copied from interface: IContextListener
      Notifies that one or more properties of an instance of IContext have changed. Specific details are described in the ContextEvent.
      Specified by:
      contextChanged in interface IContextListener
      Parameters:
      contextEvent - the context event. Guaranteed not to be null.
    • getActiveContextIds

      public final Set getActiveContextIds()
      Returns the set of active context identifiers.
      Returns:
      The set of active context identifiers; this value may be null if no active contexts have been set yet. If the set is not null, then it contains only instances of String.
    • getContext

      public final Context getContext(String contextId)
      Gets the context with the given identifier. If no such context currently exists, then the context will be created (but be undefined).
      Parameters:
      contextId - The identifier to find; must not be null.
      Returns:
      The context with the given identifier; this value will never be null, but it might be undefined.
      See Also:
    • getDefinedContextIds

      public final Set getDefinedContextIds()
      Returns the set of identifiers for those contexts that are defined.
      Returns:
      The set of defined context identifiers; this value may be empty, but it is never null.
    • getDefinedContexts

      public final Context[] getDefinedContexts()
      Returns the those contexts that are defined.
      Returns:
      The defined contexts; this value may be empty, but it is never null.
      Since:
      3.2
    • removeActiveContext

      public final void removeActiveContext(String contextId)
      Deactivates a context in this context manager.
      Parameters:
      contextId - The identifier of the context to deactivate; must not be null.
    • removeContextManagerListener

      public final void removeContextManagerListener(IContextManagerListener listener)
      Removes a listener from this context manager.
      Parameters:
      listener - The listener to be removed; must not be null.
    • setActiveContextIds

      public final void setActiveContextIds(Set activeContextIds)
      Changes the set of active contexts for this context manager. The whole set is required so that internal consistency can be maintained and so that excessive recomputations do nothing occur.
      Parameters:
      activeContextIds - The new set of active context identifiers; may be null.