Class 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,SOAP11Context,SOAPClientContext,SOAPClientSecurityContext,WSAddressingContext,WSSecurityContext
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 ClassesModifier and TypeClassDescriptionprotected classIterator decorator which disallows the remove() operation on the iterator.static classA facade for a map of class names to class types that allows string-based access to renamed classes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.slf4j.LoggerLogger.private BaseContextThe owning parent context.private ClassIndexedSet<BaseContext>The subcontexts being managed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSubcontext(BaseContext subContext) Add a subcontext to the current context.addSubcontext(BaseContext subcontext, boolean replace) Add a subcontext to the current context.voidClear the subcontexts of the current context.<T extends BaseContext>
booleancontainsSubcontext(Class<T> clazz) Return whether the current context currently contains an instance of the specified subcontext class.protected <T extends BaseContext>
TcreateSubcontext(Class<T> clazz) Create an instance of the specified subcontext class.<T extends BaseContext>
TensureSubcontext(Class<T> clazz) Get a subcontext of the current context, creating it if it does not exist.ensureSubcontext(String className) Get a subcontext of the current context, creating it if necessary.Get the parent context, if there is one.<T extends BaseContext>
TgetSubcontext(Class<T> clazz) Get a subcontext of the current context.<T extends BaseContext>
TgetSubcontext(Class<T> clazz, boolean autocreate) Deprecated.getSubcontext(String className) Get a subcontext of the current context.getSubcontext(String className, boolean autocreate) Deprecated.useensureSubcontext(String)or {#linkgetSubcontext(String).iterator()voidRemove from our parent (if there is one).<T extends BaseContext>
voidremoveSubcontext(Class<T> clazz) Remove the subcontext from the current context which corresponds to the supplied class.voidremoveSubcontext(BaseContext subcontext) Remove a subcontext from the current context.protected voidsetParent(BaseContext newParent) Set the context parent.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logLogger. -
parent
The owning parent context. -
subcontexts
The subcontexts being managed.
-
-
Constructor Details
-
BaseContext
public BaseContext()Constructor. Generates a random context id.
-
-
Method Details
-
getParent
Get the parent context, if there is one.- Returns:
- the parent context or null
-
setParent
Set the context parent.- Parameters:
newParent- the new context parent
-
getSubcontext
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
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.useensureSubcontext(Class)or {#linkgetSubcontext(Class).Get a subcontext of the current context.- Type Parameters:
T- the type of subcontext being operated on- Parameters:
clazz- the class type to obtainautocreate- flag indicating whether the subcontext instance should be auto-created- Returns:
- the held instance of the class, or null
-
getSubcontext
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
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.useensureSubcontext(String)or {#linkgetSubcontext(String).Get a subcontext of the current context.If autocreate is false, this method will respond to a
ClassNotFoundExceptionby 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 obtainautocreate- flag indicating whether the subcontext instance should be auto-created- Returns:
- the held instance of the class, or null
-
addSubcontext
Add a subcontext to the current context.- Parameters:
subContext- the subcontext to add- Returns:
- the context added
-
addSubcontext
Add a subcontext to the current context.- Parameters:
subcontext- the subcontext to addreplace- flag indicating whether to replace the existing instance of the subcontext if present- Returns:
- the context added
-
removeSubcontext
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
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
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
- Specified by:
iteratorin interfaceIterable<BaseContext>
-
createSubcontext
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
-
ensureSubcontext(Class)or {#linkgetSubcontext(Class).