Package org.opensaml.messaging.context

# 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`, `SAMLMetadataLookupParametersContext`, `SAMLProtocolContext`, `SAMLSubjectNameIdentifierContext`, `ScratchContext`, `SecurityParametersContext`, `SimpleSignatureContext`, `SOAP11Context`, `SOAPClientContext`, `SOAPClientSecurityContext`, `WSAddressingContext`, `WSSecurityContext`

@NotThreadSafe 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.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected class`
`BaseContext.ContextSetNoRemoveIteratorDecorator`
Iterator decorator which disallows the remove() operation on the iterator.
`static class`
`BaseContext.DeprecatedContextClassNameLookAside`
A facade for a map of class names to class types that allows string-based access to renamed classes.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final org.slf4j.Logger`
`log`
Logger.
`private BaseContext`
`parent`
The owning parent context.
`private ClassIndexedSet<BaseContext>`
`subcontexts`
The subcontexts being managed.

## Constructor Summary

Constructors
Constructor
Description
`BaseContext()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`BaseContext`
`addSubcontext(BaseContext subContext)`
Add a subcontext to the current context.
`BaseContext`
`addSubcontext(BaseContext subcontext, boolean replace)`
Add a subcontext to the current context.
`void`
`clearSubcontexts()`
Clear the subcontexts of the current context.
`<T extends BaseContext>
boolean`
`containsSubcontext(Class<T> clazz)`
Return whether the current context currently contains an instance of the specified subcontext class.
`protected <T extends BaseContext>
T`
`createSubcontext(Class<T> clazz)`
Create an instance of the specified subcontext class.
`<T extends BaseContext>
T`
`ensureSubcontext(Class<T> clazz)`
Get a subcontext of the current context, creating it if it does not exist.
`BaseContext`
`ensureSubcontext(String className)`
Get a subcontext of the current context, creating it if necessary.
`BaseContext`
`getParent()`
Get the parent context, if there is one.
`<T extends BaseContext>
T`
`getSubcontext(Class<T> clazz)`
Get a subcontext of the current context.
`<T extends BaseContext>
T`
`getSubcontext(Class<T> clazz, boolean autocreate)`
Deprecated.
use `ensureSubcontext(Class)` or `getSubcontext(Class)`.
`BaseContext`
`getSubcontext(String className)`
Get a subcontext of the current context.
`BaseContext`
`getSubcontext(String className, boolean autocreate)`
Deprecated.
use `ensureSubcontext(String)` or `getSubcontext(String)`.
`Iterator<BaseContext>`
`iterator()`
`void`
`removeFromParent()`
Remove from our parent (if there is one).
`<T extends BaseContext>
void`
`removeSubcontext(Class<T> clazz)`
Remove the subcontext from the current context which corresponds to the supplied class.
`void`
`removeSubcontext(BaseContext subcontext)`
Remove a subcontext from the current context.
`protected void`
`setParent(BaseContext newParent)`
Set the context parent.

### Methods inherited from class java.lang.Object

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Logger.

### parent

@Nullable private BaseContext parent
The owning parent context.

### subcontexts

@Nonnull private ClassIndexedSet<BaseContext> subcontexts
The subcontexts being managed.

## 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

### ensureSubcontext

@Nonnull public <T extends BaseContext> T ensureSubcontext(@Nonnull Class<T> clazz)
Get a subcontext of the current context, creating it if it does not exist.

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

@Deprecated(since="5.0.0", forRemoval=false) @Nullable public <T extends BaseContext> T getSubcontext(@Nonnull Class<T> clazz, boolean autocreate)
Deprecated.
use `ensureSubcontext(Class)` or `getSubcontext(Class)`.
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)
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

### ensureSubcontext

@Nonnull public BaseContext ensureSubcontext(@Nonnull @NotEmpty String className)
Get a subcontext of the current context, creating it if necessary.

Parameters:
  `className` - the name of the class type to obtain
Returns:
  the held instance of the class, or null

### getSubcontext

@Deprecated(since="5.0.0", forRemoval=false) @Nullable public BaseContext getSubcontext(@Nonnull @NotEmpty String className, boolean autocreate)
Deprecated.
use `ensureSubcontext(String)` or `getSubcontext(String)`.
Get a subcontext of the current context.

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 or if auto-creation is set, it will 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

### 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

### removeFromParent

public void removeFromParent()
Remove from our parent (if there is one).

### 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