public abstract class BaseContext extends Object implements Iterable<BaseContext>
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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
BaseContext.ContextSetNoRemoveIteratorDecorator
Iterator decorator which disallows the remove() operation on the iterator.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoCreateSubcontexts
Flag indicating whether subcontexts should, by default, be created if they do not exist.
|
private org.slf4j.Logger |
log
Logger.
|
private BaseContext |
parent
The owning parent context.
|
private ClassIndexedSet<BaseContext> |
subcontexts
The subcontexts being managed.
|
| Constructor and Description |
|---|
BaseContext()
Constructor.
|
| Modifier and Type | Method and 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> |
containsSubcontext(Class<T> clazz)
Return whether the current context currently contains an instance of
the specified subcontext class.
|
protected <T extends BaseContext> |
createSubcontext(Class<T> clazz)
Create an instance of the specified subcontext class.
|
BaseContext |
getParent()
Get the parent context, if there is one.
|
<T extends BaseContext> |
getSubcontext(Class<T> clazz)
Get a subcontext of the current context.
|
<T extends BaseContext> |
getSubcontext(Class<T> clazz,
boolean autocreate)
Get a subcontext of the current context.
|
BaseContext |
getSubcontext(String className)
Get a subcontext of the current context.
|
BaseContext |
getSubcontext(String className,
boolean autocreate)
Get a subcontext of the current context.
|
boolean |
isAutoCreateSubcontexts()
Deprecated.
|
Iterator<BaseContext> |
iterator() |
void |
removeSubcontext(BaseContext subcontext)
Remove a subcontext from the current context.
|
<T extends BaseContext> |
removeSubcontext(Class<T> clazz)
Remove the subcontext from the current context which corresponds to the supplied class.
|
void |
setAutoCreateSubcontexts(boolean autoCreate)
Deprecated.
|
protected void |
setParent(BaseContext newParent)
Set the context parent.
|
@Nonnull private final org.slf4j.Logger log
@Nullable private BaseContext parent
@Nonnull @NonnullElements private ClassIndexedSet<BaseContext> subcontexts
private boolean autoCreateSubcontexts
@Nullable public BaseContext getParent()
protected void setParent(@Nullable BaseContext newParent)
newParent - the new context parent@Nullable public <T extends BaseContext> T getSubcontext(@Nonnull Class<T> clazz)
T - the type of subcontext being operated onclazz - the class type to obtain@Nullable public <T extends BaseContext> T getSubcontext(@Nonnull Class<T> clazz, boolean autocreate)
T - the type of subcontext being operated onclazz - the class type to obtainautocreate - flag indicating whether the subcontext instance should be auto-created@Nullable public BaseContext getSubcontext(@Nonnull@NotEmpty String className) throws ClassNotFoundException
className - the name of the class type to obtainClassNotFoundException@Nullable public BaseContext getSubcontext(@Nonnull@NotEmpty String className, boolean autocreate) throws ClassNotFoundException
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.
className - the name of the class type to obtainautocreate - flag indicating whether the subcontext instance should be auto-createdClassNotFoundException@Nonnull public BaseContext addSubcontext(@Nonnull BaseContext subContext)
subContext - the subcontext to add@Nonnull public BaseContext addSubcontext(@Nonnull BaseContext subcontext, boolean replace)
subcontext - the subcontext to addreplace - flag indicating whether to replace the existing instance of the subcontext if presentpublic void removeSubcontext(@Nonnull BaseContext subcontext)
subcontext - the subcontext to removepublic <T extends BaseContext> void removeSubcontext(@Nonnull Class<T> clazz)
T - the type of subcontext being operated onclazz - the subcontext class to removepublic <T extends BaseContext> boolean containsSubcontext(@Nonnull Class<T> clazz)
T - the type of subcontext being operated onclazz - the class to checkpublic void clearSubcontexts()
@Deprecated public boolean isAutoCreateSubcontexts()
@Deprecated public void setAutoCreateSubcontexts(boolean autoCreate)
autoCreate - whether the context should auto-create subcontexts@Nonnull public Iterator<BaseContext> iterator()
iterator in interface Iterable<BaseContext>@Nonnull protected <T extends BaseContext> T createSubcontext(@Nonnull Class<T> clazz)
T - the type of subcontextclazz - the class of the subcontext instance to createCopyright © 1999–2019 Shibboleth Consortium. All rights reserved.