Class BaseContext

java.lang.Object
org.opensaml.messaging.context.BaseContext
All Implemented Interfaces:
Iterable<BaseContext>
Direct Known Subclasses:
AbstractSAMLEntityContext, AccessControlContext, AttributeConsumingServiceContext, ChannelBindingsContext, ClientStorageLoadContext, ClientStorageSaveContext, ClientTLSSecurityParametersContext, ECPContext, EncryptionContext, EventContext, HttpClientRequestContext, HttpClientSecurityContext, InboundSOAPContext, InOutOperationContext, MessageChannelSecurityContext, MessageContext, MetricContext, ProxiedRequesterContext, SAMLArtifactContext, SAMLBindingContext, SAMLConsentContext, SAMLEndpointContext, SAMLMessageInfoContext, SAMLMessageReceivedEndpointContext, SAMLMetadataContext, SAMLProtocolContext, SAMLSubjectNameIdentifierContext, ScratchContext, SecurityParametersContext, SOAP11Context, SOAPClientContext, SOAPClientSecurityContext, WSAddressingContext, WSSecurityContext

public abstract class BaseContext
extends Object
implements Iterable<BaseContext>
Base implementation of a component which represents the context used to store state used for purposes related to messaging.

Specific implementations of contexts would normally add additional properties to the context to represent the state that is to be stored by that particular context implementation.

A context may also function as a container of subcontexts. Access to subcontexts is class-based. The parent context may hold only one instance of a given class at a given time. This class-based indexing approach is used to enforce type-safety over the subcontext instances returned from the parent context, and avoids the need for casting.

When a subcontext is requested and it does not exist in the parent context, it may optionally be auto-created. In order to be auto-created in this manner, the subcontext type MUST have a no-arg constructor. If the requested subcontext does not conform to this convention, auto-creation will fail.

  • Field Details

  • Constructor Details

    • BaseContext

      public BaseContext()
      Constructor. Generates a random context id.
  • Method Details

    • getParent

      @Nullable public BaseContext getParent()
      Get the parent context, if there is one.
      Returns:
      the parent context or null
    • setParent

      protected void setParent​(@Nullable BaseContext newParent)
      Set the context parent.
      Parameters:
      newParent - the new context parent
    • getSubcontext

      @Nullable public <T extends BaseContext> T getSubcontext​(@Nonnull Class<T> clazz)
      Get a subcontext of the current context.
      Type Parameters:
      T - the type of subcontext being operated on
      Parameters:
      clazz - the class type to obtain
      Returns:
      the held instance of the class, or null
    • getSubcontext

      @Nullable public <T extends BaseContext> T getSubcontext​(@Nonnull Class<T> clazz, boolean autocreate)
      Get a subcontext of the current context.
      Type Parameters:
      T - the type of subcontext being operated on
      Parameters:
      clazz - the class type to obtain
      autocreate - flag indicating whether the subcontext instance should be auto-created
      Returns:
      the held instance of the class, or null
    • getSubcontext

      @Nullable public BaseContext getSubcontext​(@Nonnull @NotEmpty String className) throws ClassNotFoundException
      Get a subcontext of the current context.
      Parameters:
      className - the name of the class type to obtain
      Returns:
      the held instance of the class, or null
      Throws:
      ClassNotFoundException - if the named class does not exist
    • getSubcontext

      @Nullable public BaseContext getSubcontext​(@Nonnull @NotEmpty String className, boolean autocreate) throws ClassNotFoundException
      Get a subcontext of the current context.

      As of V3.4.0, if autocreate is false, this method will respond to a ClassNotFoundException by attempting to locate a matching subcontext based on the simple class name of the children and return the first match. If no match is found, it will proceed with the throw, but a future version of the API will eliminate that from the signature and simply return a null.

      Parameters:
      className - the name of the class type to obtain
      autocreate - flag indicating whether the subcontext instance should be auto-created
      Returns:
      the held instance of the class, or null
      Throws:
      ClassNotFoundException - if the named class does not exist
    • addSubcontext

      @Nonnull public BaseContext addSubcontext​(@Nonnull BaseContext subContext)
      Add a subcontext to the current context.
      Parameters:
      subContext - the subcontext to add
      Returns:
      the context added
    • addSubcontext

      @Nonnull public BaseContext addSubcontext​(@Nonnull BaseContext subcontext, boolean replace)
      Add a subcontext to the current context.
      Parameters:
      subcontext - the subcontext to add
      replace - flag indicating whether to replace the existing instance of the subcontext if present
      Returns:
      the context added
    • removeSubcontext

      public void removeSubcontext​(@Nonnull BaseContext subcontext)
      Remove a subcontext from the current context.
      Parameters:
      subcontext - the subcontext to remove
    • removeSubcontext

      public <T extends BaseContext> void removeSubcontext​(@Nonnull Class<T> clazz)
      Remove the subcontext from the current context which corresponds to the supplied class.
      Type Parameters:
      T - the type of subcontext being operated on
      Parameters:
      clazz - the subcontext class to remove
    • containsSubcontext

      public <T extends BaseContext> boolean containsSubcontext​(@Nonnull Class<T> clazz)
      Return whether the current context currently contains an instance of the specified subcontext class.
      Type Parameters:
      T - the type of subcontext being operated on
      Parameters:
      clazz - the class to check
      Returns:
      true if the current context contains an instance of the class, false otherwise
    • clearSubcontexts

      public void clearSubcontexts()
      Clear the subcontexts of the current context.
    • iterator

      @Nonnull public Iterator<BaseContext> iterator()
      Specified by:
      iterator in interface Iterable<BaseContext>
    • createSubcontext

      @Nonnull protected <T extends BaseContext> T createSubcontext​(@Nonnull Class<T> clazz)
      Create an instance of the specified subcontext class.
      Type Parameters:
      T - the type of subcontext
      Parameters:
      clazz - the class of the subcontext instance to create
      Returns:
      the new subcontext instance