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 class
Iterator decorator which disallows the remove() operation on the iterator. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.slf4j.Logger
Logger.private BaseContext
The 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.void
Clear 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.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) Get a subcontext of the current context.getSubcontext
(String className) Get a subcontext of the current context.getSubcontext
(String className, boolean autocreate) Get a subcontext of the current context.iterator()
<T extends BaseContext>
voidremoveSubcontext
(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 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
-
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 obtainautocreate
- 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 obtainautocreate
- 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
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
-
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:
iterator
in 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
-